Moving sprite slowly from one point to another - libgdx

I am new to libGDX. I am trying to move a sprite from one point to another by changing the x and y of the rectangle. Can I do this gradually ?
I am currently using this to set new co-ordinates
batch.draw(bucketCyan, bucket.x, bucket.y);

What you're talking about is called interpolation, and there are a bunch of different ways to do it. You can either update the variables yourself using the approach noone commented with, or you can check out the Interpolation class: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Interpolation.html

Google Universal Tween Engine. It's an easy to use interpolation "engine". It lets you modify or interpolate any values over time. It is easy to use and works well. It's worth spending some time to get familiar with.

Related

Moving an object in elliptical Path

In my LigGdx based game, I wish to move my Sprite in an elliptical path to reach the destination. I do not find any support in Universal tween engine. Sample of route example is shown below.
Questions :
Is there is any methods in UniversalTween Engine to have a elliptical path ?
Also let me know what is waypoints in UniversalTween Engine ?
Thanks in Advance !
The Universal Tween Engine now supports curves - Default is CatmullRom which would definitely be able to provide the smooth movement you want.
It's a little tricky to get your head around at first but not that bad once you get used to it.
Universal Tween Engine
Details of update that added curves
Well I have searched up this question for you and discovered you many people have already asked this question, and none of them got an answer, yet. So I will try to answer as best as I can. I believe that my method is not the best. But if your application is not time or performance sensitive, then this method may work.
Now this comes to a math problem. You know that the screen is make out of pixels and there is no point making it overly detailed because it isn't possible. So you can do this:
They grey line being your intended line, and the green line being your actual drawn line. If you move objects using the tween engine along the green path and switch path when hitting the red dots. You could mimic an elliptical movement. However, you need to use math and calculate your path. You could set the coordinates of your path as a constant for every screen size, or you could calculate it every time.
Overall, the more points you calculate, the more elliptical the movement will be.
Anyways if you look at this website, it teaches you how to tween.
You can use Tween.to(...); to help you tween to the points.
Hope this helped you

Customize or create Starling animations, movements and Transitions

Since I don't know english very well, I'm not able to find clear examples and/or tutorials for what I'm trying to do.
So the (maybe stupid) question is:
How can I strongly customize tweens using Starling framework and make my Sprites(or MovieClips) following a line, curve or create every other non-linear movement that doesn't exist in Transition Class?
I have no problem with Basic Starling animation. So it should be a good start point.
Thanks in advance for examples, resources or suggestions.
PS. I already visit the "Starling Wiki" page about custom Transitions but, as a Beginner(almost Intermediate) coder I wasn't able to completely understand it.
I know there are many online resources about AS3/Starling/Flash/Nape/Box2D but it's not easy for a non-english Beginner programmer to understand them.
You can simple move Starling's movieClip by set .x .y .rotation
Since now, I haven't heard of scripted transition to make predefined non linear movement. As you said, you can move object from one position to another, but it won't happen in a curved line.
What I've done in the past is to predefine the path of the movement, as I needed exactly the same weird path. I did a path tween in Flash, then used one simple function to loop through all frames (using gotoAndStop()) and getting x and y property of the object, storing them in an array. This was done when initializing. Later on I could start animation on all my weird paths whenever I wanted, using onUpdate method of tween, and passing positions from the array I've populated in the beginning.
This of course is good if you have very weird paths. If you want very little curves, you could try to do a mathematical equation. Tween classes have an update function, which will be called on each frame. So on each frame you could do some calculations and modify the parameters. For example if you tween x and y properties, you could use the update function to add a random number to those values. Of course this will make very uncontrolled movement, I'm just giving an example.
The best solution I could think of, speaking of complexity/result ratio - to use Greensock's TweenMax (look at the second example) - it has a built in bezier tweening. This means it could move from point A to point B within a bezier curve. I think this will be a good solution for your problem :)

Is AS 3 capable of supporting a game with 600 + rotating images?

