How to prevent the sprite from leaving the layout?

This forum is currently in read-only mode.
From the Asset Store
Minimal Sprite Font with Stroke for Pixel Art games.
  • Hi I'm new here.Sorry my English is bad.

    I set a 8-direction movement for a sprite and it just keept on moving and moving until it disappeared from the screen.

    But I want it to STOP moving when it reach the edge of the window.

    Is there a way to do that?

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • IF Sprite X<0: Set Sprite X = 0

    IF Sprite X>[insert your layout Width]: Set Sprite X = [Insert your layout width]

    IF Sprite Y<0: Set Sprite Y = 0

    IF Sprite Y>[height of your layout]: Set Sprite Y = [Your layout height]

    try it

  • If you are using sprite with 8-dir movement you can create Tiled Background object around game window (outside the layer) and make that object solid.

    No event, no coding :)

  • If you are using sprite with 8-dir movement you can create Tiled Background object around game window (outside the layer) and make that object solid.

    No event, no coding :)

    yes but the sprite will get neurotical attack whenever he'll hit the solid obstacle. with my method he'll just nicely stop without suddenly going apes***t <img src="smileys/smiley36.gif" border="0" align="middle" />

    but bottom line is - yes, both methods will work just fine.

  • Can't remember this happen to me. but i'm always using square detectors not actual "hero" sprites... so yes it can start to move like crazy <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Easy and effective way:

    + System: Always (every tick)

    -> Sprite: Set position to clamp(.x, 0, LayoutWidth ), clamp(.y, 0, LayoutHeight )

  • Easy and effective way:

    + System: Always (every tick)

    -> Sprite: Set position to clamp(.x, 0, LayoutWidth ), clamp(.y, 0, LayoutHeight )

    Tell that to people who are still scared or never found system expressions <img src="smileys/smiley1.gif" border="0" align="middle" />

    We're trying to help using simple and understandable things for begginers <img src="smileys/smiley1.gif" border="0" align="middle" />

  • It's never too early to start learning :)

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