• Content Count

  • Joined

  • Last visited

About kurhlaa

  • Rank
    Advanced Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. kurhlaa

    Strange rewriting of a variable at Tilemap.js

    Probably variables names are a little confusing. Also according to the docs getLayer() accepts: string integer Phaser.Tilemaps.DynamicTilemapLayer Phaser.Tilemaps.StaticTilemapLayer but hasTileAt() (by docs) itself takes {Phaser.Tilemaps.LayerData} as param and sends it to the getLayer(). So my first thought was that it takes LayerData to get LayerData Probably docs should be fixed and hasTileAt() (and all similar functions) accepts the same types like getLayer() mentioned before?
  2. Hello, I was looking at the source code of Tilemap.js (https://github.com/photonstorm/phaser/blob/master/src/tilemaps/Tilemap.js) and I see strange rewriting of the layer variable all the time. For example: hasTileAt: function (tileX, tileY, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return TilemapComponents.HasTileAt(tileX, tileY, layer); }, Could you tell more what is the idea to sent layer as an argument and then rewrite it with itself in the very beginning?
  3. kurhlaa

    Is RTree improving performance?

    Probably no, because World.js has: /** * The spatial index of Dynamic Bodies. * * @name Phaser.Physics.Arcade.World#tree * @type {Phaser.Structs.RTree} * @since 3.0.0 */ this.tree = new RTree(this.maxEntries); /** * The spatial index of Static Bodies. * * @name Phaser.Physics.Arcade.World#staticTree * @type {Phaser.Structs.RTree} * @since 3.0.0 */ this.staticTree = new RTree(this.maxEntries); ... ... ... this.tree.load(bodies); // on every frame .. and bodies are dynamic bodies. But it doesn't really matter - in this test I take a default Phaser and create normal bodies like in any example, and enabled RTree makes the update loop run slower. There are no separate settings for static and dynamic bodies
  4. kurhlaa

    Is RTree improving performance?

    Hello! From docs and code comments I see that Phaser uses RTree for faster calculations. It should improve the performance very much. Recommendation is to use it with <5000 bodies, and it is enabled by default. But I did a simple test - calculate how long it takes to run 1 physics step: /* * @method Phaser.Physics.Arcade.World#step */ step: function (delta) { var t0 = performance.now(); ... var t1 = performance.now(); console.log("Call took " + (t1 - t0) + " ms"); } Then I create a player and a group of 1000 bodies: function create () { var player = this.physics.add.sprite(50, 50, 'dude'); player.setVelocity(500, 0); player.setBounce(1, 0); player.setCollideWorldBounds(true); var group = this.physics.add.group({ key: 'boom', active: false, frame: [ 0, 1 ], frameQuantity: 500 }); Phaser.Actions.GridAlign(group.getChildren(), { width: 30, height: 20, cellWidth: 16, cellHeight: 16, x: 0, y: 0 }); this.physics.add.collider(player, group); } And the numbers I see most of time are ~0.8 - 1.0 ms. Then I set useTree: false and try again. The numbers are ~0.4 - 0.5 ms. That means RTree at this moment makes Phaser to run slower. I also tried to comment out recreating RTree on every frame: // this.tree.clear(); // this.tree.load(bodies); .. this makes numbers pretty close to disabled RTree. I'm not sure whether such testing is correct, but here it shows that RTree currently is not an improvement. Or there should be a special environment to make RTree useful?
  5. So easy, thanks! refresh() must be called after any modification of static group/body?
  6. Hello, I try to use GridAlign for static Arcade physics objects, but I get strange positions. Code example, which you can run at https://labs.phaser.io/edit.html?src=src\games\firstgame\part10.js: var config = { type: Phaser.AUTO, width: 800, height: 600, physics: { default: 'arcade', arcade: { gravity: { y: 200 }, debug: true } }, scene: { preload: preload, create: create, update: update } }; var player; var platforms; var cursors; var game = new Phaser.Game(config); function preload () { this.load.image('sky', 'src/games/firstgame/assets/sky.png'); this.load.image('ground', 'src/games/firstgame/assets/platform.png'); this.load.spritesheet('dude', 'src/games/firstgame/assets/dude.png', { frameWidth: 32, frameHeight: 48 }); this.load.spritesheet('diamonds', 'assets/sprites/diamonds32x24x5.png', { frameWidth: 32, frameHeight: 24 }); } function create () { // A simple background for our game this.add.image(400, 300, 'sky'); // The platforms group contains the ground and the 2 ledges we can jump on platforms = this.physics.add.staticGroup(); platforms.create(400, 568, 'ground').setScale(2).refreshBody(); platforms.create(600, 400, 'ground'); platforms.create(50, 250, 'ground'); platforms.create(750, 220, 'ground'); // The player and its settings player = this.physics.add.sprite(100, 450, 'dude'); player.setCollideWorldBounds(true); // Our player animations, turning, walking left and walking right. this.anims.create({ key: 'left', frames: this.anims.generateFrameNumbers('dude', { start: 0, end: 3 }), frameRate: 10, repeat: -1 }); this.anims.create({ key: 'turn', frames: [ { key: 'dude', frame: 4 } ], frameRate: 20 }); this.anims.create({ key: 'right', frames: this.anims.generateFrameNumbers('dude', { start: 5, end: 8 }), frameRate: 10, repeat: -1 }); // Input Events cursors = this.input.keyboard.createCursorKeys(); // Collide the player and the stars with the platforms this.physics.add.collider(player, platforms); // STATIC ALIGNED GROUP var group2 = this.physics.add.staticGroup({ key: 'diamonds', frame: [ 0, 1 ], frameQuantity: 2 }); Phaser.Actions.GridAlign(group2.getChildren(), { width: 3, height: 10, cellWidth: 32, cellHeight: 32, x: 100, y: 100 }); // DYNAMIC ALIGNED GROUP var group3 = this.physics.add.group({ key: 'diamonds', frame: [ 0, 1 ], frameQuantity: 2 }); Phaser.Actions.GridAlign(group3.getChildren(), { width: 3, height: 10, cellWidth: 32, cellHeight: 32, x: 500, y: 100 }); this.physics.add.collider(player, group2); this.physics.add.collider(player, group3); this.physics.add.collider(platforms, group3); } function update () { if (cursors.left.isDown) { player.setVelocityX(-160); player.anims.play('left', true); } else if (cursors.right.isDown) { player.setVelocityX(160); player.anims.play('right', true); } else { player.setVelocityX(0); player.anims.play('turn'); } if (cursors.up.isDown && player.body.touching.down) { player.setVelocityY(-330); } } Here strange is that all static objects (group2) position is 0x0 - you can see the debug layer in canvas top-left corner. You can also try to move a player there - images do not have collisions, but that rectangle in the corner does have. If I create the same, but dynamic group (group3) - everything is Ok. The question is should it be like that or static bodies are not being placed correctly by GridAlign ?
  7. kurhlaa

    Understanding the 'emit' functions

    Oh, not everything is being used by Phaser internally, got it, thanks! But in general, if I see object.emit('eventName' ... ) - I should search for object.on('eventName' ... ) and check the function inside, correct? Can I be sure that event's name won't be obfuscated or replaced by variable, so searching for 'eventName' will always give results if such listener exists?
  8. kurhlaa

    Understanding the 'emit' functions

    So far I understand, that it's possible to do something like that: // Setup listener a.on('overlap', func, this); // Run related function when needed a.emit('overlap', param1, param2); // Function to be executed after calling 'emit' function func(param1, param2) { // ... } is this correct? If Yes - in Phaser there must be somewhere: world.on('overlap', .... sprite.on('overlap', .... but I don't see something like that. Even if I search in Phaser for a string 'overlap' - nothing is there except emit functions
  9. Hello, I'm trying to understand how some parts of Phaser work. But I'm confused by the emit functions. For example arcade/world.js script at https://github.com/photonstorm/phaser/blob/master/src/physics/arcade/World.js contains: ... this.emit('overlap', body1.gameObject, body2.gameObject, body1, body2); ... this.emit('collide', body1.gameObject, body2.gameObject, body1, body2); ... sprite.emit('overlap', body.gameObject, tile, body, null); ... sprite.emit('collide', body.gameObject, tile, body, null); ... the same in many other places in Phaser. Please explain how to find the exact JavaScript code that is executed by these emit(). Thanks!
  10. Hi, @Martin Pabst, this was already discussed on GitHub. Fortunately it is fixed in the latest version of Tiled and we shouldn't worry
  11. Hello, It seems, that if I switch browser's tab while game is running - the world stops completely. If I start jumping, then switch tab and wait for some time, then switch back - I'm still in the air and continue to fall down. Bullets also freeze in the air. I try to add this to the create() function, but there is no effect: var game = this.sys.game; game.events.off('hidden', game.onHidden, game); game.events.off('visible', game.onVisible´╗┐, game);´╗┐ What can I do to prevent stopping of the physics loop? I could live with missing animations, sounds and things like that, but physics should continue to run and change bodies positions. What can I do?
  12. kurhlaa

    disableVisibilityChange in Phaser 3

    Hi, @samme, With the latest Phaser I get this error: Uncaught TypeError: game.off is not a function What is the actual syntax for your code?
  13. kurhlaa

    Change animation's duration or frameRate

    If Phaser 3 currently doesn't support it - it's also an acceptable answer at least I haven't found yet
  14. Hi, If I create animation this way: myanim = scene.add.sprite('myanim'); scene.anims.create({ key: 'myanim', frames: scene.anims.generateFrameNumbers('myanim', { start: 0, end: 20 }), duration: 1000, hideOnComplete: true }); .. and later I want to change it's duration or frameRate - how to do that? I try this, but no luck: myanim.anims.duration = 3000; myanim.anims.frameRate = 15; myanim.anims.currentAnim.duration = 3000; myanim.anims.currentAnim.frameRate = 15; Animation still runs with the initiall duration.
  15. Hello! I've created a tilemap layer this way: layer = map.createStaticLayer('ground', tiles, 0, 0).setDepth(1); After that added a particles emitter this way: particl = scene.add.particles('imagename').createEmitter({ lifespan: 300, alpha: { start: 1, end: 0 }, on: false }); Although the emitter is created after the layer - in the application particles are behind the layer's tiles, so partly not visible. How do I set the depth of the emitter to make it always visible? Any other way to bring it in front of the layer is also good. Thanks!