Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Sprite collision not being detected?

Author
Message
roswell1329
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 7th Oct 2014 02:08
The sprite collision command seems to be behaving erratically for me. I have a chunk of code that has been working great to detect when the explosion sprite from an exploding bullet is colliding with an incoming missile sprite.

Then, I added one more collision detection to check and see when the bullet hits another target on screen, but this command seems to be completely ignored and I cannot explain why. Any help would be greatly appreciated! The problem command is in the moveBullets() function on line 417 (if sprite collision (bulletSprite, bogieSprite))

I am very sorry for posting my complete source code here, but I didn't know how to extract the problem command without the rest of the code as context.

Attachments

Login to view attachments
roswell1329
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 7th Oct 2014 22:56
Nevermind, gang! Turns out that the sprite number I was using was probably getting constantly recycled (although, I'm not entirely sure where). Using a sufficiently high sprite ID number fixes the problem.
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 9th Oct 2014 13:44 Edited at: 9th Oct 2014 18:25
I think the prolem might be in assigning sprite numbers.You use inc command and this could lead to numerous problems.Try Matrix1's find free sprite.It will find first free sprite and assign it to variable of your liking, you can even set a range with this command.

Noticed in your moveBogies() function you delete bogieSprite sprite if certain condition is met, but never recreate it.Once this happens boggieSprite variable is still 5, but there is no longer sprite with this number.So now pay attention to line 416 : if sprite exist(bogieSprite), obviously at some point it just skips the rest because the check says that bogieSprite does not exist.

I recommend you to write in pseudo code from time to time.I do it if i can not contain the full logic of the code in my mind.I'm sure it will pay off.Designing is also part of coding.If you do it well, you will spend less time debugging your code trying to find the false logic.

Coding is My Kung Fu!
And My Kung Fu is better than Yours!
roswell1329
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 9th Oct 2014 19:25
Thank you very much for the analysis, luskos! Yes, I am having a hard time with keeping track of my sprite numbers. And your original post actually resolved another error I was having trouble replicating. I wasn't aware of the Matrix1 plugins until you mentioned "find free sprite". I may give it a try. Do you know if he offers the same thing for AppGameKit? This is going to be my first complete game, and I wanted my next project to be porting it to AppGameKit to learn the new language a bit.

You were mostly right about the moveBogies() function. I wanted this sprite to appear at most once per level, which is why I didn't want to recreate the sprite. Simply using a sprite number I know isn't being used for anything else seems to have worked.

Thank you again very much for your help!

Login to post a reply

Server time is: 2024-11-27 05:36:34
Your offset time is: 2024-11-27 05:36:34