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?
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.
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.
Does anyone know this is happening? or a way to get around it at all?
Still need some help with this, can anyone?
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.
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.
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?
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).
Develop games in your browser. Powerful, performant & highly capable.
— 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.
Thanks guys, the Sprite.Count worked, the targets no longer spawn over each other!
Learn more with demos: