Just move sprites from point A to B with an event?

Get help using Construct 2

Post » Tue Sep 18, 2012 2:20 am

Making a game where there will be many sprite translations/movement controlled by events...

Is there an easy way to just place a sprite at some location on-screen then run an event to tell it to go to X,Y coordinates at N speed?
I couldn't find anything that just does this. With ease-in and out would be even better.

I don't want to use external plug-ins though. :)TheDev2012-09-18 03:29:32
B
4
Posts: 41
Reputation: 407

Post » Tue Sep 18, 2012 11:00 am

I have the same issue - this is my nr.1 desired function.

I don't think you can do this without someones tween plugin which I am avoiding if I can as they wont be commercially supported.

I am approximating this with the bullet behavior to send the sprite in the right direction, then stopping it when it goes over a certain coordinate. However, if you make the animation fast, it doesnt seem to stop exactly at the right spot - it seems to overshoot sometimes (which is to be expected). I then pull it back to exactly the right spot.

I dont know if you can use ease-in with bullet behavior - havent' got that far yet, but I guess you could use the sine behavior at the end?

Its a shame there is no access to the excellent easing functions in jquery easing plugin.

nutmix2012-09-18 11:04:02
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Tue Sep 18, 2012 11:08 am

I want this feature too, sometime bullet behavior lerp or 3rd party plugins are not the best choice.hylists2012-09-18 11:09:06
B
19
S
5
Posts: 51
Reputation: 1,883

Post » Tue Sep 18, 2012 11:26 am

Add a couple private variables to the sprite, let's call them GoalX and GoalY.

+ distance(Sprite.X,Sprite.Y,Sprite.GoalX,Sprite.GoalY) > 1
> Sprite: Set position to lerp(Sprite.X,Goal.X,0.1),lerp(Sprite.Y,Goal.Y,0.1)
++ (subevent) distance(...same as above...)<1
>> Sprite: Set position to Goal.X,Goal.Y

This basically moves the sprite to goal coordinates, with easing toward goal. See lerp expression in the manual and experiment with it. You can also use this for snapping to position or another object. Following, too.
The subevent makes sure the sprite sets proper position whenever it is close enough.

If you want a more smooth move from start to finish, use lerp(StartX,GoalX,Timer),lerp(StartY,GoalY,Timer) as well as a Timer variable which you add dt to (see system expressions, timedelta or deltatime).

+ Sprite.Timer < 1.0
> Sprite: Set position to lerp(StartX,GoalX,Timer),lerp(StartY,GoalY,Timer)
++ Sprite.Timer >= 1.0
>> Sprite: Set position to GoalX,GoalY

So, this basically moves the sprite from Start to Goal in one second (Timer = 0 at start and Timer = 1.0 at finish).

For easing, you want to get a little more creative, you can use the cos for one form of easing at start/end. But that's getting a bit mathy.Mipey2012-09-18 11:27:37
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Tue Sep 18, 2012 11:30 am

There is a custom plugin for this, called MoveTo.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Tue Sep 18, 2012 11:35 am

Or you could use a bit of trigonometry and some system expressions:

MoveTo.capx (r103.2)
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Tue Sep 18, 2012 1:03 pm

Interesting, I didnt now C2 had lerp. Its not in the manual or in the help on expressions so I didnt know it was there - how did the first person find it?

@Mipey - nice example, thanks.

All this manual maths to move an object from A to B cumon C2, give us a built in MoveTo behavior with easing - you know you want to!nutmix2012-09-18 13:03:31
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Tue Sep 18, 2012 1:10 pm

@nutmix:

Manual link
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Tue Sep 18, 2012 1:18 pm

@Nimtrix, doh! I was looking under expressions:

http://www.scirra.com/manual/78/expressions

Which is where the in C2 expression help takes you.

Its a real shame that you cant search the manual for things like this - I can never find what I'm looking for.
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Tue Sep 18, 2012 3:54 pm

Hi ,
is it possible to apply a vehicle Behavior..?
B
21
S
12
G
4
Posts: 31
Reputation: 4,537

Next

Return to How do I....?

Who is online

Users browsing this forum: Nifl and 23 guests