kmajic Posted September 2, 2016 Share Posted September 2, 2016 Hi all! I'm trying to make a sprite pivot, as simple as that. However, it won't work and I'm not sure if I'm missing something. I checked the tutorials/examples and I can't see the problem:http://kresimir.majic.eu/games/single_state/pivot.html I'm kinda stuck, so any help would be greatly appreciated! Thanks! Link to comment Share on other sites More sharing options...
symof Posted September 3, 2016 Share Posted September 3, 2016 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 More sharing options...
kmajic Posted September 3, 2016 Author Share Posted September 3, 2016 Bah! I feel so silly now... Thank you so much! Link to comment Share on other sites More sharing options...
Recommended Posts