0 Favourites

Bound to layout....except....

  • Is there a way to 'bound to layout' except for say, the top, or left side, etc?

    The only way I can think of, would require a lot of events... I'm trying to minimize by using "Bound to layout" but don't want them bound to the top of the screen... but for testing purposes, this can be any side.

    Thanks!

  • This should take 3 events to sort out. If you need the behavior to apply to many different objects then just put them in a group and apply these events to the group instead:

    If Group.X < 0 then Group.X = 0

    If Group.X > LayoutWidth then Group.X = LayoutWidth

    If Group.Y > LayoutHeight then Group.Y = LayoutHeight

    Of course you can tweak the zero or layout measurements for your sprite width or add a buffer if that suits the effect you're after. If you are using physics then it gets a little more complicated only in that you will need to set your physics velocity to zero to stop the object from repeatedly trying to exit the screen.

  • You could do it in one event with clamp ;

    8 direction is moving : Set position to x: clamp(sprite.X,0,854) y :clamp(sprite.Y,-480,480);

    This assumes that the layout width is 854, and height is 480 & would bound the player to layout except the top. Allowing the player to leave the layout up to 480 px upwards.

    Edit : Don't forget to account for the sprite width and height ;

    x : clamp(sprite.X,0+sprite.Width/2,854-sprite.width/2)

    y : clamp(sprite.Y,-480+sprite.Width/2,480-sprite.width/2)

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • You could do it in one event with clamp ;

    8 direction is moving : Set position to x: clamp(sprite.X,0,854) y :clamp(sprite.Y,-480,480);

    This assumes that the layout width is 854, and height is 480 & would bound the player to layout except the top. Allowing the player to leave the layout up to 480 px upwards.

    Edit : Don't forget to account for the sprite width and height ;

    x : clamp(sprite.X,0+sprite.Width/2,854-sprite.width/2)

    y : clamp(sprite.Y,-480+sprite.Width/2,480-sprite.width/2)

    Worked beautifully; thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
33 10,752
luohuaming's avatar
luohuaming
Topic
19 996
Vangelis's avatar
Vangelis
Topic
12 1,222
eli0s's avatar
eli0s