Best way to make sprites flicker or flash

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
The Rook
Posts: 52
Joined: Mon Jul 13, 2015 8:04 am

Best way to make sprites flicker or flash

Post by The Rook » Mon Oct 12, 2020 6:39 pm

I'm trying to make a group of sprites (2 rows of 10 8x8 sprites) flicker or flash as a selection box to indicate that something is selected.

I've tried a couple different methods, including:

1) drawing every other sprite, every other frame
2) circling around the rectangle by drawing 1 sprite every frame (I don't like this method)
3) drawing 8 sprites per frame, picking up where I left off last frame and drawing 8 sprites, etc.

Does any one know of any other methods of making sprites flicker or flash?

Thanks.

I attached a demo ROM I wrote showing the 3 different methods I've tried so far.

Below is the logic for the 2 of the 3 methods:

Code: Select all

void draw_sprites_every_other_frame()
{
  // Draws every other sprite, every other frame.

  if (every_other_frame)
  {
    oam_spr(32,64,0x83,0);
    oam_spr(48,64,0x84,0);
    oam_spr(64,64,0x84,0);
    oam_spr(80,64,0x84,0);
    oam_spr(96,64,0x84,0);

    oam_spr(40,72,0x84,0 + V_FLIP);
    oam_spr(56,72,0x84,0 + V_FLIP);
    oam_spr(72,72,0x84,0 + V_FLIP);
    oam_spr(88,72,0x84,0 + V_FLIP);
    oam_spr(104,72,0x83,0 + HV_FLIP);
  }

  if (!every_other_frame)
  {
    oam_spr(40,64,0x84,0);
    oam_spr(56,64,0x84,0);
    oam_spr(72,64,0x84,0);
    oam_spr(88,64,0x84,0);
    oam_spr(104,64,0x83,0 + H_FLIP);

    oam_spr(32,72,0x83,0 + V_FLIP);
    oam_spr(48,72,0x84,0 + V_FLIP);
    oam_spr(64,72,0x84,0 + V_FLIP);
    oam_spr(80,72,0x84,0 + V_FLIP);
    oam_spr(96,72,0x84,0 + V_FLIP);
  }
}

void draw_sprites_eight_at_a_time()
{
  byte i = 0;

  while (i < 8)
  {
    if (j == 10)
    {
      j = 0;  // reset the sprite index
    }

    oam_spr(sprite_row1_x[j], sprite_row1_y[j], sprite_row1_tile_id[j], sprite_row1_pal_id[j]);
    oam_spr(sprite_row2_x[j], sprite_row2_y[j], sprite_row2_tile_id[j], sprite_row2_pal_id[j]);

    i++;
    j++;
  }
}
Attachments
FlickeringSpriteDemo.nes
(40.02 KiB) Downloaded 23 times

User avatar
tokumaru
Posts: 11891
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Best way to make sprites flicker or flash

Post by tokumaru » Mon Oct 12, 2020 9:48 pm

One common solution for displaying a large sprite is to break it into 4 quadrants, and flicker them diagonally (top left + bottom right, then top right + bottom left).

calima
Posts: 1209
Joined: Tue Oct 06, 2015 10:16 am

Re: Best way to make sprites flicker or flash

Post by calima » Tue Oct 13, 2020 12:46 am

Just use a slow blink for the entire rectangle. 0.5s or 1s per state.
edit: if the box is so big it'd hit sprite-per-line limits, I would make it a sparse box.

User avatar
Bregalad
Posts: 7963
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Re: Best way to make sprites flicker or flash

Post by Bregalad » Tue Oct 13, 2020 2:17 am

Among the solutions you introduced, I'd prefer the 1st one (flicker every other frame).

But I'd consider drawing the box using BG instead of sprites, so that it don't have to flicker at all - or can flicker slowly (to gather player's attention), both of those looks better than a very fast 2-frame period flicker.
Useless, lumbering half-wits don't scare us.

User avatar
The Rook
Posts: 52
Joined: Mon Jul 13, 2015 8:04 am

Re: Best way to make sprites flicker or flash

Post by The Rook » Tue Oct 13, 2020 9:19 am

tokumaru wrote:
Mon Oct 12, 2020 9:48 pm
One common solution for displaying a large sprite is to break it into 4 quadrants, and flicker them diagonally (top left + bottom right, then top right + bottom left).
I'm doing something similar with my "every other frame" method. The selection box is 2 rows of 10 sprite tiles each, so I draw every other sprite in the first row (1, 3, 5, 7, 9) and then every other sprite in the second row (2, 4, 6, 8, 10).

User avatar
The Rook
Posts: 52
Joined: Mon Jul 13, 2015 8:04 am

Re: Best way to make sprites flicker or flash

Post by The Rook » Tue Oct 13, 2020 9:20 am

calima wrote:
Tue Oct 13, 2020 12:46 am
Just use a slow blink for the entire rectangle. 0.5s or 1s per state.
edit: if the box is so big it'd hit sprite-per-line limits, I would make it a sparse box.
What do you mean when you say "sparse box"?

User avatar
The Rook
Posts: 52
Joined: Mon Jul 13, 2015 8:04 am

Re: Best way to make sprites flicker or flash

Post by The Rook » Tue Oct 13, 2020 9:21 am

Bregalad wrote:
Tue Oct 13, 2020 2:17 am
Among the solutions you introduced, I'd prefer the 1st one (flicker every other frame).

But I'd consider drawing the box using BG instead of sprites, so that it don't have to flicker at all - or can flicker slowly (to gather player's attention), both of those looks better than a very fast 2-frame period flicker.
As of right now, I also prefer the first method.

Drawing the box using background tiles is not an option. I need to use sprites is this instance.

calima
Posts: 1209
Joined: Tue Oct 06, 2015 10:16 am

Re: Best way to make sprites flicker or flash

Post by calima » Tue Oct 13, 2020 10:33 am

This is what I mean by a sparse box.
Attachments
sparse.png
sparse.png (281 Bytes) Viewed 392 times

User avatar
dougeff
Posts: 2762
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Best way to make sprites flicker or flash

Post by dougeff » Tue Oct 13, 2020 11:06 am

Have you ever heard of a "marching ants" selection box? That might work for a sparse box.

https://en.m.wikipedia.org/wiki/Marchin ... prov=sfla1
nesdoug.com -- blog/tutorial on programming for the NES

User avatar
The Rook
Posts: 52
Joined: Mon Jul 13, 2015 8:04 am

Re: Best way to make sprites flicker or flash

Post by The Rook » Tue Oct 13, 2020 1:14 pm

calima wrote:
Tue Oct 13, 2020 10:33 am
This is what I mean by a sparse box.
Yes, my original idea was to have something like what is on the left but then because that would require 10 sprites on a line, I thought something like what is on the right might work.
sparse_box.png
sparse_box.png (661 Bytes) Viewed 345 times

User avatar
The Rook
Posts: 52
Joined: Mon Jul 13, 2015 8:04 am

Re: Best way to make sprites flicker or flash

Post by The Rook » Tue Oct 13, 2020 1:15 pm

dougeff wrote:
Tue Oct 13, 2020 11:06 am
Have you ever heard of a "marching ants" selection box? That might work for a sparse box.

https://en.m.wikipedia.org/wiki/Marchin ... prov=sfla1
Yes, that is a good idea also, but I still run into issues with having 10 sprites on a line because of the size of my selection box.

Post Reply