# How do I... (Instances in a space-invader type of game)

Get help using Construct 2

### » Wed Nov 25, 2015 12:21 am

Hey all,

I'm creating a vertical space shooter game for a game design course, and I have a specific question:

I've set up a system where a spotlight is pinned to a cannon that moves along the X axis. What I want to have happen is as the spotlight overlaps an enemy, I want the lowest instance to trigger a pulse effect, as well as play a musical note.

How would I go about setting this up?
B
5
Posts: 12
Reputation: 249

### » Wed Nov 25, 2015 12:29 am

Let me make sure I understand you here. You must have a setup somewhat similar to this:

Pretend my black stars here are enemies. You want the lowest (i.e. closest to the bottom of the screen) enemy to trigger a pulse effect and play a note when it overlaps with the spotlight. Is this what you mean by 'lowest instance'?
B
12
S
4
G
1
Posts: 30
Reputation: 946

### » Wed Nov 25, 2015 12:32 am

with the lowest instance you mean the one with the highest y-position?

I guess a system for each sprite ordered y ascending event setting a variable to the sprite.uid and picking sprite by uid = variable would work..
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

### » Wed Nov 25, 2015 12:33 am

Let me make sure I understand you here. You must have a setup somewhat similar to this:

Pretend my black stars here are enemies. You want the lowest (i.e. closest to the bottom of the screen) enemy to trigger a pulse effect and play a note when it overlaps with the spotlight. Is this what you mean by 'lowest instance'?

Yeah, that's exactly it! The only difference being that the spotlight is a box, and not angled like that.
B
5
Posts: 12
Reputation: 249

### » Wed Nov 25, 2015 12:36 am

Another thing to consider that I totally didn't mention is on the enemy spawn, they are assigned a variable (1,2,3).

So if enemy.music = 1, play a C note, if enemy.music = 2, play an E note, etc.
B
5
Posts: 12
Reputation: 249

### » Wed Nov 25, 2015 12:38 am

LittleStain wrote:with the lowest instance you mean the one with the highest y-position?

I guess a system for each sprite ordered y ascending event setting a variable to the sprite.uid and picking sprite by uid = variable would work..

I tried this earlier, but I feel like I didn't nest a few of the commands properly ~
B
5
Posts: 12
Reputation: 249

### » Wed Nov 25, 2015 12:47 am

LittleStain wrote:with the lowest instance you mean the one with the highest y-position?

I guess a system for each sprite ordered y ascending event setting a variable to the sprite.uid and picking sprite by uid = variable would work..

I tried this earlier, but I feel like I didn't nest a few of the commands properly ~

Without seeing your events I wouldn't know, maybe true, maybe false..
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

### » Wed Nov 25, 2015 12:49 am

Hang tight, I'll print screen. I really appreciate the help, by the way!
B
5
Posts: 12
Reputation: 249

### » Wed Nov 25, 2015 12:50 am

You might need to right click and 'view image' to read the comments correctly depending on your resolution.

Try something like this on for size. This will pick the correct enemy for you to play your pulse and sound effects at. Those shouldn't be too difficult for you to implement. Hint: The 'Play by Name' audio combined with Enemy.Music should give you an easy way to play different sound effects for different enemies.

Let us know if you get stuck.
B
12
S
4
G
1
Posts: 30
Reputation: 946

### » Wed Nov 25, 2015 12:52 am

Woah! So quickly too. I'll give it a shot and report back.
B
5
Posts: 12
Reputation: 249

Next