Stuck changing sprites while pressing B

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
lazerbeat
Posts: 64
Joined: Tue Jul 09, 2013 7:13 am

Stuck changing sprites while pressing B

Post by lazerbeat »

I have been working on a little sprite demo based on a nerdynights tutorial, just moving around 64 sprites which I am pretty happy with. I have some code to update change the sprite tiles when I press B which my demo IS doing but it is doing it way too fast. I assume every frame. The code is pretty long so I have a pastebin link

http://pastebin.com/2rJy1npK

I also included my ROM, if anyone would be kind enough to take a look at this I would really appreciate it. I have been stuck on this for several hours!

Thanks everyone,
Attachments
spritefield.nes
(48.02 KiB) Downloaded 90 times
LocalH
Posts: 180
Joined: Thu Mar 02, 2006 12:30 pm

Re: Stuck changing sprites while pressing B

Post by LocalH »

Haven't looked at the code, but most likely you're merely checking every frame to see if the button is pressed. If you're not taking into account whether you have already detected that the button has been pressed then it will activate on every frame. Many games poll the controller once per frame, and then store the result in a dedicated address in RAM. That way, the code can check to see if it has been detected without directly reading the controller port every frame and using that result. You need at least one frame of the button not being detected as pressed before you trigger whatever function you wish to trigger by pressing the button. Others here who are more experienced with actually developing on the NES will be able to help you further. My knowledge is more theoretical and conceptual because I come from the C64 in terms of my programming knowledge.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Stuck changing sprites while pressing B

Post by tokumaru »

This very recent thread probably has what you need.

Some game events occur in response to the buttons that are currently pressed, such as walking/running, but others should only occur when buttons are currently pressed but weren't last frame.

Just keep a secondary set of button states, indicating buttons that have just being pressed, as suggested in that thread, and use that for this specific decision.
lazerbeat
Posts: 64
Joined: Tue Jul 09, 2013 7:13 am

Re: Stuck changing sprites while pressing B

Post by lazerbeat »

Thanks a lot, I will update my code and repost when I hopefully get it working!
Post Reply