How do I move a sprite exactly 32 pixels without teleporting

0 favourites
  • 7 posts
From the Asset Store
Vintage steam pixels for your UI! 125 unique assets in a single pack!
  • 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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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 )

    System -> objPositionSpawn = 0

    System -> Create object objEndPosition on layer x at player.x - 32, player.y

    System -> Set objPositionSpawn to 1

    Player -> On path end

    --System -> Set objPositionSpawn to 0

    --objEndPosition -> Destroy

  • Pathfinding object can be expensive, seems a waste and a long winded solution to something so easy to do.

  • 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

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)