+whenever...
set x to rand(screen_width)
set y to rand(screen_height)
Random point in an area...
+object outside screen
set x to max(min(area_left_x + rand(area_width), 0), screen_width)
set y to max(min(area_top_y + rand(area_height), 0), screen_height)
(you don't really need the min/max as the event would repeat if the new position was outside the screen - in other words, what Milo said)
Random point at a screen edge...
+ object outside screen
+ value = 0
set x to rand(2)*screen_width
set y to rand(screen_height)
set value to rand(2)
+object outside screen
+ value = 1
set x to rand(screen_width)
set y to rand(2)* screen_height
set value to rand(2)
Random point within a certain distance...
+whenever...
set valueA to rand(360)
set valueB to rand(max_dist)
set x to x + cos(valueA)*valueB
set y to y - sin(valueA)*valueB
You could add a fixed value to the random distance to create a random point *beyond* a certain distance.
I like the rand() function
I may write an article about interesting ways to use it someday.
And you might want to put a condition like (if "appearing object" is not overlapping a backdrop) in there too, or your things will teleport inside solid walls. Unless there are no walls or you don't mind.
--
"Del Duio has received 0 trophies. Click here to see them all."
"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"
DXF Games, coming next: Hasslevania 2- This Space for Rent!
Yeah, you'd probably want to use the collision mask or create a detector object for that. You have to be a bit careful with randomly generated stuff - you can't just use the same formula for the detector and the new location as they will be randomly generated separately, and therefore probably not the same.
incidentally, in my second example I got the "min" and "max" the wrong way round. careless...
Event:
- Powerup leaves the frame on the top, bottom, left or right
Action:
--> Set Powerup's Alterable Value A to random(4) + 1
Event:
- Powerup Alterable Value A = 1
Actions:
--> Set Powerup's X Position to 0
--> Set Powerup's Y Position to random(frame height)
--> Set Powerup's Direction to [purple directions]
Event:
- Powerup Alterable Value A = 2
Actions:
--> Set Powerup's X Position to Frame Width
--> Set Powerup's Y Position to random(frame height)
--> Set Powerup's Direction to [blue directions]
Event:
- Powerup Alterable Value A = 3
Actions:
--> Set Powerup's Y Position to 0
--> Set Powerup's X Position to random(frame width)
--> Set Powerup's Direction to [yellow directions]
Event:
- Powerup Alterable Value A = 4
Actions:
--> Set Powerup's Y Position to Frame Height
--> Set Powerup's X Position to random(frame width)
--> Set Powerup's Direction to [green directions]
Event:
- Powerup Alterable Value A > 0
Action:
--> Set Alterable Value A to 0.
To spawn the enemies for Necropolis Rising, I had an invisible box the same size as the enemies bounce around at the start of the frame. Then when the box collided with the player (and the box wasn't overlapping a backdrop, another enemy, or treasure chest) it would spawn at that point and subtract 1 from the total amount of enemies allowed to be on that screen at any one time. (Different areas had different possible max enemies).
It's really basic, but it worked and none of the enemies ever wound up stuck in walls as far as I know.
--
"Del Duio has received 0 trophies. Click here to see them all."
"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"
DXF Games, coming next: Hasslevania 2- This Space for Rent!