MarrMooMoo Posted September 20, 2017 Share Posted September 20, 2017 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! Link to comment Share on other sites More sharing options...
MarrMooMoo Posted September 20, 2017 Author Share Posted September 20, 2017 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! Link to comment Share on other sites More sharing options...
samme Posted September 20, 2017 Share Posted September 20, 2017 Here is one way. I have "good" and "bad" zones but the concept is the same. Link to comment Share on other sites More sharing options...
Recommended Posts