Jump to content

Arc Movement


0penS0urce
 Share

Recommended Posts

I want to make an arc spin in a circular motion by adding 1 to the angle from and the angle to params. When I try to run the code, only one side of the arc moves, so I am guessing that it it's redrawing on itself. Here's the JFiddle link to make it easier.Thanks in Advance! 

var game = new Phaser.Game(640, 480, Phaser.AUTO, '', { preload: preload, create: create, update: update });var x;var y;var oldx;function preload() {    x = 0;    y = 10;    oldx = 0;    }function create() {    }function update() {    oldx = x;    x=x+1;    y=y+1    var graphics = game.add.graphics(game.world.centerX, game.world.centerY);    graphics.lineStyle(1, 0xffd900);    graphics.arc(0, 0, 135, game.math.degToRad(x), game.math.degToRad(oldx+y), false);}
Link to comment
Share on other sites

You probably don't want to be creating a new graphics object every update frame.

Your arc is actually lots of arcs.

 

Move your creation of the graphics object out of the update function into create, and then use the clear() function it has to clear it before redrawing the arc.

function create() {    this.graphics = game.add.graphics(game.world.centerX, game.world.centerY);} function update() {    oldx = x;    x=x+1;    y=y+1    this.graphics.clear();    this.graphics.lineStyle(1, 0xffd900);    this.graphics.arc(0, 0, 135, game.math.degToRad(x), game.math.degToRad(oldx+y), false); }
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...