Spawn instance based on distance to another sprite instance

Get help using Construct 2

Post » Sat Dec 05, 2015 7:01 am

How would I go about spawning a sprite instance based on the distance in X another sprite instance?

sprite instance<------------- x distance -------------->another sprite of the same instance<------------- x distance -------------->another sprite of the same instance ...etc..

Am I right in thinking that I need to make an array and add the x position of the first spawned instance to that array, then compare values, then create another
instance and add its x position to the array?

Time to sleep, will think about this tomorrow, in the meantime any help will be appreciated.

Thanks and goodnight for today.

Ps. Or maybe using an invisible sensor sprite? Hmm...

EDIT
I think would have to track the X position of the instance as it is moving constantly...
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Sat Dec 05, 2015 2:34 pm

What I figured so far, but having problem implementing it in code:

On Layout Start: Spawn sprite in position(x,y)

For each spawned sprite
___Store sprite.x in array.pos(0,0)

If array.pos(0,0) < 800
___Spawn sprite in position (x,y)
___Store recent spawned sprite.x in array.pos(0,0)


Now the problem is that the x of the sprite is constantly moving at different speeds, I have to track it all the time. I was wondering how to do that?
Also, how do I store the recent spawned X in the array?

The sprite has a CustomMovement behaviour.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Sat Dec 05, 2015 2:41 pm

Would something like this work?

Give the sprite a boolean HasSpawned

system for each sprite
sprite is not boolean HasSpawned
sprite.x < 800
> system create sprite at (x,y)
> sprite set boolean spawned to true
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Dec 05, 2015 2:55 pm

Thanks for the reply, I was wondering If the sprite has not spawned yet how can the system check if its x value is lower than 800?
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Sat Dec 05, 2015 3:03 pm

Based on your idea I have something like this:

On layout start: Set Boolean CanSpawn = false, Create [email protected]

IF Sprite.X < 800
Set CanSpawn = True

IF CanSpawn = true
Create Sprite @ X
Set CanSpawn = false


But I would need to store the Sprite.X in an array for each instance and override the 1 value in the array? And that array value for each Sprite.X instance would have to be compared to <800. But how can I store each x for each instance in 1 field and override it? Would it use the For loop?

For each created instance > store sprite.x @ array.pos(0,0) ?

Eh, got mixed up again.
Last edited by Solomon on Sat Dec 05, 2015 3:06 pm, edited 1 time in total.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Sat Dec 05, 2015 3:05 pm

Well, in this example hasspawned only checks if a sprite has already spawned another sprite, not if it itself is created..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Dec 05, 2015 4:35 pm

LittleStain wrote:Well, in this example hasspawned only checks if a sprite has already spawned another sprite, not if it itself is created..


Ah, ok I get the reasoning behind it, thanks.

LittleStain wrote:Would something like this work?

Give the sprite a boolean HasSpawned

system for each sprite
sprite is not boolean HasSpawned
sprite.x < 800
> system create sprite at (x,y)
> sprite set boolean spawned to true





Sadly it doesnt work :(

Image

If I add 1 box from the beginning a line just forms of the boxes then they stop.

If I dont add a box then just 1 box is created.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Sat Dec 05, 2015 4:45 pm

Put the toggle hasspawned action above the system create action
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Dec 05, 2015 4:51 pm

LittleStain wrote:Put the toggle hasspawned action above the system create action


Wha...What kind of magic is this?? You sir are a genius! Thanks it works like a charm now!
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Sat Dec 05, 2015 5:07 pm

Construct2 reads events top to bottom..
If the HasSpawned action is above the create-action it acts on the instance referenced in the event, if it's below the create-action it acts on the instance just created..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775


Return to How do I....?

Who is online

Users browsing this forum: batto, bclikesyou, Lancifer and 25 guests