How do I create a bound to layout?

0 favourites
  • 8 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • 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.

  • 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.

  • 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):

    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
    }
    [/code:3co0tcxe]
  • 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.

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

    You can drag the green object with mouse or use arrow keys.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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... <img src="{SMILIES_PATH}/icon_rolleyes.gif" alt=":roll:" title="Rolling Eyes">

    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

  • Thank you so much tmntppn. It's exactly what I'm looking for. Thanks.

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