Souleste Posted August 10, 2017 Share Posted August 10, 2017 I am trying to make a gate that opens when you click on it, and rotate it 90 degrees. I have accomplished this much, but how do I make it go back to it's original position once I click on it again? For instance: *clicks on gate, gate opens, 90 degrees.* *clicks on gate again, gate closes, -90 degrees from the 90 degrees that it went on previous click* Any help would be appreciated! html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Simple Canvas Game</title> <style> html { background: black } canvas { margin: auto; } </style> </head> <body> <script src="phaser.js"></script> <script src="game.js"></script> </body> </html> game.js var game = new Phaser.Game(550, 540, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.crossOrigin = 'anonymous'; game.load.image('gateopen', 'fenceleft.png'); } var sprite function clickSprite() { console.log("clickSprite"); sprite.angle += 90; } function clickGame() { console.log("clickGame"); } function create() { sprite = game.add.sprite(100, 100, 'gateopen'); sprite.anchor = {x: 1, y: 1} game.inputEnabled = true; sprite.inputEnabled = true; sprite.events.onInputDown.add(clickSprite) game.input.onDown.add(clickGame); } function update() { } function render() { game.debug.bodyInfo(sprite, 32, 32); game.debug.body(sprite); } Link to comment Share on other sites More sharing options...
samid737 Posted August 10, 2017 Share Posted August 10, 2017 something like this? function clickSprite() { console.log("clickSprite"); sprite.angle =90-sprite.angle; } Link to comment Share on other sites More sharing options...
Sturb Posted August 10, 2017 Share Posted August 10, 2017 You could have a boolean to determine the state of the door (open/closed) then do something like: function clickSprite() { console.log("clickSprite"); isOpen = !isOpen; sprite.angle = isOpen ? 90 : 0; } raaaahman 1 Link to comment Share on other sites More sharing options...
Recommended Posts