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

Get help using Construct 2

Post » Sun Apr 27, 2014 2:57 pm

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:

Image

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

Post » Mon Apr 28, 2014 2:24 am

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

Post » Mon Apr 28, 2014 8:44 am

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)
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Mon Apr 28, 2014 10:24 am

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.
B
18
S
4
G
1
Posts: 332
Reputation: 3,149

Post » Mon Apr 28, 2014 12:27 pm

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:

Image

Can occur.

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

Suggestions?
B
5
S
1
Posts: 5
Reputation: 396


Return to How do I....?

Who is online

Users browsing this forum: Christmas, irina, minigame and 6 guests