Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: scale animation problem  (Read 1379 times)

0 Members and 1 Guest are viewing this topic.

Mortal

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
scale animation problem
« on: April 05, 2016, 01:37:19 am »
hello

i'm having trouble time with scale animation which i thought it will be most easiest part in my game that i'm working on. but it turned i was wrong about it.

my goal is to achieve smooth and constant scaling animation. i have implemented the "easing" technique to calculate ratio of scale amount that need to step each frame to sprite object. it seems run but i didn't get what i was looking for.  the scaling effect is varying from time to time which is not suppose to happen. some time it goes faster while other goes slower.

also, i have faced problem with float point comparison that i can't compare two float values for equality with if statement, i had to implement "close enough" approach.

i have created minimal example to demonstrate the issue:
(click to show/hide)

my questions
how can i fix this tripping in animation?, is my implementation is correct? and are there other ways to achieve smooth and constant scale animation?

Edit: i fixed it, my bad, it was a bug in both source code. i corrected example here and code in my game both work fine at last but it seems i overly complicated it for just scaling , i'm sure there is an easy way to do it, but i don't know it.

is there a better way to do scale animation?

« Last Edit: April 12, 2016, 01:01:51 pm by MORTAL »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: scale animation problem
« Reply #1 on: April 05, 2016, 02:36:58 am »
I don't know the direct solution to your problem, but I see a huge opportunity for simplification that may very well solve it or at least make it much easier for you to figure out yourself.

Pass the desired duration of the animation to scalingEffect() along with the stuff you're already passing to it, and compute the speed based on that. Then you can get rid of scalingEffect's return value, and the entire closeEnough() function and its epsilon weirdness, since you can detect whether the animation is over simply by comparing the time elapsed so far to the desired duration of the animation.

Mortal

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: scale animation problem
« Reply #2 on: April 05, 2016, 02:54:00 am »
thanks Ixrec

I don't know the direct solution to your problem, but I see a huge opportunity for simplification that may very well solve it or at least make it much easier for you to figure out yourself.
yeah, me too i like the simplicity over any thing else in this matter but i had to do it for the site rules that says the minimal example should be within the main. in my game i used regular functions only

Pass the desired duration of the animation to scalingEffect() along with the stuff you're already passing to it, and compute the speed based on that. Then you can get rid of scalingEffect's return value, and the entire closeEnough() function and its epsilon weirdness, since you can detect whether the animation is over simply by comparing the time elapsed so far to the desired duration of the animation.
good point, gonna try it. luckily it works now after fixed the bug in both source codes
« Last Edit: April 05, 2016, 02:55:52 am by MORTAL »

 

anything