• Content Count

  • Joined

  • Last visited

  1. Ok so I was able to accomplish what I wanted just by doing this: function laneCScoreModifier (player, lane) { if (player.key == 'heroc') { score++; } else { score--; } } I'm still open to hearing better suggestions or other methods if anyone has any!
  2. I'm currently making my first ever game and am fairly new to coding so I apologize if this code doesn't make much sense. In my game the player sprite changes with the collection of various items. When a certain item is collected I want it so that the score increases when the player is in a certain zone and decreases when the player is out of that zone all while the player sprite is that specific model, and then I want the score to decrease if the player is in that zone while the sprite model isn't correct. (Sorry if that doesn't make sense!) Here is what I have so far: //in the update function: game.physics.arcade.overlap(player, laneC, laneCScoreModifier, null, this); //outside update function: function laneCScoreModifier (player, lane) { if (player.key == 'heroc') { timer = setInterval(plusScore, 1000); if (! game.physics.arcade.overlap(player, laneC)){ clearInterval(timer); } } else { timer = setInterval(minusScore, 1000); if (player.key == 'heroc') { clearInterval(timer); timer = setInterval(plusScore, 1000); if (!game.physics.arcade.overlap(player, laneC)){ clearInterval(timer); } } } } function plusScore(){ score++; } function minusScore(){ score--; } So my first guess is the '!' modifier isn't doing anything there. When I run the game once the player enters the zone while not having the correct sprite the timer never stops, even if they leave. Anyone have any idea how I should approach this? Any help will be greatly appreciated!
  3. In my game I want my character to instantly move to predetermined points at the press of the left and right arrow keys. The player starts at x coordinate of 0. Here is my current code: var n = 0; cursors = game.input.keyboard.createCursorKeys(); var coordinates = [{x: 0}, {x: 100}, {x: 200}, {x: 300}, {x: 400}]; if (cursors.left.isDown && player.position.x != 0) { n -= 1; player.position.x = coordinates[n].x; } if (cursors.right.isDown && player.position.x != 400) { n += 1; player.position.x = coordinates[n].x; } So this basically works, but the problem is it runs it for however long I have the key pushed down, and I want it to only run once per key stroke. I read that onDown is what I'm looking for, but I'm not sure how to use that. Can someone help me out or suggest a better way?
  4. I think I might've found my solution with moveToXY, but if anyone has better suggestions for what I'm describing please tell me!
  5. I'm still new to Phaser and coding in general so I apologize if this doesn't make sense. I have player gravity and bounce set to 0 and movement velocity cranked up so movement seems instant. I'm looking to make it so that once the player hits a certain point on the x axis it stops, then the movement key must be pressed again to continue in either direction until it hits another one of those points, and so on. One idea I had was to populate the screen with vertical immovable bars with collision spread out evenly, but I don't know how to make it so that once the player hits them and stops their momentum they can then proceed through them at the press of the movement key (or if thats even possible). I feel like its more likely that I'd be able to set a coordinate for movement to stop, but again I don't know if thats possible either. Any help would be appreciated!