How do I clamp to a object ?

0 favourites
  • 8 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • ...hi guys, how can i do this: a target is pinne to my ship..the target is bound to layout. If i go to touch the upper or lower limit it sticks there...this is what I want... since my lauout is very long..this will not happen with the left or right side... how can i achive the same effect also for right and left ? I think putting a sprite as barrier is fine...how can i clamp my target to the sprite ?

    thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm not completely sure what you mean..

    Do you want the Sprite to be bound to the right and left edges of the layout?

    Otherwise, you can always use conditions such as

    IF Sprite.X < [desiredXmin]
    THEN Sprite.X - set X to [desiredXmin][/code:6trrm93r]
    
    and vice versa for the max value:
    
    [code:6trrm93r]IF Sprite.X > [desiredXmax]
    THEN Sprite.X - set X to [desiredXmax][/code:6trrm93r]
    
    If that's not what you want, please explain your problem more.
  • hi, basicly its like the bound to layoout... but immagine that my layout is 20000 long and high 800. This means that the sprite is blocked on top and bottom...but disappaeras on left or right side since the window view is just 1500*800.... i would need something like "bound to screen" ...did u undersand my problem ? thanks

  • Alright, I see.

    Okay, so just use what I posted above and replace the desiredXmin by the system expression ViewportLeft, replace desiredXmax by ViewportRight.

    (Those two expressions return the X coordinate for the left/right edge of the window (not the layout).

    Hope that this is what you need.

  • To bound the edges to view port.

    For each sprite

    ___System > compare two values .. Sprite.BBoxLeft < ViewportLeft ( the compare does not pick !, why the for each)

    ________ Sprite > set x to ViewportLeft + Sprite.Width

    ___Else

    _________move the sprite as you are moving it currently

    ___System > compare two values .. Sprite.BBoxRight > ViewportRight

    ________ Sprite > set x to ViewporRight - Sprite.Width

    ___Else

    _________move the sprite as you are moving it currently

    or pick them this way

    System > pick by comparison > expresssion = Sprite.BBoxLeft .. Less than value = ViewportLeft

    For each sprite (if more sprites can exceed the boundary's at the same time)

    Ether way, you have to pick them.

  • thanks, could u do that on my capx ? iam sch a bad coder...

    https://lookaside.fbsbx.com/file/target ... Y6JxOcDvcI

    the target should NEVER leave the screen...

    tahnks

  • you can use Scroll To behavior for the sprite

  • thanks

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