Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: trevmeister66 on April 17, 2007, 03:51:00 pm

Title: Sprite Masking
Post by: trevmeister66 on April 17, 2007, 03:51:00 pm
I was wondering if anybody could give me a crash corse on sprite masking and give some example code. This is going to be used with XLIB, so don't use any asm jargon, unless you need to ;)wink.gif.
Title: Sprite Masking
Post by: Jon on April 17, 2007, 04:36:00 pm
I can't help you as far as code goes, i don't know basic worth beans, but i can explain the general point of masking.  What it does is it plots a sprite on the screen, preserving the background.  The point of a mask is to remove the background where the sprite will be placed, but preserve it everywhere else.
Here is an example of an 8x8 sprite and its mask:

sprite:
.db %00000000
,db %00111100
.db %01000010
.db %01000010
.db %01000010
.db %01000010
.db %00111100
.db %00000000

spritemask:
.db %11111111
.db %11000011
.db %10000001
.db %10000001
.db %10000001
.db %10000001
.db %11000011
.db %11111111

So the mask is plotted using AND logic, meaning all the 0's in the mask will erase the corresponding pixels, and 1's will leave the pixels as they were before.  Then the sprite is plotted on top of that using OR logic, meaning all the 0's in the sprite will leave the previous image unchanged, and all the 1's will translate to black pixels.  If you were to just use OR logic, without masking, the background would be preserved around the sprite, but the sprite itself would look funky.
Title: Sprite Masking
Post by: trevmeister66 on April 20, 2007, 07:18:00 pm
mk, im starting to somewhat understand it. Thanks alot for ur help.
Title: Sprite Masking
Post by: Halifax on April 20, 2007, 07:50:00 pm
QuoteBegin-Jon+17 Apr, 2007, 22:36-->
QUOTE (Jon @ 17 Apr, 2007, 22:36)
I can't help you as far as code goes, i don't know basic worth beans, but i can explain the general point of masking.  What it does is it plots a sprite on the screen, preserving the background.  The point of a mask is to remove the background where the sprite will be placed, but preserve it everywhere else.
Here is an example of an 8x8 sprite and its mask:

sprite:
.db %00000000
,db %00111100
.db %01000010
.db %01000010
.db %01000010
.db %01000010
.db %00111100
.db %00000000

spritemask:
.db %11111111
.db %11000011
.db %10000001
.db %10000001
.db %10000001
.db %10000001
.db %11000011
.db %11111111

So the mask is plotted using AND logic, meaning all the 0's in the mask will erase the corresponding pixels, and 1's will leave the pixels as they were before.  Then the sprite is plotted on top of that using OR logic, meaning all the 0's in the sprite will leave the previous image unchanged, and all the 1's will translate to black pixels.  If you were to just use OR logic, without masking, the background would be preserved around the sprite, but the sprite itself would look funky.  

 You always were the master at masking(in my eyes haha). At least you taught me how too. :thumbup:google.gif
Title: Sprite Masking
Post by: Jon on April 21, 2007, 04:00:00 pm
Thx, I'll make sure to find my way back to psugen when i get more free time :)smile.gif
Title: Sprite Masking
Post by: dinhotheone on April 25, 2007, 01:09:00 pm
well i cant really give you any code but basically (assuming you have no clue what it is) you create sort of a cutout of the sprite where the body of where your sprite would be is white and the rest is black. then AND that onto the screen after the backround, this clears all the pxl's inside the body of the sprite. then just OR the actual sprite on and you are good to go.

...i CAN give you a program with basic masking and little else but i have no clue how get that to you. wait no i see it, leme get it up for you.

edit: it was in a group in my calc, sorry about being lazy (i left the other progs with it), it uses xlib, just run "sprite" (assuming you have xlib) and select the first option and your good to go. Also feel free to use anything in that package. its all pretty mundane and i'd rather it be put to use by someone than let it stew on my calc.