I posted this under the GapiDraw forum, but since my example uses PF, I thought it would be more useful to have it posted here. I even added an extra bit of code to accellerate it. What this code does is provide a full-screen disintegration effect.
Hopefully someone finds this useful.
-John
- Code:
// DEFINITION
#define DISSOLVE_BLOCK 1 // 1, 2, 4 or 8
#define DISSOLVE_FPS 30
#define DISSOLVE_TIME 3
// INITIALIZATION
int iDissolveFrame = 0;
int iDissolveX = (240/DISSOLVE_BLOCK);
int iDissolveY = (320/DISSOLVE_BLOCK);
int iDissolveBlocks = iDissolveX * iDissolveY;
int *iDissolveArray = new int[iDissolveBlocks];
for(int i=0; i<iDissolveBlocks; i++)
iDissolveArray[i] = random_number(0, DISSOLVE_FPS * DISSOLVE_TIME - 1);
// IMPLEMENTATION
if(iDissolveFrame < DISSOLVE_FPS * DISSOLVE_TIME)
{
for(int y=0; y<iDissolveY; y++)
for(int x=0; x<iDissolveX; x++)
if(iDissolveArray[y*iDissolveX+x] == iDissolveFrame)
if(DISSOLVE_BLOCK == 1)
GetDisplay()->SetPixel(x,y,Color(0,0,0));
else
GetDisplay()->FillRect(x*DISSOLVE_BLOCK,
y*DISSOLVE_BLOCK,
(x+1)*DISSOLVE_BLOCK,
(y+1)*DISSOLVE_BLOCK,
Color(0,0,0));
iDissolveFrame++;
}
// DESTRUCTION
delete iDissolveArray;
Hopefully someone finds this useful.
-John