How do I do a bound to object ?

0 favourites
  • 8 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Hello !

    I have an object overlapping an other one and it absolutly needs to stay in this condition, but I don't know how to do this.

    To illustrate it properly, I would like to adapt the " Bound to layout " behavior to a bound to object.

    Regards.

  • did you try the Pin behavior?

  • Yeah I've tried and it doesn't show the result I want. My overlapping object has to move "inside" the overlapped, and pinning it would stop any movements.

  • oh I understand now, you want it to move within that other sprite.

    I work it the same way you can code "Bound To Layout" with the behavior. Just keep testing for when it's not overlapping and when it isn't return it to where it was last overlapping. Look into overlapping at offset. It probably depends on how exact you want to be and how big your bounding sprite is..

  • How do exactly do you move it ?

  • I've found an other way to do it, and it simplify my next iteration of the work. I've just put simple cases into the sprite and the sprite that has to move just go onto the cases, so it can't move out of it.

    But in the first place I was moving it by adding X pos + sprite size to the new X pos till it is overlapping. But the way I need to use it, it wasn't appropriate in the first place.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • hello

    i found this post while searching

    did anybody figured out how to bound a sprite to another sprite plz ??

  • Here is a very primitive example, works with rectangular shapes with Origin point set to (0,0) :

    SmallSprite Compare X if less than BigSprite.x  -> SmallSprite Set x to BigSprite.x
    Compare two values -> SmallSprite.BBoxRight>BigSprite.BBoxRight  -> SmallSprite Set x to (BigSprite.BBoxRight-SmallSprite.width)[/code:2snzegm8]
    (similar code for Y coordinate)
    
    If your sprites have complex shapes, there are several things you can do.
    If partial overlapping is ok, you can save SmallSprite position in instance variables oldX and oldY on every tick. If on next tick the sprite moves and no longer overlaps the BigSprite, return its position to oldX, oldY.
    
    Or you can pin a few very small invisible sprites to the corners of the SmallSprite, lets call them detectors. If any of the detectors is not overlapping the BigSprite, return SmallSprite to its previous position. 
    Or you can use the same principle with image points and "Pick overlapping point" event.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)