khleug35 Posted March 25, 2018 Share Posted March 25, 2018 Here is my full code of the example. https://jsfiddle.net/d7p7upso/4/ First, I prepared two image, One for main character , one for On Screen control Button 1. 2. I hope I can do that When User click and hold on the "DOWN" button or Green Button The sprite will hold crouch image like this But unlucky...... The sprite is looping the sprite Anyone have idea how to make the spite complete his animation and hold it in last frame??? Thank you very much , I am sorry for my pool english var game = new Phaser.Game(500, 300, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update}); var crouchFlag = false; function preload() { game.stage.backgroundColor = '#85b5e1'; game.load.spritesheet('player', 'assets/crouch.png',45,65); game.load.image('button', 'assets/HitBoxButton.png'); } function create() { player = game.add.sprite(100, 100, 'player'); player.customParams = {}; cursors = game.input.keyboard.createCursorKeys(); crouchAnim = player.animations.add('crouch', [0, 1, 2, 3], 10, false); crouchAnim.onComplete.add(function () { crouchFlag = false; }); Button1 = game.add.button(game.width - 200, game.height - 120, 'button'); Button1.scale.setTo(0.5); Button1.events.onInputDown.add(function(){ player.customParams.isCrouch = true; }, this); Button1.events.onInputOver.add(function(){ player.customParams.isCrouch = false; }, this); Button1.events.onInputUp.add(function(){ player.customParams.isCrouch = false; }, this); Button1.events.onInputOut.add(function(){ player.customParams.isCrouch = false; }, this); } function update () { if (cursors.down.isDown || player.customParams.isCrouch) { crouchFlag = true; } else{ } console.log(crouchFlag); if (crouchFlag) { player.animations.play('crouch'); } else{ player.frame = 4 } } Link to comment Share on other sites More sharing options...
Recommended Posts