GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Randomised left / right spawners

Geta-VeGeta-Ve Posts: 18Member
So, I am trying to create a scene where I have 10 spawners, 5 on the left and 5 on the right. I want to be able to randomly choose 5 of those spawners to activate every time I start the game. The tricky part is that the spawner on the opposite side cannot be active when the other is.

See image for clarification.

https://www.dropbox.com/s/x8vamcwlumphca5/randomSpawnProblem.png

There are a few ways I know I can do this but none as simple as I'd like. The first way I thought of doing this is to simply have two separate spawners, SpawnerLeft and SpawnerRight. Another way I thought about doing this is to randomise the spawners position between -10 and 10 on X, and then write a statement that checks its position and activate accordingly (though this still isn't fool proof).

What I'd like to be able to do is have one global spawner, placed in all 10 locations, and randomly choose which to activate itself, taking into account whether or not the opposite is active. This way I only need to manage one set of spawning rules.

I apologize if this is a bit convoluted, I will try to explain alot better if need be.

Thank you kindly!

Comments

  • HopscotchHopscotch Posts: 2,782Member, PRO
    I would use one spawner,


    make a game.attribute for each lane

    In the spawner:
    - choose a lane (1-5) if it is not 1 (active)
    - choose a direction (from left or right)
    - launch the projectile (or something)
    - set a game.attribute for that lane to 1

    (once the spawned projectile reaches the end of the lane set the game.attribute for that lane to 0)

    repeat


    Maybe use a table which holds the coordinates of each lane and its current state.
  • SocksSocks London, UK.Posts: 12,822Member
    edited October 2013
    Assuming a landscape iPad project with actors inset by 100 pixels from the edges. . . .

    Simply place 5 spawners where you require them vertically (it doesn't matter where you place them horizontally) and make the X position for the spawned actor read:

    Spawn Actor at: position X = random ((0,1)*824)+100

    You can also achieve all this with a single spawner by incrementing its Y position with an attribute that counts up to 5, but using 5 spawners saves an attribute or two and makes the generation of the spawned actors pretty much instantaneous.
  • Geta-VeGeta-Ve Posts: 18Member
    Hey guys! Thank you so much for the great responses! I combined some of the advice from both of you and came up with a solution which I think is pretty nice, though still clearly lacking extensibility (as you will soon see).

    What I did was created a spawner_actor which spawned the projectile spawner in 1 of 2 places (essentially left side / right side) dependant on an actor attribute.

    So I have 5 actor attributes -- spawnerLane_01 to 05 (ints)
    Each time I press play my spawner_actor randomises each spawnerLane attribute from 0 to 1 (on or off)
    It then asks
    If spawnerLane_01 = 1
    Do Spawn projectile spawner AT location X, Y (left side)
    Else Spawn projectile spawner AT location X, Y (right side)

    Repeat for each spawnerLane attribute.

    The benefit here is that I only need 2 spawners. 1 to choose the lane and side, and the other to fire the actual projectiles.


    Now, the obvious problem, this is entirely dependant on my current project resolution. I am unaware of a way to have this fit all sizes (or at least all iOS sizes, as the res is more standard and predictable).

    Any help in this department would be super awesome. I have a feeling that I will probably need a slightly different approach to the whole thing, but during the interim it feels great to have figured out this issue, with your help that is!!

    Thank you guys so much!
  • HopscotchHopscotch Posts: 2,782Member, PRO
    edited October 2013
    Do your projectile spawners not change sides during gameplay? Once a left side projectile spawner has been created for lane 1, does it stay there?


    To the resolution issue, could you use a table that contains the predefined x,y positions for each screen size?
  • Geta-VeGeta-Ve Posts: 18Member
    Hey Hopscotch!

    For your first question, they 'projectiles' do not change sides during each play session.

    For the second, I probably could use predefined settings per device, but that seems like an unintuitive way to go about it.

    Though I suppose part of the issue here is that this is more than just simply moving UI elements around.

    Hmmm, I shall have to ruminate on this issue ... :)

    Thank you!!
Sign In or Register to comment.