• Content Count

  • Joined

  • Last visited

1 Follower

About Stathis

  • Rank

Recent Profile Visitors

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

  1. Thanks a lot for looking at this guys! @PixelPicoSean that did seem like bug to me as well, but the souce code made me think it could be like that by design. And if so, it probably would be nice to have a post-creation hook added to the lifecycle of a scene, for cases like mine. As it is a one time thing, that gets triggered after a scene is created. And I assume it might be quite common, as people create boot scenes that do nothing but loading assets. But in its absence, I agree, update is fine. I guess I will raise an issue at the phaser repo then, and see what happens.
  2. Ok, I digged around in the source code and I think I found what the "issue" is. Data are passed to scenes, only if the scene you are switching from is not running. I assume this is by design. Maybe that's what you meant @PixelPicoSean but I did not get it. Many of the examples I've seen, as well as the code I posted above, start a new scene from the create function. And that works fine when you have no data to pass. At that point, the currently runnig scene (eg BootScene) has not yet been fully initialised and is not considered as runnning. I was looking for another hook to put my scene switch, but I could not see anything in the code, like created, or loaded, that is triggered after create has actually finished. So, for now, I put it in update, which is not great. The first time BootScene hits update, it will switch to the new scene with data passed to it. Edit: Sorry, I might have "hijacked" () this post @pixelhijack, I realised I am talking about a different issue than yours, as you are not switching from a scene to another.
  3. I am facing the same issue. I cannot make data get passed onto a scene... My use case is: Start LevelScene Stop LevelScene (I print isActive() here, it's false) Start LevelScene again with data Data never come up on LevelScene's create In my case, I am trying to make a game with a level stucture similar to Angry Birds. Each level is mostly a different configuration of the same template. I obviously don't want to create 100 different level scenes. Can you suggest a reccomended way of dynamically passing config to a scene? @samme, in your comment, I think you made a typo, what is the sequence you reccomended? Just scene.add and then scene.start?
  4. I had the same question recently... I guess it very much depends on how you have setup your game. In my case, my intro cutscene uses a lot of the assets and setup of the game state. For that reason, I created some chained tweens on the create of the main game state. The issue with that is that the game loop (update) starts before the intro cutscene has finished. I have a global canUpdate flag that is set to `true` when the cutscene has finished, and only then the relevant sprites/entities can be updates. Something like this (simplified version) : export default class extends Phaser.State { preload() { = false; } create() { // Several setup stuff here // Intro cutscene const shipArrives = .to({ y: 0 }, 2000, Phaser.Easing.Cubic.Out, true); shipArrives.onComplete.addOnce(() => { this.player.visible = true; }); const shipMoves = .to({ x: 32 }, 800, Phaser.Easing.Exponential.Out, false); shipArrives.chain(shipMoves); shipMoves.onComplete.addOnce(() => { // Game can now start normally = true; }, this); } update() { if ( { this.controller.update(); this.lives.setText(`lives: ${this.player.lives}`); } } } ... // It could be that some sprite needs to wait for canUpdate export default class extends Phaser.State { constructor(game, x, y, asset) { super(game, x, y, asset); } update() { if ( { // Do stuff } } } This is how I've done it, I just came up with it. I am not sure if there is a more elegant way, I am also interested in this. Sorry, I don't know what's the best approach storing/fetching the text, a file sounds fine to me though.
  5. @frokenstein I had the same exact issue, that I have mentioned here. At first I went for the above solution (thanks @valueerror), but then I realised I can do something like this: sprite.body.velocity.setMagnitude(Math.min(MAX_SPEED, sprite.body.velocity.getMagnitude())); and I think it works fine for me .
  6. Update: I think for the max velocity issue, it's much easier if I just do: ship.body.velocity.setMagnitude(Math.min(MAX_SPEED, ship.velocity.getMagnitude())); as this seems to take into account the angle. The source code actually first normalises the velocity vector and then multiplies.
  7. Ok, I have found what the problem is ! There are actually two issues. One is the drag, that is mentioned above. This affects small velocities. The other one, affects max velocities. When the ship reaches max velocity, the velocity vector is calculated wrong in Phaser. Or maybe not necessarily wrong, but different to what my expectation was. Without looking at Phaser's code, I assume it does not take into account the angle of the sprite; maybe it just checks each axis separately, and not the combined velocity vector they compose. The solution written here works perfectly for me. This also means that now my ship has steady actual max velocity, and does not run faster/slower in certain angles.
  8. Ok, I believe I have found an approach to this. I think what I need is apply sideways friction when thrust is pressed. I've found this solution, adapted it to my code, and I am not sure how it does what id does , but seems to work for me! (I will probably also disable drag, as discussed above). My ship still appears to be "slipping" a bit, on narrow angles, as described in my first post. I think this has to do with a separate issue; I will need to investigate a bit more.
  9. @sammethanks for the reply. But doesn't this have exactly the same problem? If I understand this correctly, body.velocity is a vector of the direction and magnitude of ship's velocity. Decreasing this on both axes, is not going to decrease the momentum (on the ship's relative x axis), it is just going to decrease the ship's current velocity. Sorry, I am not making myself very clear. I just created this image, to try to explain better: Imagine that this depicts the ship in different phases in time. And the arrow shows when the key is pressed. Let's say that when it starts, on the left, it has already some momentum (drag), that makes it move to the right, with no key pressed. Then up is pressed. The effect I am going for, is gradually remove the previous momentum on the x axis, and only move upwards. I think that if I do what you said, and after actually testing it, the ship will do this: And it will keep going sideways, as I keep thrust pressed. (accelerationFromRotation has exactly the same effect as my acceleration calculations above)
  10. @samme thanks, this does remove the effect I mentioned! Although I liked the drag feature... Any idea why it does that? The actual kind of movement I am going for, is the following. When the ship thrusts with an angle, the ship starts moving towards that direction. If you tilt the direction a bit (but always keep pressing thrust), the ship should keep the momentum it had for a bit, but gradually keep moving exclusively to the new direction. I know that when thrust button is not pressed, I can keep multiplying the velocity with a constant, eg 0.9, but that will only work for that case, when thrust is not pressed. Any ideas on how to do this? Do I somehow need to maintain two vectors, one for the direction, and one for the momentum, and somehow keep decreasing the momentum one? I hope all that made sense.
  11. Hi all. I am trying to make a simple top-down, asteroids-like game, where movement is done through Phaser's arcade physics system. I find quite puzzling how angular movement works for it. I've followed a few tutorials, where I find the same issue. What is happening is, when my ship has an angle, thrusting or reversing is quite inconsistent. The ship appears to be "slipping" a bit in random directions, and does not always follow exactly the direction it's facing. The relevant create code is: player.body.maxVelocity.setTo(MAX_SPEED, MAX_SPEED); player.body.drag.setTo(DRAG, DRAG); whereas the relevant update code is: if (cursors.left.isDown) { player.body.angularVelocity = -ROTATION_SPEED; } else if (cursors.right.isDown) { player.body.angularVelocity = ROTATION_SPEED; } else { player.body.angularVelocity = 0; } if (cursors.up.isDown) { player.body.acceleration.x = Math.cos(player.rotation) * ACCELERATION; player.body.acceleration.y = Math.sin(player.rotation) * ACCELERATION; } else if (cursors.down.isDown) { player.body.acceleration.x = -Math.cos(player.rotation) * ACCELERATION; player.body.acceleration.y = -Math.sin(player.rotation) * ACCELERATION; } else { player.body.acceleration.setTo(0, 0); } I don't understand what could be causing this. Is the code just wrong (although I've seen this happening in all the tutorials)? Is it some rounding error? Am I just being crazy seeing this as wrong behavior? Is there any way to achieve the effect I am looking for (moving diagonally back and forth, on a straight line)? You can play around with this here as well.