Search the Community
Showing results for tags 'conditional'.
-
I've hit a bug I cannot figure out. I'm trying to make it so that 'x'/buttonfire is the interaction button - if you're in front of something interactive, you interact, if you are not, then the player loops an animation. So when x is hit, it toggles fire on and off. While fire is toggled on, the player should loop an animation. For some reason, the animation I want in the fire loop is not working. The animation I want is "player.animations.play('tink1');", but it stops at the first frame of animation. "player.animations.play('walk');" also doesn't work. But "player.animations.play('stand');" DOES work, and all of the peeve animations work. 'walk' and 'tink1' work if I slot them into other actions. I am very confused. Here is a boiled down version of the game code to show the issue: module.exports = function(game) { var gameState = {}; var player; var ground; var left=false; var right=false; var turnleft=false; var duck= false; var fire=false; scaling = 2; jscaling = 3/5; gameState.create = function () { // PHYSICS this.game.physics.startSystem(Phaser.Physics.ARCADE);//activate physics this.game.physics.arcade.gravity.y = 1200; //realistic gravity this.game.world.setBounds(0, 0, 2000, 300);//(x, y, width, height) this.game.physics.arcade.setBoundsToWorld(true, true, false, true, true); //(left, right, top, bottom, setCollisionGroup) this.game.physics.arcade.friction = 5; // default friction between ground and player or fireballs // STUFF :: SKY this.sky = this.game.add.tileSprite(0,-100,1902*15, '720','sky'); this.sky.scale.setTo(jscaling,jscaling); this.sky.smoothed = false; this.sky.fixedToCamera = true; // STUFF :: peeve peeve = this.game.add.sprite(250, this.game.world.height - 120*jscaling, 'peeve'); //create and position player this.game.physics.arcade.enable(peeve); peeve.body.fixedRotation=true; // do not rotate on collision peeve.anchor.setTo(0.5,0.5); peeve.scale.setTo(jscaling,jscaling); peeve.body.collideWorldBounds = true; peeve.body.allowGravity = false peeve.smoothed = false; // STUFF :: peeve :: ANIMATIONS peeve.animations.add('p_yawn', Phaser.Animation.generateFrameNames('peeve', 9, 12, '', 2), 6, true); peeve.animations.add('p_run', Phaser.Animation.generateFrameNames('peeve', 1, 4, '', 2), 6, true); peeve.animations.add('p_lick', Phaser.Animation.generateFrameNames('peeve', 5, 8, '', 2), 6, true); peeve.animations.add('p_stand', Phaser.Animation.generateFrameNames('peeve', 13, 16, '', 2), 6, true); peeve.animations.play('p_stand'); // STUFF :: PLAYER this.w = this.game.world.width; this.h = this.game.world.height; player = this.game.add.sprite(150, this.game.world.height - 110*jscaling, 'tan'); //create and position player this.game.physics.arcade.enable(player); player.body.fixedRotation=true; // do not rotate on collision player.anchor.setTo(0.5,0.5); player.scale.setTo(jscaling,jscaling); player.body.collideWorldBounds = true; player.smoothed = false; player.body.allowGravity = false; this.game.camera.follow(player); //always center player this.game.camera.deadzone = new Phaser.Rectangle(100, 100, 300, 400); // STUFF :: PLAYER :: ANIMATIONS player.animations.add('tink1', Phaser.Animation.generateFrameNames('tan2', 6, 7, '', 2), 6, true); player.animations.add('stand', Phaser.Animation.generateFrameNames('tan1', 9, 12, '', 2), 6, true); player.animations.add('walk', Phaser.Animation.generateFrameNames('tan1', 1, 4, '', 2), 6, true); player.animations.add('turn', Phaser.Animation.generateFrameNames('tan1', 5, 8, '', 2), 6, true); player.animations.add('sit', Phaser.Animation.generateFrameNames('tan2', 1, 4, '', 2), 6, false); player.animations.play('stand'); // STUFF :: HUD this.inputkeys(); }; var movelike = function(thing){ // add these parameters to the chosen game objects. // thing.checkWorldBounds = true; // thing.outOfBoundsKill = true; thing.scale.setTo(jscaling,jscaling); thing.smoothed = false; thing.anchor.setTo(0.5, 0.5); game.physics.arcade.enableBody(thing); thing.body.allowGravity = false; }; ///////////////// INPUT ///////////// gameState.inputkeys = function () { this.xkey = this.game.input.keyboard.addKey(Phaser.Keyboard.X); this.xkey.onDown.add(this.firenow, this); this.buttonfire = this.game.add.button(this.game.width-48*jscaling, this.game.height-100*jscaling, 'action', this.firenow, this, 1, 1, 1); this.buttonfire.fixedToCamera = true; this.buttonfire.scale.setTo(jscaling,jscaling); this.buttonfire.smoothed = false; this.leftkey = this.game.input.keyboard.addKey(Phaser.Keyboard.LEFT); this.leftkey.onDown.add(function(){left=true;}); this.leftkey.onUp.add(function(){left=false;}) this.buttonleft = this.game.add.button(0, this.game.height, 'buttonleft', null, this, 1,1,1); this.buttonleft.anchor.setTo(0,1); this.buttonleft.fixedToCamera = true; this.buttonleft.scale.setTo(jscaling,jscaling); this.buttonleft.events.onInputOver.add(function(){left=true;}); this.buttonleft.events.onInputOut.add(function(){left=false;}); this.buttonleft.events.onInputDown.add(function(){left=true;}); this.buttonleft.events.onInputUp.add(function(){left=false;}); this.buttonleft.smoothed = false; this.rightkey = this.game.input.keyboard.addKey(Phaser.Keyboard.RIGHT); this.rightkey.onDown.add(function(){right=true;}); this.rightkey.onUp.add(function(){right=false;}); this.buttonright = this.game.add.button(this.game.width, this.game.height, 'buttonright', null, this, 1,1,1); this.buttonright.anchor.setTo(1,1); this.buttonright.fixedToCamera = true; this.buttonright.scale.setTo(jscaling,jscaling); this.buttonright.events.onInputOver.add(function(){right=true;}); this.buttonright.events.onInputOut.add(function(){right=false;}); this.buttonright.events.onInputDown.add(function(){right=true;}); this.buttonright.events.onInputUp.add(function(){right=false;}); this.buttonright.smoothed = false; }; ///////////////// UPDATE ///////////// gameState.update = function () { /// PERSPECTIVEthis.rectangle = new Phaser.Rectangle(this.game.camera.x+100, 100, 300, 200);this.rectangle.fixedToCamera = true;this.game.physics.arcade.collide(player,this.floor); // MOVEMENT :: PLAYER this.playermove(); if (this.game.input.currentPointers == 0 && !this.game.input.activePointer.isMouse){ fire=false; right=false; left=false; jump=false;} //this works around a "bug" where a button gets stuck in pressed stat }; gameState.playermove = function () { if (left) { fire = false; player.scale.x = -1*jscaling; turnleft = true; player.body.velocity.x=-100; player.animations.play('walk'); } else if (right) { fire = false; player.scale.x = 1*jscaling; turnleft = false; player.body.velocity.x=100; player.animations.play('walk'); } else { player.animations.play('stand'); player.body.velocity.x=0; }///////////////////////////////////////////////////////////////////////////////////////////////////////// HERE BE THE ISSUE ////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (fire){ // if (!c_close) { player.body.velocity.x=0; player.scale.x = 1*jscaling; player.animations.play('tink1'); peeve.body.velocity.x=0; peeve.animations.play('p_lick');} else {peeve.animations.play('p_stand');}}; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// gameState.firenow = function () { if (!fire) {fire = true;} else { fire = false;} }; gameState.render = function () {}; return gameState;};
- 3 replies
-
- phaser
- animation loop
-
(and 1 more)
Tagged with: