How do I move a sprite X pixels over Y milliseconds?

Get help using Construct 2

Post » Thu Aug 28, 2014 10:19 pm

Hey all

in the event sheet, all the command on a sprite are instant move functions like set X set Y and Set position.

I would like the sprite to move 32 pixels over 0.5 seconds. Any way of doing it using a simple way, or I have to count the moved pixels in a variable?

Thanks :)
B
18
S
7
G
1
Posts: 157
Reputation: 1,928

Post » Thu Aug 28, 2014 10:37 pm

If I'm thinking correctly the sprite should move 64*dt every tick for 0,5 seconds..

so you could start the movement by setting a boolean variable and giving the sprite timer behaviour

if boolean variable is true
- sprite set position : sprite.x+64*dt
- sprite start timer "moving" for 0,5 seconds

on timer "moving"
- sprite set boolean to false
You do not have the required permissions to view the files attached to this post.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Aug 28, 2014 10:41 pm

hm... doesn't dt changes with performance? I mean, it is the difference between ticks, no?
B
18
S
7
G
1
Posts: 157
Reputation: 1,928

Post » Thu Aug 28, 2014 10:45 pm

Try it..

using dt like this makes sure that the movement takes 0,5 seconds regardless of framerate..
you wanted 0,5 seconds, so I put it in..

I also added an action to put the sprite exactly at the desired spot at the end of the movement, but if this doesn't work for you..?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Aug 28, 2014 10:50 pm

It works perfectly well, LittleStain, thank you very much. I was just trying to understand how come it works :)
B
18
S
7
G
1
Posts: 157
Reputation: 1,928


Return to How do I....?

Who is online

Users browsing this forum: Lightstone, rayolf and 37 guests