Spawn instance based on distance to another sprite instance

0 favourites
  • 10 posts
From the Asset Store
Advanced inventory mechanics for your RPG game (Array-based). Take Items, split them, pick up them, read the description
  • 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...

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

  • 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

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

  • Based on your idea I have something like this:

    On layout start: Set Boolean CanSpawn = false, Create Spritemce@X

    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.

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

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

    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

    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.

  • Put the toggle hasspawned action above the system create action

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

  • Try Construct 3

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

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

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