Welcome! Log In Create A New Profile

Posted by diego_pmc
 diego_pmc Fade-to-black transitions May 15, 2010 08:59PM Registered: 14 years agoPosts: 34
Could someone help me out with this, please? I need to create some fade-to-black and fade-from-black transitions for images I display at the beginning of the game with logos and such. As an example, look at the beginning of TetWiis. I'm using GRRLIB.
 Crayon Re: Fade-to-black transitions May 16, 2010 12:23AM Registered: 15 years agoPosts: 175
Try those functions:
```/**
* @param tex    Texture.
* @param scaleX Texture X scale.
* @param scaleY Texture Y scale.
* @param speed  Fade speed (1 is the normal speed, 2 is two time the normal speed, etc).
*/
void GRRLIB_DrawImg_FadeInOut(struct GRRLIB_texImg *tex, float scaleX, f32 scaleY, u16 speed)
{
GRRLIB_DrawImg_FadeIn(tex, scaleX, scaleY, speed);
GRRLIB_DrawImg_FadeOut(tex, scaleX, scaleY, speed);
}

/**
* @param tex    Texture.
* @param scaleX Texture X scale.
* @param scaleY Texture Y scale.
* @param speed  Fade speed (1 is the normal speed, 2 is two time the normal speed, etc).
*/
void GRRLIB_DrawImg_FadeIn(struct GRRLIB_texImg *tex, float scaleX, f32 scaleY, u16 speed)
{
s16 alpha;
f32 xpos = (rmode->fbWidth - tex->w) / 2;
f32 ypos = (rmode->efbHeight - tex->h) / 2;

for(alpha = 0; alpha < 255; alpha += speed) {
if(alpha > 255) alpha = 255;
GRRLIB_DrawImg(xpos, ypos, tex, 0, scaleX, scaleY, 0xFFFFFF00 | alpha);
GRRLIB_Render();
}
}

/**
* @param tex    Texture.
* @param scaleX Texture X scale.
* @param scaleY Texture Y scale.
* @param speed  Fade speed (1 is the normal speed, 2 is two time the normal speed, etc).
*/
void GRRLIB_DrawImg_FadeOut(struct GRRLIB_texImg *tex, float scaleX, f32 scaleY, u16 speed)
{
s16 alpha;
f32 xpos = (rmode->fbWidth - tex->w) / 2;
f32 ypos = (rmode->efbHeight - tex->h) / 2;

for(alpha = 255; alpha > 0; alpha -= speed) {
if(alpha < 0) alpha = 0;
GRRLIB_DrawImg(xpos, ypos, tex, 0, scaleX, scaleY, 0xFFFFFF00 | alpha);
GRRLIB_Render();
}
}
```
 LordAshes Re: Fade-to-black transitions May 16, 2010 03:17PM Registered: 14 years agoPosts: 121
Basically what the above code (provided by Crayon) does is change the Alpha Transparency of the object(s). When the Alpha Transparency is 255 the object is fully visible. As the Alpha Transparency is lowered the object becomes less visible as it is blended with the background. I am not sure if this is exactly what you wanted since it means that if the background is not black then you will be fading the objects to the background color and not black.

If you specifically want the fade to black then I suggest applying a percentage to each of the color components instead of the Alpha Component. For example, you would start with Fade = 100 and draw the initial objects such that:

Then as you decrease Fade the respective color components will be scaled down (to a fraction of the original) and thus the image will become darker and darker until the screen is completely black (i.e. when Fade=0).

Doing it this way will mean that the objects always fade to black regardless of the background color. However, it does mean that you should do the same for your background color and/or background image otherwise the objects will fade to black but your background will not (thus leaving black shadows of the faded objects on the non-black background).
 diego_pmc Re: Fade-to-black transitions May 16, 2010 07:05PM Registered: 14 years agoPosts: 34
Thank you very much for all the help!
 LordAshes Re: Fade-to-black transitions May 18, 2010 05:44PM Registered: 14 years agoPosts: 121
If the information has helped you solve your problem, as a courtesy, you should edit the original post (i.e. the first post in this thread) and change the subject like to include something like *SOLVED*. This not only indicated to others that they do not need to reply but it also allows other, with the same problem, to see that a working solution has been posted.
 Ksmiler Re: Fade-to-black transitions May 19, 2010 02:31AM Registered: 15 years agoPosts: 30
Quote
LordAshes
If the information has helped you solve your problem, as a courtesy, you should edit the original post (i.e. the first post in this thread) and change the subject like to include something like *SOLVED*. This not only indicated to others that they do not need to reply but it also allows other, with the same problem, to see that a working solution has been posted.

Wouldn't this hinder further discussions on the topic / stifle discussions?
For example if someone wanted to talk about the code, as it is not working for them, the *SOLVED* part of the forum title may stop them from posting... It's a forum so I would have thought that forums encourage discussions instead of finding an end to it.

(This is just a general question on this forum as I am noticing some topics saying *SOLVED*. Some forums don't like this and have it has a rule not to add them to titles so was checking for a general stance on this one.)
 LordAshes Re: Fade-to-black transitions May 19, 2010 06:15PM Registered: 14 years agoPosts: 121
Could be. Generally I set my posts to *SOLVED* when my issue has been solved AND I have had time to test it.

This way others that have the same problem can immediately see that a solution that works (at least works for someone) has been posted.

Technically changing the title to include SOLVED does not actually prevent anyone from posting more posts to the thread (so they can still, for example, indicated that the code does not work for them).

This also helps knowlegable members who often come to help users with all sorts of problems...they can easily see which posts have not been resolved and put in a solution as opposed to having to check each post to see if a solution has been posted.

This, of course, is only my 2 cents and everyone is entitled to their own opinion :-)

Quote
ksmiller
(This is just a general question on this forum as I am noticing some topics saying *SOLVED*. Some forums don't like this and have it has a rule not to add them to titles so was checking for a general stance on this one.)

They are probably my own posts that some kind hearted soul has helped me solve. I started using this convention on this forum to let others know which on my posts were already resolved.

Edited 1 time(s). Last edit at 05/19/2010 06:18PM by LordAshes.
Sorry, only registered users may post in this forum.