Spawn actors outside screen?

Hello i want to spawn actors outside screen but don’t really get how,

actor.x = math.random(50,700)
actor.y = math.random(50,900)

this way i can random spawn actors inside the stage but how do i randomly spawn outside the stage?

If i only wanted it to spawn from one side i could easily do it but how do i spawn randomly from all four sides?

Anyone who can push me in a direction;)?
Cheers [import]uid: 90942 topic_id: 23410 reply_id: 323410[/import]

I’m asuming you’re working in portrait mode here.

you would need to first determine which side of the screen the actor is going to start from so:

screenSide = math.random(1,4)

so lets say if screenSide = 1 then the actor starts on the right hand side of the screen.

function whichSide()  
 if screenSide = 1 then -- right side  
 actor.x = \_W + actor.contentHeight / 2  
 actor.y = -- whatever you want the y position to be  
 end  
  
 if screenSide = 2 then -- bottom  
 actor.x = --whatever x position you want  
 actor.y = \_H + actor.contentHeight / 2  
 end  
  
 if screenSide = 3 then -- left side  
 actor.x = 0 - actor.contentWidth / 2  
 actor.y = --whatever y position you want  
 end  
  
 if screenSide = 4 then -- top  
 actor.x = --whatever x position you like  
 actor.y = 0 - actor.contentHeight / 2  
 end  
  
end  

Hope that helps? [import]uid: 67933 topic_id: 23410 reply_id: 93813[/import]

Hello Spider!

That helps alot, its in landscape but that dosent matter:) with this i now can spawn them pretty easy:) (at least i hope so:))

Thank you very much:) [import]uid: 90942 topic_id: 23410 reply_id: 93820[/import]