i3Designer Posted March 14, 2014 Share Posted March 14, 2014 I created two variables: X = game.world.randomX; Y = game.world.randomY; But I would like to create a random Min and Max That I have a 600x400 game, I want the objects appear out of the game and go to the middle of the game (also close to downtown, random). With random speed. I have also used: ball.body.velocity.x = 100 + Math.random () * 200; How does the math random?, Sorry too many questions but I have difficulties with English you can not find good guides. Link to comment Share on other sites More sharing options...
Heppell08 Posted March 14, 2014 Share Posted March 14, 2014 minX = this.rnd.integerInRange(0, 200);maxX = this.rnd.integerInRange(200, 400);The rnd will pick randomly between 2 given numbers. In the example above minX can be anything between 0 and 200. Link to comment Share on other sites More sharing options...
i3Designer Posted March 14, 2014 Author Share Posted March 14, 2014 .... function creaAsteroide() { X=game.world.randomX; Y=game.world.randomY; asteroide=game.add.sprite(X,Y,'asteroide'); // asteroide.body.velocity.x=100+Math.random()*200; // asteroide.body.velocity.y=100+Math.random()*50; } So the asteroid is random in the game, but outside? how can I? I did not understand. Excuse me. Link to comment Share on other sites More sharing options...
Heppell08 Posted March 14, 2014 Share Posted March 14, 2014 asteroide.body.velocity.x= this.rnd.integerInRange(minimum number, maximum number); Its always a random amount with the rnd built in to phaser. So if you wanted the speed of it to be between 200 and 500, you could use integerInRange to decide randomly between the 2 numbers.So the asteroid could come in at 356 velocity and the next could be 297 speed. It will use any number between the 2 given numbers you specify it to be. Link to comment Share on other sites More sharing options...
i3Designer Posted March 14, 2014 Author Share Posted March 14, 2014 Ok I understand but Link to comment Share on other sites More sharing options...
rich Posted March 14, 2014 Share Posted March 14, 2014 If:this.rnddoesn't work then use:game.rnd i3Designer 1 Link to comment Share on other sites More sharing options...
i3Designer Posted March 14, 2014 Author Share Posted March 14, 2014 Thaaaaanks Rich. You're doing a great job with Phaser, you are a great man. Sorry if I did not understand but they are new, it is unfortunately not knowing English well, I have difficulty to understand the few guides. Link to comment Share on other sites More sharing options...
Heppell08 Posted March 14, 2014 Share Posted March 14, 2014 Yeah sorry I use states so a majority of my code is:this.world or this.rndIf this doesn't work then yeah as Rich said, use game.rnd or game.world. Glad you got it up and running though. Link to comment Share on other sites More sharing options...
Recommended Posts