Meowts Posted March 27, 2014 Share Posted March 27, 2014 Heya, I'm porting my game to Phaser 2.0.1 - love the updates, but there are two things I'm not sure how to handle... What I had is an input area sprite, and then an onUp event on the game object - this way the user can click on the area and move the mouse, and the move function will still fire. This is what I had://Add input down event to the clickable areathis.area.events.onInputDown.add(this.accelerate, this);(...)//Add input up to the whole gamethis.game.input.onUp.add(this.move, this);This worked fine with 1.3.1, but what happens now is:-Input down event fires, calls accelerate()-Input up event fires, calls move()-Input down event no longer fires Also, when it comes to setting a sprite's velocity - before if I said something like:this.sprite.body.velocity.x = 100;this.sprite.body.velocity.y = -100;it would sent the sprite flying in the air. Now it's not moving at all. How should I go about sending the sprite on its merry way (using Arcade physics)? Link to comment Share on other sites More sharing options...
JP91 Posted March 27, 2014 Share Posted March 27, 2014 if phaser2 has had some changes and one of them has been the Arcadephysics ehh can you show a little more code? Link to comment Share on other sites More sharing options...
Meowts Posted March 27, 2014 Author Share Posted March 27, 2014 Well, here are the two handlers I have above:accelerate : function (){ this.wasClicked = true; this.sunImg.frame = 0; this.timer.start(); this.powerBar.play('powerUp', 20);},move : function (){ if(this.wasClicked){ //Get total amount time since the click this.timeElapsed = this.timer.seconds+1.1; this.timer.update();//I had this before and it worked fine, necessary? this.timer.stop(); this.powerBar.animations.stop('powerUp'); if(this.timeElapsed > this.maxTime){ this.timeElapsed = this.maxTime; } //Set velocity this.sprite.body.velocity.x = this.timeElapsed*100; this.sprite.body.velocity.y = -(this.timeElapsed*160); this.area.inputEnabled = false; this.wasClicked = false; }}//end move()//Also FYI when a new sprite is spawned, this.area.inputEnabled = true;With 1.3.1, the result of this would send the sprite across the screen, its distance depending on how long you held down the click. Now, unfortunately, it does nothing :\ Link to comment Share on other sites More sharing options...
JP91 Posted March 28, 2014 Share Posted March 28, 2014 Hi,you can already test Phaser 2.0.2,mmmmm "this.timer.update()" I think it is automatically called for the core. Link to comment Share on other sites More sharing options...
jyapayne Posted March 28, 2014 Share Posted March 28, 2014 You do have to enable the physics system if you want to use bodies and velocity.game.physics.startSystem(Phaser.Physics.ARCADE);And then if you want to use it on a sprite:game.physics.arcade.enable(sprite);Also, refer to http://examples.phaser.io/_site/view_full.html?d=arcade%20physics&f=launcher.js&t=launcher for an example of something similar. Hope that helps! Link to comment Share on other sites More sharing options...
Meowts Posted March 28, 2014 Author Share Posted March 28, 2014 Thanks, I noticed about an hour after this debacle that 2.0.2 had just those fixes, also learned about manually enabling physics on the Sprites. I haven't had a chance to implement this yet, but I'm sure it'll work Link to comment Share on other sites More sharing options...
Recommended Posts