Hey all I have another weird bug plaguing my game. I am trying to destroy a projectile when it overlaps the enemy and then subtract 1 from the enemy’s statusbar. I have used this code countless times before, but for some reason in this game my projectile isn’t consistently being destroyed and sometimes causing 1-5 damage. 
As a sanity check, I created a test game using the same images and coding logic and of course it is working as expected:
Any ideas? Are my animations causing the issue? Duplicative ongame update blocks? I’m really not sure where to look from here - I ran the game in debug mode and saw the destroy block run and watched the projectile survive for several more overlaps before it finally vanished.
I appreciate any ideas for possible fixes.
Problem is not at projectile overlapping enemy handling code, but firing projectile.
Note that these 2 ways of firing projectile is different:
In the test field,
in the project,
The latter fires multiple projectiles because on game update runs every ‘game tick’ or something like that, while on A button press run only once when each time a button is change from release to press.
Adding a ‘add 1 score after firing projectile’ will make it clear.
I can see that A button press behaves differently in menu / in-game, my usual way would be separating the concern by state variable and function, something like:
onAButtonPressed() {
if (mode == Menu) {
doMenuSelect()
} else if (mode == InGame) {
handleFiringLogic()
}
}
1 Like
Ah - that makes sense @felixtsu and I agree with the change in logic using state variable. I’ll make the changes. Thanks!
Success! Thanks again for the help.
1 Like