How do I move a sprite exactly 32 pixels without teleporting

Get help using Construct 2

Post » Mon Sep 29, 2014 6:56 am

So lets say a sprite of a guy is standing there and you click the arrow key one time. I want him to move a set number of pixels such as from his current 32x32 tile to the next 32x32 tile. I have no idea how to do this without him appearing to teleport. It would be more like a walk from point A to Point B but without making points just move this far then stop.

So let say he is at 96x 96y and you click the right arrow he would then walk to 128x 96y and then stop.
B
6
S
1
G
1
Posts: 31
Reputation: 945

Post » Mon Sep 29, 2014 8:16 am

Theres an example which comes with construct that shows how to use the bullet behaviour to move to the mouse position, just substitute the mouse coordinates to an x,y position of your choice.

Alternatively theres also a great third party tween plugin which allows for a variety of movements with different easing options which you might want to play with.
https://www.scirra.com/forum/behavior-litetween_t70700

Otherwise you could use a local variable set to 32, the do local variable > 0 set sprite to self.x + 1, and subtract 1 from local variable. etc.
B
43
S
22
G
20
Posts: 735
Reputation: 11,977

Post » Tue Sep 30, 2014 1:44 am

I was playing around with bullet behavior and chasing a moving dot that would be invisible but that led into a lot of probles such as missing the coordinates and flying off screen.

I will check out the links.
B
6
S
1
G
1
Posts: 31
Reputation: 945

Post » Tue Sep 30, 2014 2:04 am

@heromedel You could spawn a transparent 1x1 sprite object to a position you want, then move the moving object to that sprite's location. With your example, let's say you press the Left arrow and want to move -32. Give the moving object the Pathfinding behaviour to save some events.

Please keep in mind this isn't tested, but the logic works, :). The idea is to make a variable you can toggle to make the transparent sprite only spawn once, and when it's spawned while holding the Left arrow, the moving object will move to the transparent sprite. When reaching the destination, the transparent sprite is removed.

*Make a global variable called objPositionSpawn and set it to 0*

Keyboard -> Left is down
--Player -> Find path to objEndPosition
--Player -> Move along path

(These are sub-events [S])
[S] System -> objPositionSpawn = 0
[S] System -> Create object objEndPosition on layer x at player.x - 32, player.y
[S] System -> Set objPositionSpawn to 1

Player -> On path end
--System -> Set objPositionSpawn to 0
--objEndPosition -> Destroy
Founder of Jadelight Studio, Developer of Libertas Aedifex, regular C2 Help contributor and fan of ambient music and Star Wars.
B
12
S
4
Posts: 255
Reputation: 2,008

Post » Tue Sep 30, 2014 8:38 am

Pathfinding object can be expensive, seems a waste and a long winded solution to something so easy to do.
B
43
S
22
G
20
Posts: 735
Reputation: 11,977

Post » Tue Sep 30, 2014 8:46 am

One way would be to, with the use of 2 instance variables OriX and parcours, set its position X to :

lerp(self.OriX, Self.OriX+32, parcours)

And you increase parcours from 0 to 1 using :

Set parcours to: clamp(parcours+speed*dt, 0, 1)

Where speed is the movement speed in pixel per seconds
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
52
S
22
G
18
Posts: 2,122
Reputation: 17,093

Post » Thu Apr 02, 2015 9:43 am

I have found a method I like.

What I have ended up doing to fit my movements needs for tile based movements is..
I use two objects one is the real object the other is invisible like a shadow. When push an button such as right arrow the shadow jumps to the new position and checks for overlap or collisions. If none are found then the real object moves to the shadow. If a collision or other problem occurs the shadow jumps back to the real object and a message such as "there is a wall" can be played or if it is an enemy then an attack can occur.

I even use this for my wandering enemies if they move in a tile like way. Though I am going to have to work on better path finding for enemies.
B
6
S
1
G
1
Posts: 31
Reputation: 945


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 14 guests