How do I make an object detect other to happen a thing?

0 favourites
  • 5 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 want to know how to make an object, when created, if other exactly one already exist near of it, make it change sprite/frame?

    Something like this:

    On the left, have the object that is already on layout, the object on right is what i am putting after.

    When i put the object on right of the other one, the other change frame to the one you can see on image.

    So, how do i can do that?

    Thanks.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So, no one can show me how to do that or tips? I really need to know how to do that for/on my game.

  • I suggest you have a look at using overlap at offset ?

    so you would get something like

    if (sprite placed) is overlapping at offset (-(X amount),0) -- replace (overlapped sprite) and (sprite placed) with (new sprite)

  • Hello friend.

    I think you should use arrays for this. Maybe you can use the official tilemap as well.

    The idea is that you will have an array, and for each tile on your layout, the corresponding array adress (i.e. x=5 y=10) will hold a value indicating the state of the sprite at that adress.

    Imagine your level as a chessboard. Each square is represented on the array. If there is a piece on any adress, the value in the array will be 1. If empty, it will be 0.

    Then your array will look like this:

    0,0,0,0,0,0,0,0

    0,0,0,1,0,0,0,0

    0,0,0,0,0,0,0,0

    0,0,0,0,0,0,0,0

    0,0,0,0,0,0,0,0

    You will then have an event mechanism that for each adress on the array, checks the neighbouring adresses, and if they also have a sprite in that direction, sprite frames will be updated accordingly. With the above example, since there is only one object on your level, nothing will happen. But if:

    0,0,0,0,0,0,0,0

    0,0,0,1,1,0,0,0

    0,0,0,0,0,0,0,0

    0,0,0,0,0,0,0,0

    0,0,0,0,0,0,0,0

    When the event detects the tile in (3,1) has an object (remember, arrays are 0-based in c2, meaning first line or row starts to count with 0, not 1), it will change it's sprite frame. To which frame it will change you will decide with which direction it has a neigbouring piece. Since in this case it will have a piece on right, (and the piece in(4,1) has a piece on left) it will change accordingly. I hope I could explain myself.

    This is the hard-ish way of doing this, but if you succeed, not only you will have delved deeper into development, you will also have a scalable basis for many other games you could build in the future.

    It may be possible with easier, on-the fly ways but I think this is the best aproach.

  • I got it working using the Compare X condition with 'Greater than Object.X', but it only works in comparison to oher objects and i need to compare the X position of the same 2 objects, for this:

    Can occur.

    Note: I'm not using any behavior on it.

    Suggestions?

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