filvoyage

Members
  • Content Count

    3
  • Joined

  • Last visited

  1. I was using Groups as the basis for my physical hierarchy. The Sprite gets added to the player Group (and thus physically parented to the player) when picked up, meaning when the player moves after that the Sprite moves with it (after adjusting the position to reflect the new parents transforms). I think you're right - the extra maths required in getting all the transforms to update coupled with the hierarchical setup is probably more trouble than its worth. I'll create something in the update that maintains the offset for all the picked up objects. Thanks for your help guys!
  2. Hey guys, I did a search of the forums as well as the Phaser/Pixi docs and came up short (let me know if it's answered anywhere else). I'm trying to create a mechanic whereby the player is able to pick up and drop sprites. I've been able to achieve pickups by using the group.add() function where the group parent is the player sprite, but when using .remove() to drop the sprite, the sprite just completely disappears. Its position, alpha, scale etc all look sensible and haven't been modified. What I have seen however is that the sprite parent name changes to being undefined, which seems unhealthy as when it spawns in the world its parent appears to be "__world". I also tried directly calling addChild() inherited from Pixi which is used in the Phaser groups, and the result was the same. It's easy to reproduce, my code is below. This is in .create() this.testGroup = game.add.group(PLAYER) this.testLight = game.add.sprite(300, 300, "buttonGradient");This is in .update() if (PLAYER_OBJECT.inputIsActive("y")) { this.testGroup.add(this.testLight); } if (PLAYER_OBJECT.inputIsActive("u")) { this.testGroup.remove(this.testLight); }Does anyone know if my setup is bad, or if there are other ways to achieve my desired effect? I had a look at the group remove example on the official examples page and the same thing happens there - I don't know if it's a bug or an intentional result of the system. Thanks in advance!
  3. (sorry moderators, another one like this has already posted before I'd finished writing!) Hi! I've just been getting into phaser over the last few days, and have come slightly unstuck attempting to make smooth player movement. For the most part phaser has the tools available in the physics system to achieve this (acceleration, drag) but I have been unable to make direction changes smooth. It works correctly if the player sprite travels just in one direction and then moves in the opposite direction, as the drag and acceleration handles the change correctly. However, if travelling diagonally (holding down W and A, applying both x and y acceleration), and then releasing one key, the change in direction happens instantly. What I'd like to achieve is some drag that happens during this change in velocity so that the player slides a little before fully changing direction. (I hope I've explained this correctly). I wanted to try achieving this by tweening the acceleration to 0 when a key is released. However, I cannot seem to be able to get the tween working correctly. I don't think I'm adding acceleration correctly to the tween manager - other tween examples I've seen have just needed to access the parameters of the sprite object, whereas this seems slightly more complex to me. TL;DR - does the below look correct? This is done in the create function //playergame.player = game.add.sprite(game.width/2, game.height/2, "player");game.player.anchor.setTo(0.5, 0.5); //player physicsgame.physics.startSystem(Phaser.Physics.ARCADE);game.physics.enable(game.player, Phaser.Physics.ARCADE);game.player.body.maxVelocity.setTo(playerMaxSpeed, playerMaxSpeed);game.player.body.drag.setTo(playerDrag, playerDrag);game.playerAccelerationTween = game.add.tween(game.player.body.acceleration); And this in the updateif (inputIsActive("W")) {game.player.body.acceleration.y = -playerAcceleration;} if (inputIsActive("S")) {game.player.body.acceleration.y = playerAcceleration;} if (inputIsActive("A")) {game.player.body.acceleration.x = -playerAcceleration;} if (inputIsActive("D")) {game.player.body.acceleration.x = playerAcceleration;} if (!inputIsActive("W") && !inputIsActive("S")) {game.playerAccelerationTween.to({y: 0}, 2000, Phaser.Easing.Linear.None);} if (!inputIsActive("A") && !inputIsActive("D")) {game.playerAccelerationTween.to({x: 0}, 2000, Phaser.Easing.Linear.None);} Apologies if this has been answered elsewhere or is easily available in the documentation, I'm quite new to coding in general and this stumped me. Thanks in advance!