How do I create a bound to layout?

Get help using Construct 2

Post » Sun Apr 09, 2017 11:07 pm

Hello Everyone,

Can I create a square and has an object bound to it from inside?

Let say I have a sprite X:500px by Y: 500px.

Then I have an object bound inside the square.

Thank you.
B
24
S
4
Posts: 78
Reputation: 1,308

Post » Mon Apr 10, 2017 1:11 am

Yes, just use an is overlapping condition.. when not overlapping it is considered to have left the object so you can perform your events to keep it there..

Another option is to put a larger square under the first and use is overlapping larger but not over lapping smaller to detect when it left smaller square..

Another option is to put image points on each side of square and spawn/pin solid behavior sprites on all 4 sides and give them and your object the physics behavior..

You could always do it with some maths too... but yuck. Someone else can xsplain that.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
70
S
19
G
8
Posts: 639
Reputation: 9,674

Post » Mon Apr 10, 2017 4:38 am

As chrisinfinger said, one weakness about overlapping condition is that it only measure "at least" overlapping. This means that you can have the object overlapping by a single pixel, while the rest is out of the square, and still considered overlapping. This depends on how you want it in your project.

For example my project, I have a feature where the user can arrange a table layout in a room. This of course, cannot have a single pixel out of the square as the table would puncture the wall. In my case, I cannot use overlapping condition.

I prefer with some comparison, as I don't want to add unnecessary object. Here's what I do (very simple actually):
Code: Select all
if (Table.BBoxLeft >= FloorObj.BBoxLeft AND
Table.BBoxRight <= FloorObj.BBoxRight AND
Table.BBoxTop >= FloorObj.BBoxTop AND
Table.BBoxBottom <= FloorObj.BBoxBottom) {
   [VALID LOCATION]
   Table set animation frame to 0
}
else {
   [INVALID LOCATION]
   Table set animation frame to 1
}
B
33
S
10
G
2
Posts: 46
Reputation: 3,063

Post » Mon Apr 10, 2017 7:15 am

Thanks chrisinfinger and tmntppn. I see this is something I need to get a grasp on.

I tried to simulate bound to layout behavior with a custom square sprite but its not happening.

All I want to do is create an object 500 X 500. This object will be inside of layout then inside the object is the player.

The player would move and bound to object but I don't have any luck.

I tried creating four separate objects and set collision to player but my player would jiggered when colliding with the blocks.

Can I code to get this done correctly? Please help.

Thank You.
B
24
S
4
Posts: 78
Reputation: 1,308

Post » Mon Apr 10, 2017 8:02 am

Try this: https://www.dropbox.com/s/hor58fh29csb8 ... .capx?dl=1

You can drag the green object with mouse or use arrow keys.
B
33
S
10
G
2
Posts: 46
Reputation: 3,063

Post » Mon Apr 10, 2017 7:20 pm

Hi tmntppn,

Thank You. I think this will work.

When I use the arrow to move..when it couches the grey border..it seems to go out a little then jumps back in..

Is there a way to meke so when the green box touches the grey boder it just stops?

Thank You.
B
24
S
4
Posts: 78
Reputation: 1,308

Post » Mon Apr 10, 2017 8:25 pm

Trimeister wrote:When I use the arrow to move..when it couches the grey border..it seems to go out a little then jumps back in..

LOL... I did it on purpose as I thought it was fun and smother... :roll:

There are many ways you can adjust it. Just look at the big picture about how to detect your trigger (arrow keys) and validate the value before you make the move.

Try this: https://www.dropbox.com/s/s68pe4hib7r18 ... .capx?dl=1 (this one isn't using the 8Direction behavior)

I'm not sure what you intend to do with this, if you're going to make multiple objects and obstacle that aren't penetrable anyway, then adding wall objects and solid behavior will be much easier to do: https://www.dropbox.com/s/gmxpetto7mfsa ... .capx?dl=1
B
33
S
10
G
2
Posts: 46
Reputation: 3,063

Post » Tue Apr 11, 2017 6:24 am

Thank you so much tmntppn. It's exactly what I'm looking for. Thanks.
B
24
S
4
Posts: 78
Reputation: 1,308


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo and 24 guests