Omnimaga
Calculator Community => TI Calculators => General Calculator Help => Topic started by: cooliojazz on June 01, 2010, 10:38:02 pm
-
I have a quick question; how can I do sprite masking without AND logic?
-
You have two sprites to make the final image, the transparency mask and the sprite mask we'll say. The transparency mask is black where the image is solid and white where it is transparent. The sprite mask is Black where the sprite is white (counterintuitive i know, thats why i want ANDing) a,d white where it is anything else. To display, you OR the transparency mask, then XOR the sprite mask.
-
you need two copies of your sprite: a black mask and the sprite itself.
The black mask represents all areas of your sprite that you want transparent and the ones that aren't. The black areas are the ones that aren't. First, you display your mask using the OR logic (all black pixels from your sprite turns the screen pixels black, white ones won't change anything.) Then you display your mask again but using the XOR logic, which inverts the area that got turned black to white. Once done, display your regular sprite using the OR logic.
-
Wow... thats complicated, glad others know how to do it, I never would have figured that out. Thanks! I wonder if Quigibo is planning on adding AND to axe parser sometime in the future...
-
I don't think he will since it can already be done like me and BBoy posted. However, if you use masking a lot in your games, you can simply put both sprites near each others in your tile sheets and use sub-routines to prevent repetitive code
-
Mmm thats a more intuitive way DJ :) Yeah with mine, you dont actualy get to store the actual sprite anywhere :P its all just messed up masks ;D
-
Efficiency or readability... hm... You could always just make a special hex editor that supports masked sprites and gives the hex for both masks.
Also, something that wasn't mentioned: you can also use such masking to invert areas, in addition to white, black, or untouched (transparent). With what builderboy mentioned, in the second mask you put black where in the first mask you put white, and, while it cannot be done with DJ's method as-is, replacing that final OR with an XOR and using black where there was white the first mask does the trick.
-
Mhmm Builderboy method sounds more efficient indeed... would save some speed for sure when many sprites at once are shown.
-
Sorry, but could you provide example code of BuilderBoy and DJ Omnimaga description?
I am having difficulties understanding the steps and it looks interesting. :(
-
For each piece of code, the first mentioned sprite is Pic1 and the second mentioned one Pic2. The sprite location is given by X and Y
.This is Builderboy's
Pt-On(X,Y,Pic1
Pt-Change(X,Y,Pic2
.This is DJ's
Pt-On(X,Y,Pic1
Pt-Change(X,Y,Pic1
Pt-Change(X,Y,Pic2
.The last line for DJ's as given would be a Pt-On rather than a Pt-Change, but my variation works about the same and is more flexible
Note that Pt-On performs an OR, and Pt-Change performs an XOR operation.
-
Thanks, I got it. :)