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

Just started using Construct 2? Post your questions here

Post » Wed Feb 10, 2016 3:00 am

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

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.

Thanks!
B
13
Posts: 20
Reputation: 457

Post » Wed Feb 10, 2016 4:04 pm

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?
B
7
S
2
Posts: 56
Reputation: 583

Post » Thu Feb 11, 2016 4:00 am

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.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
65
S
17
G
8
Posts: 635
Reputation: 9,331

Post » Thu Feb 11, 2016 5:12 am

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.

Image

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!
B
13
Posts: 20
Reputation: 457

Post » Thu Feb 11, 2016 9:12 am

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

Image

I'm sure you can see that didn't work either :lol: I was trying to 'Pop' to the next object but that didn't work! In fact, it didn't even fire at all!
B
13
Posts: 20
Reputation: 457

Post » Thu Feb 11, 2016 2:33 pm

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.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
65
S
17
G
8
Posts: 635
Reputation: 9,331

Post » Thu Feb 11, 2016 3:18 pm

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 array.at(0)
pop front

Imagen your array as a bullet clip full of colors...you 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..


Image
B
7
S
2
Posts: 56
Reputation: 583

Post » Thu Feb 11, 2016 10:08 pm

Image
B
63
S
23
G
7
Posts: 1,480
Reputation: 10,796

Post » Sun Feb 14, 2016 2:31 am

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!!
B
13
Posts: 20
Reputation: 457

Post » Sun Feb 14, 2016 2:32 am

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
B
13
Posts: 20
Reputation: 457


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests