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,
Stuck changing sprites while pressing B
Moderator: Moderators
Stuck changing sprites while pressing B
- Attachments
-
- spritefield.nes
- (48.02 KiB) Downloaded 90 times
Re: Stuck changing sprites while pressing B
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.
Re: Stuck changing sprites while pressing B
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.
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.
Re: Stuck changing sprites while pressing B
Thanks a lot, I will update my code and repost when I hopefully get it working!