Hollow sprites/shapes?

Get help using Construct 2

Post » Sat Jul 13, 2013 3:14 pm

Hi all,

Still learning but have a relatively basic (i hope) question for everyone. I have a shape that I want to be hollow e.g. a square and it has a another shape inside it e.g. a circle. What I want to do is be able to move the circle around the inside of the square and be contained to that area. I can move the circle around easily enough with behaviours but i'm not sure about the square, should it even be a sprite? I can't make the square a solid as the circle then appears outside the square. Is the alternative to add in some "hidden" sprites that would mark out the collision area of the edge of the square?

I've had a look on the forums and tutorials but i'm not even sure i'm calling it the correct thing to find the correct answer.

Cheers!
B
3
Posts: 6
Reputation: 212

Post » Sat Jul 13, 2013 3:58 pm

Hey @partTimeCrazy,

Not completely sure I know what you're after! But if you want to limit the movement of your circle sprite, to be contained within your square sprite. You could try adding a condition to only move the circle sprite if touch/click etc, is within the boundaries of the square sprite.

If I've completely misunderstood what you're trying to achieve, it may be worth adding a capx, so that others can more easily understand the problem.

Good luck :)
B
33
S
6
G
7
Posts: 494
Reputation: 8,252

Post » Sat Jul 13, 2013 4:00 pm

Look into the 'blend modes' example capx, I think that may be what you're after.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,674

Post » Sat Jul 13, 2013 5:34 pm

something like that?
squareConstraint.capx
Last edited by Yann on Sun Sep 14, 2014 7:15 pm, edited 1 time in total.
B
64
S
22
G
14
Posts: 1,482
Reputation: 16,457

Post » Sun Jul 14, 2013 8:27 pm

Yann has the right idea but i'm not sure how to do that if the square in the example is an irregular shape? Basically the square needs to only have an outline of the square i.e. walls and the circle can only move inside those walls.

I'm thinking I may be better off making each "wall" a sprite in itself and having collision detection on it that way. I thought there might have been an easy way to have a single sprite with a hollow center but I may be over thinking it.

Thanks for the responses anyway! Its nice to see such a helpful forum!



Also Yann, those Reddit Videos are awesome! partTimeCrazy2013-07-14 20:28:44
B
3
Posts: 6
Reputation: 212

Post » Sun Jul 14, 2013 10:26 pm

If you want some thing more complex, like having any shape constrained inside any other shape, it becomes more complex.

It would be slightly easier if we had access to the position of the collision polygon's vertices.
Then we could do some math ourself to check if one of the point of the dragged object is outside of the constraining shape.

Then it would be a matter of keeping in memory the previous position of the object and interpolating between this position and the position the object would be if there were no constraint by running a loop to approximate the position the shape should be to stay within the constraints.

Using multiple objects to build the constraining area would be a possible solution but, to me, it would look quite messy to set up.
B
64
S
22
G
14
Posts: 1,482
Reputation: 16,457

Post » Sun Jul 14, 2013 10:45 pm

the polygon zone is always completly filled, it could work if we could cut holes with a polygon mesh) but now the only way is to construct multiple walls, pin them together and have a cirle inside the zone. well if thats what your after..
ImageImage
B
69
S
21
G
7
Posts: 824
Reputation: 10,011


Return to How do I....?

Who is online

Users browsing this forum: aramesh, duditon, Governador and 2 guests