Jump to content

Pivot not working


kmajic
 Share

Recommended Posts

http://phaser.io/sandbox/edit/VUwUUmfd

http://phaser.io/examples/v2/sprites/pivot

2 things you did wrong.

1. The scope of your testsprite is wrong. You made it local to create function, it should be global or child of game.

2. You need to update the rotation of the testsprite in either update or render function otherwise it sits still.

This was your original code:

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload:preload, create:create, update:update, render:render });

function preload() {
	game.load.image("ball", "assets/flat/grey.png");
}

function create() {
	var testSprite = game.add.sprite(200, 200, "ball");
	testSprite.anchor.setTo(0.5);
	testSprite.pivot.x = 100;
}

function update(){
}

function render() {
}

This is how it should be like

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload:preload, create:create, update:update, render:render });

var testSprite;

function preload() {
	game.load.image("ball", "assets/flat/grey.png");
}

function create() {
	testSprite = game.add.sprite(200, 200, "ball");
	testSprite.anchor.setTo(0.5);
	testSprite.pivot.x = 100;
}

function update(){
}

function render() {
	testSprite.rotation += 0.05;
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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