I made a simple game where squares collect crystals and bring them to a base and replicate. They are just .png images that rotate and move and yet when their number becomes greater than 500, the game starts to lag out. In Java I'm able to do a similar thing with 30,000 units. Could I be doing something wrong or is Flash just not that capable?
I'm using Flash Builder.
I get the image like this:
[Embed(source="../lib/red.png")]
public var redImgClass:Class;
public var redImg = new redImgClass();
Then I pass redImg to a "unit" class which takes an instance of "Bitmap"
I change its "rotation" and x,y members every frame.
Am I doing something wrong here?
you're not using Stage3D. If you use Starling, ND2D or write your own Stage3D wrapper you'll be able to get better performance.
You can also take a look at Jackson Dunstan's blog, this post is especially helpful: http://jacksondunstan.com/articles/2279
Another possible answer is to use blitting, that is, use a single Bitmap object to draw everything on via copyPixels(). This requires that your rotating crystal PNG be replicated into a sequence of rotated images, which you then use instead of directly changing rotation property. This approach is more performance-friendly, and does not depend on video card performance like Stage3D does.
Adobe's manual on blitting
Some discussion on blitting done by game devs
Daniel's answer is correct in that you should use the Stage3D APIs for greater performance. He didn't however mention that you should seriously consider using Starling, which wraps the Stage3D API with much easier to use classes:
Learn more about Starling here.
Example of the level of performance you could expect from Stage3D.
Starling is what you`re looking for (http://gamua.com/starling/)

Flash TextField not tweening smoothly

I'm having an issue with TextFields, whenever I tween the containers that they are inside of, the text will sorta jump and not scale very smoothly. Is there a solution to this problem? I have tried setting cacheAsBitmap, and that doesn't seem to have any effect. Thanks.
Wanted to add that I'm doing this in AIR, and the tweens are not linear, as in, not just an x tween, it is a tween that is affecting both x and y. I have a feeling it may be due to this.
Make sure they are anti-aliased for animation and not for readability. You can find the setting in the textfield properties. If using script, like TweenLite, you may also want to consider rounding the position on update.
Change the anti-alias option to "antialias for animation" instead of "antialias for readablility."
As people in other answers state, you can try to round the values the textfield is set to, to partly (sometimes totally) avoid such "jumps".
If you're using a tween engine, like TweenLite, eaze, anything like that, you can try to look for a method to round the position :
for example by using the RoundPropsPlugin in Tweenlite,
or using the Math.round(value) function in an onUpdate event coming from the tween itself.
Most of the time, good tweening engine will have either (or even both !) of these solutions possible (if not, maybe consider changing engine, TweenLite or eaze are the two bests in my opinion !)

as3 dynamic Tween duration

I have an object in a Movieclip that I currently have a tween set up for. I set it up on the stage, not with actionscript.
I need to dynamically change the duration of this tween. I have not found reference to a way to do this.
I don't mind dynamically creating the tween if I need to, setting the initial duration in code, but I still have not found any reference to changing the duration dynamically.
Is this possible?
I'm just learning as3, so sorry if this is something that should be obvious.
I strongly suggest you to switch to TweenLite/TweenMax library, it's awesome, free, super-easy to use and it will change the way you work!
Have a look here, and here on the forum there's an explanation on how to change duration dynamically
Ideally you'd do it by programming the tween, there are many libraries out there that make it quite easy.
One of the ones I use frequently is eaze-tween, it has a timeline tween function, though I haven't used it, it is worth a try. eaze(target).to(duration, { frame:"label" });
Grant Skinner's gtween library also seems to be able to that using the GTweenTimeline Class.
The other thing you can do is modify the frame the animation is at at a varied rate, so to speed it up you'd go through it two frames at a time, so twice as fast. This way makes it limited to multiples of speed.
If you want to have more control there you'd need to have a longer tween, otherwise you might notice movement that is not very smooth. The way to do that would be to have a transition of a 100 frames, and use a tweening library, where the on update makes the value of the tween(which is a number between 0 and 1) and multiply it by the number of frames(100) and update the frame mc.gotoAndStop(int(val*100);. You can then assign various tweening functions and durations.
hope it helps