Climbus Posted December 21, 2014 Share Posted December 21, 2014 Hi all I've got a problem with physics in my game. Sometimes my player sprite is moving forward to end of world or colliding object. I'm testing it by refreshing a page. Sample code below.var Plain = Plain || {};Plain.Game = function(){};Plain.Game.prototype = { preload: function() { // sprite atlases this.load.atlasJSONHash('player', 'assets/images/player.png', 'assets/sprites/player.json'); // levels this.load.tilemap('level', "assets/maps/level1.json", null, Phaser.Tilemap.TILED_JSON); // layers this.load.image('land', 'assets/images/green_land.png'); }, create: function() { this.map = this.add.tilemap('level'); this.map.addTilesetImage('green_land', 'land'); this.backgoundLayer = this.map.createLayer('Land'); this.backgoundLayer.resizeWorld(); this.physics.startSystem(Phaser.Physics.ARCADE); this.cursors = this.input.keyboard.createCursorKeys(); this.camera.y = this.world.height - this.camera.height; this.player = this.add.sprite(400, 2300, "player", 1); this.player.anchor.setTo(0.5, 0.5); this.player.scale.x = 1.3; this.player.scale.y = 1.3; this.player.fixedToCamera = false; this.physics.arcade.enable(this.player); this.player.body.velocity.x = 0; this.player.body.velocity.y = -10; this.player.body.collideWorldBounds = true; this.player.health = 100; this.player.points = 0; }, update: function() { //this.camera.y -= 4; this.time.advancedTiming = true; this.player.body.velocity.x = 0; if (this.cursors.down.isDown) { this.player.body.velocity.y += 10; } else if (this.cursors.up.isDown) { this.player.body.velocity.y -=10; } if (this.cursors.left.isDown) { this.player.body.velocity.x = 10; } else if (this.cursors.right.isDown) { this.player.body.velocity.x = -10; } }, render: function() { this.game.debug.text("Player: " + this.player.position, 32, 32); }};Am I doing something wrong or is this a problem in Phaser? Link to comment Share on other sites More sharing options...
Recommended Posts