kurhlaa

Members
  • Content Count

    146
  • 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. Hello, I've modified a little one labs example (first game). I have 1 ground platform and all stars falling on it, and a player. Plus collisions between everything, even between stars themselves. Player initially is in the middle of the screen and stars. If I move to the right - stars are moving, hitting each one and all joining the line; so you hit 1 and move it, then 2'nd star joins, then 3'rd, 4'th and so on. That's correct, you get all stars in a line next to each other. The issue appears when you move to the left - I'm able to join only 2 stars - all other acts like physicsless and player/stars just go through them. So you get max 2 stars in a row. Is this an arcade/collisions bug? What can I do to make collisions always be the same and objects do not go through each other? If I comment out the internals of my function collideElem - results for different directions are still different. I use it for stopping the star after a collision. Here is my testing code which is runnable at labs.phaser.io: var config = { type: Phaser.AUTO, width: 800, height: 600, physics: { default: 'arcade', arcade: { gravity: { y: 300 }, debug: false } }, scene: { preload: preload, create: create, update: update } }; var player; var stars; 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.image('star', 'src/games/firstgame/assets/star.png'); this.load.spritesheet('dude', 'src/games/firstgame/assets/dude.png', { frameWidth: 32, frameHeight: 48 }); } function create () { this.add.image(400, 300, 'sky'); platforms = this.physics.add.staticGroup(); platforms.create(400, 568, 'ground').setScale(2).refreshBody(); player = this.physics.add.sprite(300, 450, 'dude'); player.setCollideWorldBounds(true); 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 }); cursors = this.input.keyboard.createCursorKeys(); stars = this.physics.add.group({ key: 'star', repeat: 11, setXY: { x: 12, y: 0, stepX: 70 } }); this.physics.add.collider(player, platforms); this.physics.add.collider(stars, platforms); this.physics.add.collider(player, stars, collideElem, null, this); this.physics.add.collider(stars, stars, collideElem, null, this); } function collideElem(obj1, obj2) { obj2.body.setVelocityX(0); obj2.body.setVelocityX(0); } 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); } }
  2. kurhlaa

    Nested Group Error

    According to the source code - function group.add() expects GameObject as param only, not groups or anything else. child.on tries to add an event listener for the GameObject, and probably there is no such functionality for the groups
  3. kurhlaa

    Update tween END value

    @blackhawx, the question is not about a delay my timeout is just to simulate an action which happens later. How will you set a "delay" if you don't know when user will press the button? Why 1000 and not 13729 ? And I need exactly this - move an object when a needed event happens, immediately. There shouldn't be a delay inside a tween itself. The question is how to move an object to the needed position.
  4. kurhlaa

    Update tween END value

    @blackhawx, thanks for links, I've tried searching and tween.updateTo should do what I need. But why this code sample doesn't work? var config = { type: Phaser.WEBGL, width: 800, height: 600, backgroundColor: '#2d2d2d', parent: 'phaser-example', scene: { preload: preload, create: create, update: update } }; var tween; var game = new Phaser.Game(config); function preload () { this.load.image('block', 'assets/sprites/block.png'); } function create () { var image = this.add.image(100, 300, 'block'); tween = this.tweens.add({ targets: image, //x: 100, duration: 1000, paused: true, }); setTimeout(function() { tween.updateTo('x', 500, true); tween.play(); }, 1000); } function update() {} .. I create a paused tween, because there is no need to run it in the beginning. Then after some time I update an 'x' value, call tween.play() and expect the box to move to the new location (x = 500). But the box is not moving. What am I missing? You can copy this code to the labs.phaser.io to play
  5. kurhlaa

    Update tween END value

    @prob, can you show an example with updateTo ? Given lab's sample has calculation functions inside tween definition. In my case I do not have anything to calculate. During the game I just get a number and need to move there an object, for example in 100ms, or 10px per frame. In my code example I use setTimeout to simulate an action which happens later. Maybe you know how to achieve a movement to the location in other way?
  6. kurhlaa

    Update tween END value

    Hello! I try to use a tween and I need to set it's end value dynamically, and new value can't be precalculated - it is just a new integer. I try this code in labs.phaser.io: var config = { type: Phaser.WEBGL, width: 800, height: 600, backgroundColor: '#2d2d2d', parent: 'phaser-example', scene: { preload: preload, create: create, update: update } }; var tween; var game = new Phaser.Game(config); function preload () { this.load.image('block', 'assets/sprites/block.png'); } function create () { var image = this.add.image(100, 300, 'block'); tween = this.tweens.add({ targets: image, duration: 100, paused: true }); setTimeout(function() { // NewX can't bet precalculated var NewX = 500; tween.updateTo('x', NewX, true); tween.play(); }, 1000); } function update() {} .. but nothing happens, box is not moving after 1s. How do I make it to move to the NewX position?
  7. Server-side physics calculations are necessary for multiplayer games to prevent cheating. Network lag - yes, but that's on a different layer than physics calculations; partly solvable with methods like prediction and correcting of wrong predictions. But that doesn't depend on the framework's language, you can implement server-side in Javascript or even Assembler and still have issues with the network lag that's just another task. I'm not very experienced in game frameworks, but most tutorials I see talk about taking a javascript engine, add node.js plus some magic and run in on a server-side, but I still believe javascript is not for the server-side for fast performance games like FPS. So somewhen you could say "hey, I have a C++ project which allows you to run thousands of simultaneous games on a single server".
  8. Big job done! How long it took to port from day 0? Github repo is ~2 years old. Also potentially it will be great if you let developers easily to have server-side without node.js completely, so for the multiplayer games they can use BJS on a client-side and a compilable version on the server-side (physics only). I mean for performance of course. From the comments above I see it's already possible somehow, but that could be a vector to concentrate on to improve server-side performance significantly
  9. kurhlaa

    How to create ladders (with Matter)?

    Unfortunately I use Arcade only. From examples I see now Matter is a way different from Arcade, we should wait for people with more experience/knowledge
  10. kurhlaa

    How to create ladders (with Matter)?

    Is there a gravity setting in a Matter? Try to disable it for a player when it is on a ladder. Then it shouldn't slowly move down. Also you don't need sensors, since you can detect overlaps with needed tiles directly
  11. 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?
  12. 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?
  13. 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
  14. 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?
  15. So easy, thanks! refresh() must be called after any modification of static group/body?