How do I move sprite with interpolation

Get help using Construct 2

Post » Thu Oct 06, 2016 9:56 am

Message: Hunter can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Hi,
what i want to do is this :

if A pressed : sprite move 50 pixels to the Left
if B pressed : sprite move 50 pixels to the Right

like this
Image

the problem is, i can't have this interpolation, it just teleport 50 pixels to the other side

here is my capx :
https://dl.dropboxusercontent.com/u/138507172/move_sprite.capx

thank you so much
B
4
S
1
Posts: 40
Reputation: 532

Post » Thu Oct 06, 2016 12:10 pm

Done download here

http://www101.zippyshare.com/v/jxdeajHq/file.html

Press the space bar and the hero will move left , then stop on his own.
Check out my awesome Android Game releases https://play.google.com/store/apps/deve ... ames&hl=en
B
38
S
18
G
24
Posts: 682
Reputation: 16,615

Post » Thu Oct 06, 2016 12:34 pm

@Hunter
I would do it like that:

Image

Or use the MoveTo behavior from rexrainbow
http://www.scirra.com/forum/behavior-ro ... 44845.html
B
24
S
3
G
1
Posts: 451
Reputation: 2,165

Post » Thu Oct 06, 2016 4:26 pm

Asmodean wrote:@Hunter
I would do it like that:

Image

Or use the MoveTo behavior from rexrainbow
http://www.scirra.com/forum/behavior-ro ... 44845.html


Thats pretty good but you can cut down a little code. Also I would encourage you to use the least amount of plugins if your making the game for mobile try to code each feature in as best you can.
Check out my awesome Android Game releases https://play.google.com/store/apps/deve ... ames&hl=en
B
38
S
18
G
24
Posts: 682
Reputation: 16,615

Post » Thu Oct 06, 2016 6:55 pm

If you aren't using a movement behavior I recommend using lerp() — no plugins required.

Create instance variables for StartingX, FinishingX, Progress, & Speed.
Group(initially disabled)
-Every Tick
--Set Position to lerp(StartingX, FinishingX, Progress)
--Add Speed to Progress
-If Progress > 1 Disabled Group

Then when its time to move you set the starting and finishing variables, set progress to 0 and enable the group. Presto!
ImageImageImage
B
40
S
23
G
11
Posts: 498
Reputation: 10,062

Post » Sat Oct 08, 2016 11:30 am

Hi,
thank you all, and sorry for the late, i had problems with the internet

@PixelPower : i didn't think of this solution before interesting manipulate the mouvement with time, but it didn't work for my case

@Asmodean : it work perfectly, with this case even if i didn't understand exactly the way your code do it, but i will analyse it to figure out your method

@badmoodtaylor : i heard about the lerp function and i will test your code too

Thank you everybody for your help
B
4
S
1
Posts: 40
Reputation: 532

Post » Sat Oct 08, 2016 1:15 pm

ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Sun Oct 09, 2016 1:51 am

Hunter wrote:@badmoodtaylor : i heard about the lerp function and i will test your code too


I made a sample capx to demonstrate lerp() — much easier to show all the events than to explain :D

Should be pretty self-explanatory but let me know if you have any questions:

Lerp() Tutorial
ImageImageImage
B
40
S
23
G
11
Posts: 498
Reputation: 10,062


Return to How do I....?

Who is online

Users browsing this forum: Armench, dop2000, Jackriduk, kiki4construct and 23 guests