PickelHaube Posted July 7, 2017 Share Posted July 7, 2017 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 Quote Link to comment Share on other sites More sharing options...
Langerz82 Posted July 13, 2017 Share Posted July 13, 2017 function clickCupcake(){ cupcake.angle += -10;} sorry - forgot the "+=" See: https://phaser.io/sandbox/DOOngSLg Quote Link to comment Share on other sites More sharing options...
Souleste Posted August 10, 2017 Share Posted August 10, 2017 On 7/12/2017 at 11:32 PM, Langerz82 said: function clickCupcake(){ cupcake.angle += -10;} sorry - forgot the "+=" See: https://phaser.io/sandbox/DOOngSLg I tried this and it will not work, when I click the sprite, nothing happens Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.