PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Disintegration Effect

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.

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;
Also, here's the link to the GD thread: http://www.pocketmatrix.com/forums/view ... 6&start=15

Hopefully someone finds this useful.
-John
many thansk for posting. I have downloaded & will try out. At this rate you will be in the credits for STIII
Conan wrote:
many thansk for posting. I have downloaded & will try out. At this rate you will be in the credits for STIII


:D That would be quite the honor, Conan.

A couple things that would speed it up even further would be to call the GetDisplay() and Color() functions just once and save them in local variables.

DisplayDevice *pDisplay = GetDisplay();
Pixel DissolveColor = Color(0,0,0);

Also, the definition section doesn't have to be #defines. They could be variables as well, and then different screens could disintegrate differently.

I'd love to hear of ways to speed up these code snippets I've done, if anyone has any recommendations. (Like the Collision example.)

Thanks and enjoy,
-John
Why does this dissolve have to be faster? Surely it is currently fast enough to dissolve one screen into another. What does making it faster get you?

Or are you thinking of also using it within the game, as an effect? Then I could see a benefit to making it faster.
mlepage wrote:
Why does this dissolve have to be faster? Surely it is currently fast enough to dissolve one screen into another. What does making it faster get you?

Or are you thinking of also using it within the game, as an effect? Then I could see a benefit to making it faster.

Well, first, I think every game programmer strives to make the fastest and most efficient code possible.

Secondly, yes. I was thinking along the lines of a unit being destroyed, or some hidden thing being uncovered. It's a quite versatile effect.

I've uploaded a demo to: http://www.omnytex.com/pf/fileexchange/ ... d_Fade.zip

-John
OK, game effects I can understand.

I try to get the code as fast as needed, but if it's already fast enough, I work on more features, or just clean up the code (refactor, document, etc.).
Just wondering if anyone tried the demo... Comments?

Thanks, John
Please provide a pre-built version.
sorry Presto, not yet, I downloaded the project but have not built it yet as I'm coding like mad on my game getting the bases implemented. I will try it soon. (I always download everything asap just in case it goes away)
mlepage wrote:
Please provide a pre-built version.

Sure thing. Here's the ARM .exe: http://www.pocketadventures.com/download/col_test.exe

-John
jcredk · 06 Oct 2003, 15:59 UTC — "Real" Disintegration
Hy

What I would call a "real" desintegration would be :

- keep effect working on one pixel square blocks
- Each column of pixel upper new black pixel is going "down" due to gravity.

With this you could have a nicer effect (At least I think 8O ), It could looks like in cartoons when Tom is hit by the hammer of Jerry and Tom is falling down into pieces.

But implementing this one would mean increase speed to "shift" the column of pixels (for loop with get pixel and set pixel should not be enough!). But now you have a real problem of speed improvment. :wink:

Bye

jcredk
Ok, I had to get in on this... I quickly re-did some code I had written way back... It's similar to what jcredk was saying, but only shifts an intire column instead of breaking it into blocks.

Full workspace and pre-compiled exe for ARM is here.

http://www.omnytex.com/pf/fileexchange/ ... n_melt.zip

Note: if you change the images, they need to be fullscreen (ie. 240x320).

Feel free to post any comments on my battle bot image also...