How do I do a bound to object ?

Get help using Construct 2

Post » Tue Jan 31, 2017 4:08 pm

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.
B
5
S
1
Posts: 30
Reputation: 441

Post » Tue Jan 31, 2017 4:53 pm

did you try the Pin behavior?
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,018

Post » Tue Jan 31, 2017 5:31 pm

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.
B
5
S
1
Posts: 30
Reputation: 441

Post » Tue Jan 31, 2017 8:04 pm

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..
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,018

Post » Tue Jan 31, 2017 8:18 pm

How do exactly do you move it ?
B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450

Post » Tue Jan 31, 2017 10:15 pm

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.
B
5
S
1
Posts: 30
Reputation: 441

Post » Fri Nov 24, 2017 10:42 pm

hello
i found this post while searching
did anybody figured out how to bound a sprite to another sprite plz ??
B
22
S
8
G
2
Posts: 83
Reputation: 2,717

Post » Sat Nov 25, 2017 2:58 am

Here is a very primitive example, works with rectangular shapes with Origin point set to (0,0) :
Code: Select all
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)

(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.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
129
Posts: 1,780
Reputation: 68,883


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 7 guests