Need help with sprites

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
User avatar
DevEd
Posts: 51
Joined: Thu Dec 12, 2013 4:00 pm

Need help with sprites

Post by DevEd »

So I'm working on my 3rd program, which contains (among other thing) my first attempt to make a sprite. It's basically a hexadecimal number that can be incremented or decremented by pressing Right or Left respectively. It mostly works properly, HOWEVER it doesn't show up until I press Left or Right to change the value.

Specifically, what I expect to happen is that when the screen changes to the sound test, the number shows a value of 1, and changes when you press Left or Right. But what really happens is that when the screen changes, the number does not show up until I press Left or Right.

Here is the segment of code I'm using for the sprite, for reference:

Code: Select all

	pal_spr(palData);//set palette for sprites
	sprXPosition=15;
	sprYPosition=15;
	ppu_waitnmi(); // wait 1 frame
	oam_clear(); // just in case this is why the number doesn't appear at first
	sprite=oam_spr(sprXPosition,sprYPosition,0x7C,0,sprite); // create sprite
	while(1)
	{
		controllerInput=pad_trigger(0);
		if(controllerInput&PAD_LEFT)
		{
			if(SoundNumber>0) --SoundNumber;
			oam_clear(); // clear OAM so numbers do not overlap
			sprite=oam_spr(sprXPosition,sprYPosition,0x7C+SoundNumber,0,sprite);
		}
		if(controllerInput&PAD_RIGHT) 
		{
			if (SoundNumber<11) ++SoundNumber;
			oam_clear(); // clear OAM so numbers do not overlap
			sprite=oam_spr(sprXPosition,sprYPosition,0x7C+SoundNumber,0,sprite); // redraw number to reflect current sound ID
		}
		if(controllerInput&PAD_A) sfx_play(SoundNumber,0);
		if(controllerInput&PAD_B) break;
Is there something I'm missing here? Any help would be appreciated.
You know, the DevSound guy.

There are two kinds of people in this world: those who are convinced there are two kinds of people in this world, and those who aren't. - Unknown
unregistered
Posts: 1193
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: Need help with sprites

Post by unregistered »

Wish I could help you. It's not assembly... my brain is in assembly. :( Sorry.
lidnariq
Posts: 10677
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Need help with sprites

Post by lidnariq »

In neslib, you apparently have to call ppu_waitnmi after you've called oam_spr in order to write the sprite data to the the PPU.
User avatar
DevEd
Posts: 51
Joined: Thu Dec 12, 2013 4:00 pm

Re: Need help with sprites

Post by DevEd »

I tried that, but it didn't work.
You know, the DevSound guy.

There are two kinds of people in this world: those who are convinced there are two kinds of people in this world, and those who aren't. - Unknown
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Re: Need help with sprites

Post by Shiru »

lidnariq's answer is correct. Also, generally it is a good idea to put ppu_waitnmi(); in beginning (or end) of a game cycle, to avoid the loop running many times per frame. So, if you move ppu_waitnmi(); inside the while(1), it'll work.

Code: Select all

while(1)
{
 ppu_waitnmi();
 ...
User avatar
DevEd
Posts: 51
Joined: Thu Dec 12, 2013 4:00 pm

Re: Need help with sprites

Post by DevEd »

I got it working. Turns out I was using the wrong tile. Fail. :roll:

Thanks for the help anyway.
You know, the DevSound guy.

There are two kinds of people in this world: those who are convinced there are two kinds of people in this world, and those who aren't. - Unknown
Post Reply