WombatTurkey Posted October 2, 2015 Share Posted October 2, 2015 Not sure what is going on, but sometimes when you refresh everything is all smooth and works like butter. But then sometimes when u refresh everything is all glitchy, and laggy? It does this on the latest chrome and opera and Firefox. I've made a video to try to explain, although you cannot really tell because the screen recorder is shit and tears the screen too, but it's much noticeable on my side. And yes, it does this without recording the screen. Here is my code: var game = new Phaser.Game(1280, 720, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });function preload() { //game.load.spritesheet('GameSprite', '../img/gsprite.png'); game.load.atlasJSONHash('GameSprite', '../img/gsprite.png', 'gsprite.json'); game.load.image('background','./images/debug-grid.png'); }var Player;var tween;var button;var dashingLeft = false;function create() { game.stage.backgroundColor = '#182d3b'; game.add.tileSprite(0, 0, 1920, 1920, 'background'); game.world.setBounds(0, 0, 1920, 1920); game.physics.startSystem(Phaser.Physics.P2JS); var style = { font: "32px Arial", fill: "#ff0044"}; var PlayerPositionX = 0; var PlayerPositionY = 0; Player = game.add.sprite(game.world.centerX, game.world.centerY, 'GameSprite', 'PlayerMale'); game.physics.p2.enable(Player); /* button = game.add.button(game.world.centerX - 95, 400, 'button', actionOnClick, this, 'over', 'out', 'down'); button.onInputOver.add(over, this); button.onInputOut.add(out, this); */ cursors = game.input.keyboard.createCursorKeys(); game.camera.follow(Player, Phaser.Camera.FOLLOW_PLATFORMER); game.input.onDown.add(moveSprite, game.world); }function update(){ Player.body.setZeroVelocity(); /* if ( dashingLeft && (oldPos - Player.x < 100) ) { // 100 would be the length of your dash move Player.body.velocity.x = -500; // or something some other dashing speed } else { dashingLeft = false; } */ } function render() { game.debug.cameraInfo(game.camera, 32, 32); game.debug.spriteCoords(Player, 32, 500);}function moveSprite (pointer) { if (tween && tween.isRunning) { tween.stop(); } //sprite.rotation = game.physics.arcade.angleToPointer(sprite, pointer); // 300 = 300 pixels per second = the speed the sprite will move at, regardless of the distance it has to travel var duration = (game.physics.arcade.distanceToPointer(Player, pointer) / 200) * 1000; //Player.body.x = pointer.worldX; //Player.body.y = pointer.worldY; tween = game.add.tween(Player.body).to({ x: pointer.worldX, y: pointer.worldY }, duration, Phaser.Easing.Cubic.Out, true); }Edit: I've removed the text as well and it still does it. Edit2: Okay. I didn't add my graphics (copyright issues atm) But, in any event you can still see the lag when moving on certain refreshes, it's very noticeable. http://codepen.io/anon/pen/dYvWaL Edit: Especially the blinking is very visible on certain refreshes.. Really weird.. Link to comment Share on other sites More sharing options...
WombatTurkey Posted October 3, 2015 Author Share Posted October 3, 2015 If you're running in `Phaser.WebGL` rendered mode, you can use `game.forceSingleUpdate = true` in the update function and it currently fixes it. If anyone else was having this problem. Thanks to @photonstorm here: https://github.com/photonstorm/phaser/issues/2121#issuecomment-145231296 Mod can close if you want, seems resolved Ok so when you use forceSingleUpdate you basically eliminate the delta timer inside Phaser. This means all physics will be using an 'assumed' dt value of 60fps. If you know your game can reach 60fps under Cocoon without any troubles, then it will be fine. Also if your game doesn't really use much or any Arcade Physics, you will be fine doing this too. P2 has its own physics timer, so it won't touch that. All that is likely to happen is that on really crappy devices that can't manage 60fps then the Arcade Physics calculations will likely be wrong. But like I said above, this might not matter. Depends on the game. @rich Link to comment Share on other sites More sharing options...
Recommended Posts