Jump to content

kurhlaa

Members
  • Posts

    157
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by kurhlaa

  1. @b10b, what do you mean by "Then have each client be deterministic (bullets need only exist here)" ?
  2. @b10b, at the moment I already send a weapon's "fire" event itself, not the position of every single bullet at every frame. I also wish to avoid sending identical "fire" websocket messages tens of times per second from every player. So I'm interested to know how other projects deal with syncing every bullet. About feeling that it's "good" - agree.
  3. Hi, I have a strategical question. Imagine a standard multiplayer shooter. What are the ways to broadcast and sync the shooting events? I ask because I'm confused by the weapons like automatic rifles - they shoot many times per second, or can fire just 1 bullet, it depends on how long you press the mouse button down. If in a match there are 20 players, all of them have rifles and shoot constantly - does this mean, that each player sends tens of websocket messages every second, which means the server side broadcasts hundreds of them every second? And if there are hundreds of parallel matches - that feels like a huge network traffic generation. Are there smarter ways to sync shooting?
  4. Update: if I play a test long audio in a background - freezes disappear. Could it be that sound manager initializes something all the time, what can/should be done only once?
  5. Hello, I try to play multiple short sound files. The problem is that it looks like sound files are not being played from cache - when I replay the sound which wasn't played for some seconds I see a noticeable screen freezing, like lag. It feels like JavaScript removes it from cache after 1-2 seconds and then reads/loads the file again on replay. I tried to play sounds with 2 methods: 1. directly: this.sound.play("soundname"); 2. from the instance: var music = this.sound.add('soundname'); ... // After some delay during the game music.play(); but result is the same - freezing is very noticeable on almost all replays. Maybe it's not a cache problem, it just feels like that. What can I do to prevent freezing (or to stay sounds in memory)?
  6. What do I do if I have multiple players, they all can move and collide - but shouldn't be able to push each other? I can't set immovable for everybody, because then collisions do not work. I wish there is a physics switch in Phaser to disable energy exchanging, so when 2 objects collide - the second one doesn't feel that
  7. Can you please check this new example? I'm still doing something wrong, the wall is still moving. I see that during the collision touching.* is sometimes false. I've added collider instead of calling collide() manually and added checking for touch.left & touch.right .. var config = { type: Phaser.AUTO, parent: 'phaser-example', backgroundColor: '#0072bc', physics: { default: 'arcade', arcade: { debug: true } }, scene: { preload: preload, create: create, update: update } }; var cursors; var player; var game = new Phaser.Game(config); function preload () { this.load.image('block', 'assets/sprites/block.png'); this.load.image('flectrum', 'assets/sprites/flectrum.png'); } function create () { cursors = this.input.keyboard.createCursorKeys(); wall = this.physics.add.image(200, 300, 'flectrum'); player = this.physics.add.image(400, 300, 'block'); player.setCollideWorldBounds(true); this.physics.add.collider(wall, player, collideObjects, null, this); } function collideObjects() { wall.setVelocityX(0); player.setVelocityX(0); console.log('hit'); } function update () { player.setVelocity(0); if (cursors.left.isDown && !player.body.touching.left) { console.log(1, wall.body.touching); console.log(2, player.body.touching); player.setVelocityX(-300); } else if (cursors.right.isDown && !player.body.touching.right) { console.log(3, wall.body.touching); console.log(4, player.body.touching); player.setVelocityX(300); } if (cursors.up.isDown) player.setVelocityY(-300); else if (cursors.down.isDown) player.setVelocityY(300); }
  8. Hello, If I add lights to the scene with something like: this.lights.enable().setAmbientColor(0x555555); .. then enable lighting the needed objects with: object.setPipeline('Light2D'); Then later I wish to disable all scene lights (with being able to enable later again). I try with: this.lights.disable(); But this makes all light enabled objects invisible. Probably this is because pipeline is set to every object. The question of course is - how to just turn off lights globally, like in real world, so all images stay visible (just with default normal colors)?
  9. Simple modified version of labs example: var config = { type: Phaser.AUTO, parent: 'phaser-example', backgroundColor: '#0072bc', physics: { default: 'arcade', arcade: { debug: true } }, scene: { preload: preload, create: create, update: update } }; var cursors; var player; var game = new Phaser.Game(config); function preload () { this.load.image('block', 'assets/sprites/block.png'); this.load.image('flectrum', 'assets/sprites/flectrum.png'); } function create () { cursors = this.input.keyboard.createCursorKeys(); wall = this.physics.add.image(200, 300, 'flectrum'); player = this.physics.add.image(400, 300, 'block'); player.setCollideWorldBounds(true); } function update () { player.setVelocity(0); if (cursors.left.isDown) player.setVelocityX(-300); else if (cursors.right.isDown) player.setVelocityX(300); if (cursors.up.isDown) player.setVelocityY(-300); else if (cursors.down.isDown) player.setVelocityY(300); this.physics.world.collide(wall, player, function () { wall.setVelocityX(0); player.setVelocityX(0); console.log('hit?'); }); } if you try to move the box to the wall - box will "push" the wall left-right and so it will move too. How to prevent this?
  10. In my case both objects are able to move in general, not immovable. They can move, they can stop. I wish to disable "pushing". So both objects can move, collide, but can't push/affect each other
  11. Hello, In Arcade physics, if you move towards the other object - after the collision this object moves, so it's like you are pushing it. How to prevent pushing completely? I wish player stops after the collision completely (in collision direction only, X axis for example) and the other object does not move at all. (Player should be able to move in other directions of course). I've tried to manipulate "moves", "immovable", "isMoving", "blocked", "touching" params of both bodies, but no luck. Probably there is a special magic combination of them or other setting I haven't noticed.
  12. 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); } }
  13. 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
  14. @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.
  15. @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
  16. @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?
  17. 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?
  18. 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".
  19. 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
  20. 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
  21. 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
  22. 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?
  23. 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?
  24. 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
  25. 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?
×
×
  • Create New...