Jump to content

Need help with rotation


PickelHaube
 Share

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

Link to comment
Share on other sites

  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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