Jump to content

Porting to 2.0.1


Meowts
 Share

Recommended Posts

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

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

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

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...