Sign in to follow this  
PickelHaube

Need help with rotation

Recommended Posts

I'm new to phaser and doing a course. I'm a noob so dont make fun of me too much.

anyways, i need to rotate this image of a cupcake when clicking it counter clockwise 10 degrees.

how would i do this?

here is my code right now.


import 'phaser'

var game = new Phaser.Game(500, 300, Phaser.AUTO, 'game', { preload: preload, create: create })

function preload() {
  game.load.image('cupcake', '/api/asset/png/!vault/phaserData.cupcake')
}

// Declare a global variable which we can access in any function in the file
var cupcake

function create() {
  cupcake = game.add.sprite(80, 120, 'cupcake')
  
  // The default sprite anchor point is at the
  // top-left (anchor.x=0, anchor.y=0) of the image
  // We change the anchor point to be the center of the image
  // so that scaling doesn't look weird

  // TODO: Try other anchor points...
  cupcake.anchor.x = 0.5
  cupcake.anchor.y = 0.5
  
  // By default, clicking on a sprite will have no effect.
  // We have to enable this feature as follows:
  cupcake.inputEnabled = true
  
  // sprite has different events. More http://phaser.io/docs/2.4.7/Phaser.Events.html#members
  // we pass a function which is executed when trigger event occurs
  cupcake.events.onInputDown.add(clickCupcake)
  
  // event triggers when we click anywhere on the game screen
  game.input.onDown.add(clickGame)
}

function clickCupcake(){
  cupcake.scale.x += 0.1
  cupcake.scale.y += 0.1
}

this currently makes it grow everytime it is clicked but how would i change it to rotate it instead 10 degrees counter clockwise? thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.