mohammed alsaqqal Posted March 31, 2016 Share Posted March 31, 2016 im trying to move this prefab in random way var BasicGame = BasicGame || {}; BasicGame.balls = function(game ,x,y ,vx,vy, key) { Phaser.Sprite.call(this,game,x,y,vx,vy,key); this.game=game; this.game.physics.arcade.enable(this) ; this.body.collideWorldBounds = true; this.body.bounce.setTo(1, 1); this.body.velocity.x = vx; this.body.velocity.y = vy; this.body.immovable = true; this.body.drag = true ; }; BasicGame.balls.prototype = Object.create(Phaser.Sprite.prototype); BasicGame.balls.prototype.constructor = BasicGame.balls ; this is main js create function code var ball1 = ['greenb1' , 'greenb2' , 'greenb3' , 'greenb4' , 'blueb1' ,'blueb2' , 'blueb3' , 'blueb4' , 'redb1' , 'redb2' , 'yellowb1','yellowb2','orangeb1','orangeb2' , 'silverb1' , 'silverb2' , 'pinkb1' , 'pinkb2'] ; var x = this.game.world.randomX; var y = this.game.world.randomY; this.minSpeed = -75; this.maxSpeed = 75; var vx = Math.random()*(this.maxSpeed - this.minSpeed+1)-this.minSpeed; var vy = Math.random()*(this.maxSpeed - this.minSpeed+1)-this.minSpeed; var b1 = new BasicGame.balls( this.game ,x,y ,vx , vy ,Phaser.ArrayUtils.getRandomItem(ball1)); //Phaser.ArrayUtils.getRandomItem() this.game.add.existing(b1) ; Link to comment Share on other sites More sharing options...
megmut Posted March 31, 2016 Share Posted March 31, 2016 Could you be more specific and say what's wrong with the code you've written, or what you'd like help with? Link to comment Share on other sites More sharing options...
Recommended Posts