How do I spawn a list of Objects/Bullets on touch

0 favourites
  • 10 posts
From the Asset Store
This pack contains 10 types of bullet effects, with different shapes and colors.
  • Hi Guys,

    I'm a newbie around here, I've been playing with construct for a few days now and I've got stuck on this game I'm trying to make!

    The basic problem is: I want to be able to spawn a list of different color bullets to fire from my turret. The turret is in a fixed position and is currently spawning on touch, kind of like a bubble shooter mechanics I guess.

    So for instance, I want it to shoot: Green, Green, Red, Red, Blue then Red - I would want to modify this for each level.

    Ideally I would also like to be able to show the color of the current bullet and the next one below at the turret point like in the attached picture.

    I've thought of maybe using Global Variables to trigger different Animations and looked at a bunch of other stuff but feeling a bit lost, if someone could point me in the best direction to look it would be much appreciated.


  • Hi,

    you need an 1d array (a list) for this.

    Just fill it with colors and on every shoot take the first color for your shoot and then "pop" the first value.

    You could also use the 1,2,3 value to show whats coming next.

    Also do you want to set the list manualy for each level or make it random?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You could hack this with events but dsminor is right about a single dimensional array being best for what your trying to do.. would make it super easy to level change.

    Plus its a really good opportunity to force yourself to learn arrays in Construct2.. the 1d is really all you need for about 90% of Construct2 projects and it easy to learn.

  • Thanks for the advice guys, I'm slowly wrapping my head around it by watching some Youtube videos! I still havn't quite worked out a solution yet though.

    This was my attempt at an ugly workaround, I ran into trouble though when adding the third arrow, it fires at the same time as the last green one.

    So I understand that I can set values to certain numbers on X in a 1D array, I just don't understand how to set say 0 = GreenArrow, 1= Red etc and then edit the sequence for each level!

    I'll keep playing!

  • So I tried this but It was more just guessing than anything, I still can't quite get my head around it!!

    I'm sure you can see that didn't work either I was trying to 'Pop' to the next object but that didn't work! In fact, it didn't even fire at all!

  • You could always put all your colored projectiles into one static animation and then call them by frame# using a sequence variable.

    You would need to put an instance variable on your weapon, lets call it shotNumber=0. Set up conditions that refererence this variable then action out to spawn bullet object and set frame to appropriate color.. ie shotNumber=1 spawh object and set to blue frame, shotNumber=2... etc.

    As for the upcoming shot as long as you have a set frame order for the level (shotNumber1-2-3-4-5-6 = frames# 1-6.. then you could display object below weapon and show the next shotNumber value frame...

    For levels you would need a new order of frame numbers but you could put them all on one sheet and condition a global level=# in your events.

  • Hi,

    chrisinfinger is right you only need ONE object called arrow/bullet with different animation frames and an instance variable called colors/typ.

    Thats much easier than having an object for each different arrow.

    It doesent work because the curent value is not 0 nor 1 or 2

    The current value is the content of the cell NOT the x-coordinate.

    Also current value only works in an loop.

    (It is the content of the cell which is actually accessed in the "for each element loop".)

    You need someting like that:

    on touch:

    spawn bullet

    set bullet color/typ to

    pop front

    Imagen your array as a bullet clip full of shoot the first one and the second is then becoming the first one and you shoot it again. The position you shoot from is always the first but the colorbullet in it changes..

  • example.capx

  • Thanks for all the advice guys! There are a couple good solutions there, I did look at that .capx example and that was great fun to try and deconstruct.

    I did get the array to work as above but encountereed a problem where the array wouldn't reset back to its original values on the restart if the game was failed? I had to refresh the preview page for it to reset fully. I had the 'Set Value' under 'On Start of Layout' so couldn't figure out where I went wrong there.

    I've ultimately decided to go with the instance behaviour solution though as it worked first time for me!!

  • Also for some reason now the Spritefont I had to display the number has stopped working, it's value is based on the global variable 'level' which seems to be updating fine? I'm sure it's something silly but any ideas?

    Thanks again

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