Patrolling Sprites

0 favourites
  • 6 posts
From the Asset Store
Isometric Sprites Pack
$6.75 USD
25% off
Build your map with these isometric objects and terrains
  • What would be some basic logic to make a sprite patrol back and forth?

    I keep making conflicting conditions that just make the sprite freeze :(

  • The idea is to have the sprite moving from point A to point B, and then coming back to point A.

    Your sprite should have an instance variable "dir" that would stand for the direction the sprite is going. (example, patroling from left to right, up to down, etc...)

    Naming and type of the variable is up to you (number or text).

    For this example, let's consider a number, where 0 is the sprite going to the right, 1 is going to the left.

    + Is Sprite.dir = 0

    ++ Is Sprite.X < destination.x

    => Sprite.X + 1

    ++ Is Sprite.X >= destination.x

    => Sprite.dir = 1

    => destination.x = new destination

    + Is Sprite.dir = 1

    ++ Is Sprite.X > destination.x

    => Sprite.X - 1

    ++ Is Sprite.X <= destination.x

    => Sprite.dir = 0

    => destination.x = new destination

    It is up to you the way you set your destination.

    You can also use the same logic to test the Y position.

    Hope it is clear enough and helps you, let me know.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Worked like a charm. I could not wrap my head around what I needed to do.

    Thanks for the help!

  • Hey guys, I decided to try this out and I couldn't figure out what Kyatric meant - probably because I'm bad at reading events written this way.

    What I did instead was make 2 guide objects that my sprite had to collide with to change directions.

    Here is the capx:

    This works really well, but I would appreciate it if someone could edit this capx to represent what Kyatric is talking about :)


  • Here you go

  • Thank you :)

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