Jump to content

Rotating a Sprite back to original position


Souleste
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

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