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

0 favourites
  • 4 posts
From the Asset Store
Fly Bound
$2.49 USD
Design for game, asset for game, game kit, UI design, completed design for game FLY BOUND
  • 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)

  • Try Construct 3

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

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