Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Fading into/out of black (Sprites)

Author
Message
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 2nd Jul 2010 11:48
Hi all,

I'm trying to make a Main Menu via sprites and was wondering if there is an easier method to do a fade in and out from black?

Right now I'm thinking of doing a sprite animation with an alpha channel and when the player goes from one section to another, it shows that sprite animation and plays it (the animation being that the sprite goes from clear to black and then black to clear)

What do you guys think?
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 2nd Jul 2010 12:09
Why not just set the sprite diffuse

Even if your sprite is pure white, you can fade it to jet black with just something like this:

For b=255 to 0 step -1
set sprite diffuse 1,b,b,b
sync
next b

You can actually set a sprite to any colour this way, very very handy for bitmap font systems.


Health, Ammo, and bacon and eggs!
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 2nd Jul 2010 12:36
Oh ok...

So... I should then make all my sprites black?

Like have all of them start black. Then when I want to show a particular sprite, show that sprite, hide the others and change it from black to clear using that diffuse command? And repeat it for the others?
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 2nd Jul 2010 12:41
Nah, if you make them black, you have nothing to fade to. If you made them normal coloured, or white - setting the diffuse will fade them to black. Any white pixels on your sprite will be set to the colour you set in the diffuse - so it's great for setting exact colours. But if you have a title screen, just change the diffuse from 255,255,255 down to 0,0,0 and it'll fade to black.

It's seperate from the alpha component, setting sprite alpha will fade it out to nothing. Maybe it would be an idea to have a fade function that will take a specified colour and alpha, and fade the sprite to that automatically, maybe specify a speed too. I'd do it but still at work, so no DBPro right now.


Health, Ammo, and bacon and eggs!
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 2nd Jul 2010 12:56
Yeah that would be an idea.

I'll play around with it and see if I can get a working main menu.

Now I just need to figure out the best way to do a "pointer" so players know which option they are currently on.

I'm thinking of just setting the pointer's positions on the screen and just move the pointer to the next/previous position whenever the player presses UP or DOWN.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 2nd Jul 2010 13:41 Edited at: 2nd Jul 2010 13:50
Yeah, menus can be a pain, especially when you forget an option and have to nudge everything around. I tend to use a for.next loop and compare each option with the current option, then change the diffuse colour of that sprite while drawing it, or paste another sprite on top, a glow or something like that.

I also like to draw each option in turn in a loop, because that way it's real simple to check the mouse pointer, and you would probably have the options Y coordinate anyway.

Untested, but my menus tend to go a bit like this, assuming that images 100-105 are menu options:



Tricky to know if that would all work, but the idea is that the sprite is positioned then the diffuse colour reset (so it's as it is), if the mouse is over it, then it should go pinkish, if you select the option it should be red. Hope that helps anyway.


Health, Ammo, and bacon and eggs!
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 2nd Jul 2010 14:18
Hmmm I'm slightly confused at how that works.

Need to work on that more.

I'm currently trying to make my own version and it's really hard hahaha.

Trying to make 2 functions that fades out the current sprite and fades in the next chosen sprite.
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 6th Jul 2010 14:14
Hey I was just wondering.

Right now I have a working main menu but without fade in and out. To make the fade in and out, would it work if I just had a sprite that is completely black and use that as the fades?

So like, make sure that the black sprite is at the very top, but make it see through and hidden. Then, when you go from one page to another, it shows the see through black sprite, make it slowly regain its blackness and then reverse it. And when the blackness reaches its maximum, change the main menu image.

Would that work?
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th Jul 2010 15:00
Yes that would work, and in fact I prefer to use sprite alpha levels rather than diffuse settings for this kind of thing, as it allows you to add a background of some sort without having to change too much code.

DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 6th Jul 2010 15:26 Edited at: 6th Jul 2010 15:38
Kewl, I'll try it now
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 6th Jul 2010 15:30
Why waste a sprite for the sake of tracking a variable from 0 to 255 and 255 to 0? - or however you want to represent it.

I mean your just making work for yourself - I can understand if you wanted a backdrop, maybe some 2D lighting effect (like having the menu items as neon signs, with a backdrop and sprite. But your only worried about fading to black, and sprite diffuse does that without needing anything else, no other sprites, no other handling except 1 variable to control the fade!

Did you try that first little snippet I posted, that fades a sprite to black. What more do you need? - if you post your main menu stuff, I'll add the fading for you.

SET SPRITE DIFFUSE Sprite,Red,Green,Blue

It does everything you need efficiently. I've used this technique to add drop shadows to text, it will fade to pure black with no problems.


Health, Ammo, and bacon and eggs!
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 6th Jul 2010 15:41
Yeah I tried Van B's method but found it slightly harder to do. It's just me mind you.

Anyways, I'll just try both methods. Hope I didn't offend you or anything Van B by doing trying another method. I just like to know the different options I have.
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 6th Jul 2010 17:47 Edited at: 6th Jul 2010 17:48
Hi again,

I used Van B's method and finally got it all working! Took me a while to write the fade in and fade out codes so that I didn't have to repeat it all for every single option.

All I have to do now is lock the player's controls when the menu is currently transitioning (when you try to choose an option while the menu is still fading in/out, it messes the code and it just doesn't work).

Thanks very much Van B =D
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 6th Jul 2010 18:07
Hehe, no worries, was just puzzled as to why you'd put yourself through the turmoil . Good to know you got it working.


Health, Ammo, and bacon and eggs!
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 6th Jul 2010 23:41
Quote: "Took me a while to write the fade in and fade out codes so that I didn't have to repeat it all for every single option."


Lolol all that sounds way too complicated.

Whenever I wanna fade to black I just load in a 1x1 black pixel, make a sprite use this image, size the sprite to fill the screen then alter the alpha mapping on the sprite depending on whether I need it fading in or out.

Imagine if you want to fade 100 sprites and any other 3D content to black. :S - Setting diffuse levels for that many entities would be a burden on the system. - Having 1 sprite over the top simplifies everything down to just controlling 1 sprite rather than all of them in a for-loop or something.

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th Jul 2010 23:54 Edited at: 7th Jul 2010 00:05
Quote: "Whenever I wanna fade to black I just load in a 1x1 black pixel, make a sprite use this image, size the sprite to fill the screen then alter the alpha mapping on the sprite depending on whether I need it fading in or out"

Agreed, I do the same... very easy that way!!

Maybe a snippet needs loading, let me look...

EDIT:
Here's an edited version of mine...


DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 7th Jul 2010 05:52
Well I got mine working using SET SPRITE DIFFUSE and it works fine.

I think I'll stick to this one since it's already working XD

Thanks though ^^
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 7th Jul 2010 19:03
Doing it with one big sprite is easy and effective, but say if you wanted to fade out only parts of the screen, one of the parallax layers in a shooting game for instance, it would fall down. For a full screen fade probably the best method. But for fading individual sprites alpha or diffuse are good.

http://s6.bitefight.org/c.php?uid=103081
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 7th Jul 2010 19:16
There are lots of neat little tricks you can do with sprites, just gotta get into them and figure out all that they can do - I like the way you can change the UV coordinates. When I first found out about that, I went off and made an awesome perspective correction tool for sprites - well it was awesome in it's day, before they added it to the major art packages as standard.

I never paid them any mind until quite recently, now I consider using sprites for lots - although I have been concentrating on 2D games recently.


Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2026-07-25 09:40:34
Your offset time is: 2026-07-25 09:40:34