-
On whatever X and Y, move to these X and Y
Hi all.
so, I've been trying to make my somewhat first game, and got stuck.
trying to make the "Enemy UI".
You don't need any background info.
Its a Thinking Question
Enemy is at 100X and 200Y.
Make him move to 350X and 50Y. ( in a somewhat animation )
So I was thinking, check if Current X is smaller or bigger than 350, then every frame ( or by Time Animation ), do x++ or x-- Accordingly.
Same for the Y.
Is there a better way to it?
Something that will make the animation smoother?
A way thats better, can be "upgraded" in the future?
thanks
-
You can approach it in many ways, but ultimately you are interpolating from one set of values to another. This is exactly what Tweening engines are for. All that you really need to do is go from one value to another over time. If you want the movement to be smooth, then you will move (x1 - x2)/totalmoves each time. So in your case, for the x movement
x += (350-100)/totalmoves.
You can calculate totalmoves either by number of frames, or from a total time you'd like the animation to take up and the frames per second.
-
hmm, how didnt I think of the /totalmoves ? Some math brain I am
Iv'e never done any "real" as3 animation.
In Tweening Engines , you mean Custom Libraries or some set of methods I should look in to?
also, what can a "Tweening Engine" do beyond /totalmoves ?
-
A Tweening engine is just a package that will interpolate values for you. There are lots of them out there, and just about all of them are better than the built in Tween classes. The one I use most often is TweenLite.
Example usage for you would be something like this:
Code:
TweenLite.to(yourobject, 1, {x:350, y:50});
http://blog.greensock.com/tweenlite/
-
awesome.
lot o' thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|