Inverting conditions

Just started using Construct 2? Post your questions here

Post » Thu Mar 26, 2015 3:14 pm

Probably a dumb question, but I'm making a game where targets pop up randomly and you have to hit them, so I have it set up the system will randomly spawn targets, all the targets spawn in the same respective area, but sometime a target spawns over the same target, which I don't want to happen.
So I've added the Sprite is on screen condition and inverted it, so it should be if the sprite is not on the screen then the action runs, but it just kinda doesn't work. The condition seems to just get passed over like it's not there. I've also tried inverting is on layer and is visible, but they don't work, they'll either get passed over or it wont spawn any targets. Is there a reason this is happening? Is there another way to make the system not spawn the same target again if it has already spawned and it's on screen?
B
4
Posts: 12
Reputation: 224

Post » Thu Mar 26, 2015 7:49 pm

does the first target spawn? are any copies of the Target on the screen at anytime?

if you want to specify a certain target (one of the copies of your Target object) you'll need to reference by UID. Otherwise if you just reference the Target object, that will pick ALL of the objects that are Targets.
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Thu Mar 26, 2015 8:37 pm

There is one of every target off screen, and on different layers from the targets because I couldn't spawn them without at least one on there. But this shouldn't conflict with any of the conditions, because they are off-screen, on a different layer, and not visible. Yes the targets all spawn and I'm just trying to get them to stop spawning multiple over the same one.

So for example, Target1 will pop up but then a second Target1 will spawn and pop up in front of the first Target1. So I'm trying to target whichever Target1 is on-screen at the time and say if there's a Target1 spawned/on-screen do not spawn another Target1 until it is no longer on screen. I hope that makes sense.
B
4
Posts: 12
Reputation: 224

Post » Fri Mar 27, 2015 2:06 pm

Does anyone know this is happening? or a way to get around it at all?
B
4
Posts: 12
Reputation: 224

Post » Mon Mar 30, 2015 2:30 pm

Still need some help with this, can anyone?
B
4
Posts: 12
Reputation: 224

Post » Mon Mar 30, 2015 3:14 pm

Try employing a spawner object and moving that around the screen. I had an example for another question made Here. It has a simple "Enemy spawner" example. See if that helps you a bit. You could have more than one if you's like or modify the time it takes to spawn an enemy. It's not what you have in your game I'm certain, however, the spawner should still be helpfull I've been using it in many of the games I'm making.
Freefall Bird
B
47
S
9
G
5
Posts: 280
Reputation: 5,781

Post » Mon Mar 30, 2015 3:18 pm

If you invert "Sprite: Is on screen" it doesn't mean "are there no sprites on screen?". It means "are there any sprites not on screen?". Which in your case is always true because you have some sprites off-screen.

You could destroy the off screen sprites on start of layout if you don't need them and then check Sprite.count to see if any exist before spawning.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Mon Mar 30, 2015 3:47 pm

I don't need the off screen sprites, but what do you mean by check sprite count? How do you tell it how to check for sprite count?
B
4
Posts: 12
Reputation: 224

Post » Mon Mar 30, 2015 3:54 pm

Use the "System: Compare two variables" condition and enter Sprite.Count as the first value to compare (where Sprite is the name of your sprite).
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Mon Mar 30, 2015 4:00 pm

@WhiffeSniffers as @ramones said you can destroy the sprites at the beginning of the laoyout. I usually add a "destroy outside of layut behaviour" to keep it simple on my end. Or on start of layout I destroy everything I'll be spawning or creating later.
Also you can use the "On created" event of a sprite to check if its on collision with another similar sprite then you could re-locate it to some coordenates for example.
Lets say all your sprites are abbout 32px x 32px if one ends up touching another I would move the one you just created 42px somewhere else (42 because 'Im adding 10px separation just in case) you could use the current x and y coordinates and pick either one to add the 42px to move it somewhere else it shouldn't be too hard.
Freefall Bird
B
47
S
9
G
5
Posts: 280
Reputation: 5,781

Next

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 3 guests