Switch to full style
Understanding the language, error messages, etc.
Post a reply

Sprite questions

Fri Apr 11, 2014 9:59 am

Image

Is it possible to create sprites with white outlines (fig. A) or is white (0) strictly defined as transparent (fig. B)?

Re: Sprite questions

Fri Apr 11, 2014 10:34 am

the engine used to have a BLACK option idk if its still in there
but is u wanted overlapping images is to use 2(or more) images one for the black outline and one for the white fill for example (dont forget that the image data for the white is actually black)
Attachments
overlay.jpg
overlay.jpg (69.75 KiB) Viewed 7573 times

Re: Sprite questions

Fri Apr 11, 2014 1:12 pm

Adekto is right, you have to separate every color in different sprites.
You'll render the white and black part every frame (you can set the color using gb.display.setColor(BLACK) or gb.display.setColor(WHITE)), and to render gray you display black every other frame.

Re: Sprite questions

Fri Apr 11, 2014 3:16 pm

somthing like this for grey?
Code:
void setup(){
isGrey = true;
}

void loop(){
gb.display.setColor(BLACK);
// black sprite

if(isGrey) gb.display.setColor(BLACK);
isGrey = !isGrey;

// grey sprite
}

Re: Sprite questions

Fri Apr 11, 2014 3:25 pm

Code:
gb.display.setColor(BLACK); //not necessary as black is the default color
gb.display.drawBitmap(x, y, blackSprite);

if(gb.frameCount%2) //every other frame
   gb.display.drawBitmap(x, y, graySprite);

gb.display.setColor(WHITE);
gb.display.drawBitmap(x,y, whiteSprite);

Re: Sprite questions

Mon Apr 28, 2014 4:54 pm

Since many games will be using grey could we implement easy support for "colored" sprites?
Something like this:

Code:
void drawSprite(sprite, x, y) {
gb.display.setColor(BLACK); //black
gb.display.drawBitmap(x, y, sprite);

if(gb.frameCount%2) //grey - every other frame
   gb.display.drawBitmap(x, y, sprite);

gb.display.setColor(WHITE); //white
gb.display.drawBitmap(x,y, sprite);
}

drawSprite(walk1,10,10);


Edit: removed the data storing part
Last edited by phi on Mon Apr 28, 2014 9:36 pm, edited 4 times in total.

Re: Sprite questions

Mon Apr 28, 2014 8:35 pm

One bit has only 0 or 1

Re: Sprite questions

Mon Apr 28, 2014 9:28 pm

The example above was just to illustrate the storage of the pixel data using some sort of array.
I was thinking of a basic image format that supports 3 Colors (and maybe a mask layer).

Re: Sprite questions

Mon Apr 28, 2014 9:36 pm

Try: 0 = transparency, 1 = white, 2 = gray and 3 = black. This way you use the 4th value of your 2 bits array for something useful. ;)

Re: Sprite questions

Tue May 20, 2014 8:43 pm

I'll chime in

I've written an alpha-bitmap sprite routine to use with TVout on the Hackvision.

I did it exactly for the reason the OP is asking: to have opposite color edges around the sprite.

In my opinion, having 2 bits per pixel in an array is a bad idea. Instead of reading whole bytes, you'd have to parse the bitmap data bit by bit and then decide what to do with each pixel.

It would be much better to have 2 arrays. 1 for value, 1 for mask. In each sprite header would be the dimensions of the sprite AND whether it is negative or positive. Alternatively this information could be given in the sprite drawing call.

The logic would work something like this:
(v=value, m=mask)
v m result
0 0 = transparent pixel
1 0 = 50% visible (gray) pixel
1 1 = opaque pixel

The point is this: if you want a pixel to be transparent, why would you need the bit set in the bitmap data ? Therefore v:m = 1:0 can be reserved to mean gray. The graphics subsystem could alternate between an AND and OR combination of mask and bitmap on each drawing cycle. That way black pixel remains black all the time, while a gray pixel is toggled. By having 2 arrays, you can process both arrays as bytes, no need to bitshift through the whole lot.

Its not so simple but that would be the basic idea.

Also, making an edge detect routine for a sprite would be another way of implementing an inverted edge witout the need for a mask array.
Post a reply