Enemies spawning and following camera
as in my previous discussion i had explained myself in detail about my situation... the height of the scene is 320 and the width is 10,000. I have an actor that is constrained to the player that is called collision and when enemies crashes into it the actor is destroyed. i have an enemy spawner that randomly spawns around the screen so enemies come flying in and try to crash into the player from all directions. The players x and y positions are constrained with the camera origins x and y. The enemies follow the player until the camera moves to the right then the enemies just fly a certain distance to the right of the player and explode (instead of crashing into the player) but if you restart the scene and dont cause the camera to move the enemies come flying right at you. The collision is perfectly centered with the player the whole time. But ive found a hint to this matter... when i make the enemy spawner scrollable on the scene then the enemies follow you perfectly the whole time but then the spawner is left behind to the left side which causes the enemies to only spawn on the left. I found the issue on what was wrong.... the enemy is being spawned in the non scrollable layer because the actor that spawns the enemy needs to be in a non scrollable layer (as i tested an enemy being in both layers and the scrollable followed me the whole time) BUT the issue is that the enemy spawner has to stay non scrollable so it can keep spawning around the screen but how can i modify the code in it to make it in a scrollable layer but still spawn randomly around the screen i have screen shots of code in the actor that spawns the enemies:
Part 1:
http://postimg.org/image/dmxj45sjx/
Comments
Bump.
Just of the top of my head use the camera origin X and Y plus your spawn positions. You will need to unlock the instance of the actor and go to Current Scene/Camera/Origin/X or Y.
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
im kind of confused what should i put for the x and y positions for the enemies when they spawn? @colander
For example in the Spawn Actor action the X position would be scene.Camera.Origin.X + random(?,?). I used ? because I can not see your values on the screenshot.
I noticed you used 568 in your Y position setting. You should also avoid using hard values where it makes sense and is possible. Instead use attributes you create or better still device size (game.Screen.Size.Height), actor size (self.Size.Height), etc. This way if you change say an actors width you wont have to go and manually change that value in all code which uses that dimension in a calculation. It also makes creating a universal binary easier to deal with.
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
@colander ok so im a little confused still i have this for my code so far...
for spawning on the top of the screen i have
position>: scene.camera.origin.x+random(0,320) and position^: 568+30
for spawning at the right:
position>: 568+30 and position^: scene.camera.origin.x+random(0,320)
for spawning on the bottom:
position>: scene.camera.origin.x+random(0,320) and position^: 0-30
for spawning on the left i have:
position>: 0-30 and position^: scene.camera.origin.x+random(0,320)
is this correct because when i tried this the left and right sides arent spawning correctly.... but the top and botttom are working. nothing is spawning from the right side so what should i alter?
Here's a debugging tip: in the right and left spawned actors, add a Log Debugging Statement at the top of their rules list (not in any rule, just standalone): self.position.Y.
Then open the Debugger window and see what shows up. If nothing shows up, then you're right that they aren't getting spawned. If some huge number shows up, then you know that they spawned way off screen.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Im sorry i didnt make my results detailed enough. what i meant was that the left and right side of enemies is still spawning at the starting point of the scene and not with where the camera is at. the top and bottom parts of the spawner are working fine they spawn where ever the camera is at but the left and right side still spawn at the beginning of the scene so when you keep moving to the right the left and right side of the enemy spawner is still at the beginning of the scene while the top and bottom are spawning at where ever the camera is at. @tatiang
What is the actual value of scene.camera.origin.x when you spawn the actors? And what do you expect it to be?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
the scene.camera.origin.x is constrained to the player's x position - 285 so that the player always stays in the center @tatiang
I'm actually getting at a way to debug your code. People (myself included) often assume that the way they've set up their code is correct and GameSalad is somehow mysteriously betraying them. But then if they log the actual values, they find that -- surprisingly! -- the values aren't what they expected. Based on what you say, scene.camera.origin.x should be easy to predict, but it's still worth checking.
What happens when you log the value of that attribute at the moment the actor is spawned? And also the value of self.position.X? I would put both log statements inside the actor(s) that gets spawned.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Ehhh well this is what i did so far. I logged the players x position in the debugger. right when the scene started the players x position was at 285 and the position of the camera x was at 0 now logging the enemy position is kind of difficult to do because there are so many of them being spawned at once the debugger logs all of them in. i was getting all these random numbers from the enemy x positions. @tatiang
Sounds like you need to simplify things. Try spawning ONE enemy so that you can log the position.
You're welcome to send me the project file (as a .zip) if you'd like me to take a look.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Ok I'll send it to you @tatiang
Sent you a PM.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Track your players X,Y position and your players speed then just have your enemies move to players X based on camera speed plus or minus a few more and make sure both are on scrollable layers.