actionscript 3 - How to make an object randomly spawn inside of the stage only -


my stage size 640 x 1136

i want spawn objects randomly inside of stage.

i used this

object.x = math.random() * stage.stageheight; 

how can make x position spawn within stage area?

you want "random in range" function like 1 here (included below).

however, if doing game may not satisfied result of randomly spawning objects (e.g. objects piling on each other, etc.) , want exert more control. lots of ways clever – like defining set of regions or quadrants, picking 1 of randomly , generating random coordinates within region, or having array of defined "good" points , randomly selected it. actual randomness less interesting idea or appearance of randomness.

public function randrange(minnum:number, maxnum:number):number {    return (math.floor(math.random() * (maxnum - minnum + 1)) + minnum); } 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -