Sprite questions

Understanding the language, error messages, etc.

Sprite questions

Postby phi » 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)?
User avatar
phi
 
Posts: 50
Joined: Sun Mar 23, 2014 1:48 pm
Location: Germany

Re: Sprite questions

Postby adekto » 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 7296 times
User avatar
adekto
 
Posts: 448
Joined: Tue Feb 25, 2014 9:47 pm
Location: belgium

Re: Sprite questions

Postby rodot » 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.
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Sprite questions

Postby adekto » Fri Apr 11, 2014 3:16 pm

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

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

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

// grey sprite
}
User avatar
adekto
 
Posts: 448
Joined: Tue Feb 25, 2014 9:47 pm
Location: belgium

Re: Sprite questions

Postby rodot » Fri Apr 11, 2014 3:25 pm

Code: Select all
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);
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Sprite questions

Postby phi » 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: Select all
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.
User avatar
phi
 
Posts: 50
Joined: Sun Mar 23, 2014 1:48 pm
Location: Germany

Re: Sprite questions

Postby ripper121 » Mon Apr 28, 2014 8:35 pm

One bit has only 0 or 1
User avatar
ripper121
 
Posts: 224
Joined: Fri Apr 04, 2014 2:02 pm
Location: Germany

Re: Sprite questions

Postby phi » 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).
User avatar
phi
 
Posts: 50
Joined: Sun Mar 23, 2014 1:48 pm
Location: Germany

Re: Sprite questions

Postby Drakker » 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. ;)
User avatar
Drakker
 
Posts: 297
Joined: Sun Mar 30, 2014 2:54 am
Location: Québec, Canada

Re: Sprite questions

Postby jonnection » 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.
User avatar
jonnection
 
Posts: 317
Joined: Sun May 04, 2014 8:21 pm

Next

Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 11 guests

cron