Jump to content

movement problem


mohammed alsaqqal
 Share

Recommended Posts

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...