Is there some way of draw sprites without flickering?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
cpusam
Posts: 7
Joined: Tue Dec 06, 2022 2:57 pm

Is there some way of draw sprites without flickering?

Post by cpusam »

Hi, I like so much this forum and I have a idea:
for example: suppose that we have a C function (sorry I don't know assembly) to draw a simple point, drawPoint(x,y,color).
So, I think that draw only one point at time it not wll provocates flickering, or is this false? Draw a entire sprite can cause flicker if the sprites number increase.

If it is true, so, we call drawPoint to draw as points of a sprite and without cause flickering.

Can I anyone more experienced confirm this to me?

Thanks in advance.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Is there some way of draw sprites without flickering?

Post by rainwarrior »

The NES does things in 8x8 pixel blocks, or "tiles".

The background is made up of a grid of these. The sprites are made up of 64 of these which don't have to be placed on a grid.

If you use a single pixel as a sprite, you still have to use a whole 8x8 block.

Flickering happens when you have more than 8 sprite tiles on the same row of the screen. So you could do "drawPoint" with sprites, but after 8 points, they might start to flicker if they were on the same line, and then after 64 points you are out of sprites to use.

Otherwise if you want "drawPoint" to draw on the background, you don't have flickering, but there is another problem that the NES doesn't normally come with enough video RAM to cover the whole screen in tiles. You can put unique pixels on 1/4 of the background fairly easily, or 1/2 of the background with a little bit of trickery. Otherwise if you want to be able to draw freely on the whole screen you'll need a special cartridge with large CHR-RAM.

Answers in this recent thread may be relevant: is mario paint possible on the NES?
cpusam
Posts: 7
Joined: Tue Dec 06, 2022 2:57 pm

Re: Is there some way of draw sprites without flickering?

Post by cpusam »

rainwarrior wrote: Sun Dec 11, 2022 1:38 pm The NES does things in 8x8 pixel blocks, or "tiles".

The background is made up of a grid of these. The sprites are made up of 64 of these which don't have to be placed on a grid.

If you use a single pixel as a sprite, you still have to use a whole 8x8 block.

Flickering happens when you have more than 8 sprite tiles on the same row of the screen. So you could do "drawPoint" with sprites, but after 8 points, they might start to flicker if they were on the same line, and then after 64 points you are out of sprites to use.

Otherwise if you want "drawPoint" to draw on the background, you don't have flickering, but there is another problem that the NES doesn't normally come with enough video RAM to cover the whole screen in tiles. You can put unique pixels on 1/4 of the background fairly easily, or 1/2 of the background with a little bit of trickery. Otherwise if you want to be able to draw freely on the whole screen you'll need a special cartridge with large CHR-RAM.

Answers in this recent thread may be relevant: is mario paint possible on the NES?
Thanks man, good answer!
I will search more about it and see the link.
cpusam
Posts: 7
Joined: Tue Dec 06, 2022 2:57 pm

Re: Is there some way of draw sprites without flickering?

Post by cpusam »

rainwarrior wrote: Sun Dec 11, 2022 1:38 pm The NES does things in 8x8 pixel blocks, or "tiles".
Man, can you indicates me how to treat sprite flickering in game? Some algorithm to it?
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Is there some way of draw sprites without flickering?

Post by rainwarrior »

Sprites are just drawn in the order they're given in the sprite buffer. If there's more than 8 on a line, only the first 8 appear.

If you want to flicker to make sure all sprites get a turn, you just change the order of your sprites each frame.
cpusam
Posts: 7
Joined: Tue Dec 06, 2022 2:57 pm

Re: Is there some way of draw sprites without flickering?

Post by cpusam »

Oh, ok. I was reading here:
https://archive.nes.science/nesdev-foru ... 0591.xhtml
But, I get the idea with your help. So, thank you again. Now, I will make some experiments.
User avatar
nesrocks
Posts: 563
Joined: Thu Aug 13, 2015 4:40 pm
Location: Rio de Janeiro - Brazil
Contact:

Re: Is there some way of draw sprites without flickering?

Post by nesrocks »

Also, there's limited CPU time, so if you want to plot a whole image pixel by pixel every frame you'll probably find difficulty or an impossibility. One solution would be to lower the game's frame rate so you have more time to calculate the screen.
https://twitter.com/bitinkstudios <- Follow me on twitter! Thanks!
https://www.patreon.com/bitinkstudios <- Support me on Patreon!
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Is there some way of draw sprites without flickering?

Post by tokumaru »

DOS games in the early 80's used to have this problem. PC video cards never supported hardware sprites, so all the pixel manipulation had to be done in software, and CPUs back then were fairly slow. Drawing full frames pixel by pixel every frame was completely out of question.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Is there some way of draw sprites without flickering?

Post by Oziphantom »

CPU time is one thing, VBlank time is the massive killer. Even if you go PAL only you still only get what 1/3 of a screen worth?
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Is there some way of draw sprites without flickering?

Post by tokumaru »

Yeah, being able to access VRAM only during vblank is a huge bottleneck. You could, in theory, create a mapper with enough memory for two full screens worth of patterns accessible outside of vblank, but even then you still wouldn't be able to do much... The 2bpp pattern + 2-bit attributes pretty much prevents you from drawing things freely, and the CPU would still be too slow.
Post Reply