Jump to content

Screen flickering and animations not working


Julia
 Share

Recommended Posts

Edit: it's not actually flickering, more shaking (only up and down).

Hey,

 

I'm (still) trying to make a vertical platformer game. I'm having a problem here where my screen is flickering and my animations for the player don't work anymore if I press the keys. Also the player won't jump anymore. I'm guessing it has something to do with the gravity or the velocity of the player or the game itself. Any ideas?

 

Platformer.Game = function (game) {this._player;this._stars = null;this._ground = null;this._platforms = null;this._platform = null;this._numberOfPlatforms = 15;this._x = this.x;this._y = this.y;this._cursors = null;this._scoreText = null;this._score = 0;this._locs = [];};Platformer.Game.prototype = {create: function (){this.physics.startSystem(Phaser.Physics.ARCADE);this.add.sprite(0, 0, 'background');this._ground = this.add.sprite(game.world.centerX - 480, game.world.height - 124, 'ground');this.physics.enable(this._ground, Phaser.Physics.ARCADE);this._ground.body.immovable = true;this._player = this.add.sprite(this._x, this._y, 'player');game.physics.enable(this._player, Phaser.Physics.ARCADE);this._player.body.gravity.y = 300;this._player.body.bounce.y = 0.2;this._player.animations.add('walk', [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16], 10, true);this._fontStyle = {font: "40px Roboto", fill: "#fff", align: "center"};Platformer._scoreText = this.add.text(120, 20, "0", this._fontStyle);this._platforms = this.add.group();for (var i = 0; i < 20; i++) {this.createUniqueLocation();}this._platforms.sort();game.camera.follow(this._player);},managePause: function () {this.game.paused = true;var pausedText = this.add.text(100, 250, "Game paused. Click anywhere to continue.", this._fontStyle);this.input.onDown.add(function(){pausedText.destroy();this.game.paused = false;}, this);},update: function () {if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)){this._player.x -= 10;this._player.animations.play('walk');}if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)){this._player.x += 10;this._player.animations.play('walk');}if (game.input.keyboard.isDown(Phaser.Keyboard.UP) && this._player.body.blocked.down) {this._player.y -= 10;this._player.animations.play('walk');}else {this._player.frame = 0;}this._platforms.sort('y', Phaser.Group.SORT_ASCENDING);game.physics.arcade.collide(this._player, this._ground);},createUniqueLocation: function () {do {var x = this.math.snapTo(game.world.randomX, 300) / 100;var y = this.math.snapTo(game.world.randomY, 75, this._player.y - 100) / 75;if (y > 35) {y = 35;}var idx = (y * 35) + x;}while (this._locs.indexOf(idx) !== - 1)this._locs.push(idx);this._platforms.create(x * 200, y *75, 'platform', this.rnd.integerInRange(0, 25));}};
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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