Transition effects
The Master

hey y'all.

Anyone know algorithms for really cool screen transition effects?
I know the basic ones like fading to a color, or blocking the screen out. But what about those cool ones like how the screen blurs out like in those snes versions of super mario bros?

I'd like to kno cuz i'm doing some code for custom transition effects in an RPG and some algorithms for that would be very helpful.

spellcaster

Well, all transition effects are pretty similar. You have to images (i0, i1). You have transition time (t).
Now, what you want to do is to find a way that shows i0 at tcur=0 and i1 at tcur=t.

You can slide i0 in all directions out of the screen showing i1 "behind" it. You can even scroll parts i0 in different directions (one half to the left, one half to the right).

You can display lines / columns of i1 in an interval of n. Start with a large n then decrease it.

You can alpha blend the images.
You can implement a paper turn effect.

There are a lot of possibilities. Some are pretty easy to implement, some take more time.

Ariesnl

Onewing

Check out the code from Ballz, a TINS game. It had several transitions when you die/finish a level. However, most transitioned to a black screen and then out from a black screen.

spellcaster

Here's the code I use for fading effects.
Example code will follow if somebody could reply - this post is getting too long

```#ifndef CROSSFADE_HEADER

#include <allegro.h>

public:
virtual void crossfade(BITMAP* img1, BITMAP* img2, BITMAP* dst, double percent) = 0;
};

#endif
```

```#include "crossfade.h"

}
}
```

```#ifndef FADE_HEADER

#include <allegro.h>

public:
virtual void fade(BITMAP* src, BITMAP* dst, double percent) = 0;
};

#endif
```

```#include "fade.h"

}

}
```

miran

This posts does not exist. It is but a figment of your imagination.

spellcaster

Here's some example code:

example.cpp

@Miran: Thanks!

EDIT: Changed parts of the code and removed one example. The example listed will show all effects.

Paul whoknows

I tried your examples but they crashed, I am using Dev-C++ and alleg42, also it seems sprintf is no longer available.

spellcaster

Well,the crashing could be due to no images with the given name in the same directory (image1.tga, image2.tga).
Regarding sprintf: chances are that allegro no longer includes <stdio.h>. I'll add the include to the examples and I'll check if the images can be loaded.

Edit:
You can download the compiled example program and 2 example images here:

Paul whoknows

Yes that was the problem, I was using 2 pcx files, I did not see you were using .tga files!
Now it works nicely!

[EDIT]
Really nice! I am going to use the alphablending fx in my project! but I'll replace draw_trans_sprite with Fladimir's alpha blending routines.

spellcaster

Well, guess that's the problem if you simply copy'n'paste old code. I just recompiled that code with warnings enabled and almost fell out of my chair in shame.

I also realized that I can't recall all the libs and linking order to link allegro statically. Finally, it seems that this does the job:

-lalleg_s -lgdi32 -ldxguid -lole32 -ldinput -lddraw -lwinmm -ldsound

(This is the point where somebody links to the documentation showing me that this info is well documented and easily available )

Richard Phipps

Sounds like you needed something like Easy Allegro..

The Master

Those are good, but they fade from one image to another. I've got a tile based engine with sprites on top of it. What I was after was some tips on ways of postprocessing the doublebuffer, which emulates a transition effect. That is, everything gets drawn to the doublebuffer, then if the engine recieves a message to do a transition effect (from an event telling it to go to the next level or something) it will increment the effect a little.

spellcaster

Well, the double buffer is just an image.

Let's say your engine renders your start scene into buffer1. Let's also assume that your engine renders the second scene into buffer2. No, all you need to do is to pass these two buffers to the fade method. As you can see, it takes two BITMAPs and a percentage value.
This allows you to fade both static images or animated graphics fresh from your engine.

But I do hope you don't expect me to create a RPG engine just to demonstrate how you could fade two scenes by using the code above