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.

Newcomers DBPro Corner / Fade object

Author
Message
BowserYo
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location:
Posted: 4th Sep 2009 21:22
I am attempting to fade an objects opacity (slowly disappear) once an event comes to pass. This is my code for fading:



But I'm having some trouble, it doesn't seem to have an effect when I do 100 to 0, but if I do 0 to 200 it makes it really bright, also it doesn't seem to be smooth but it just snaps to 200.

Any idea's?? Thanks!

ßõw§€r¥¤
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 4th Sep 2009 22:04 Edited at: 4th Sep 2009 22:06
this should help:



lil marioman
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: Canada
Posted: 4th Sep 2009 22:10 Edited at: 4th Sep 2009 22:14
Let's deconstruct your code for a minute.

"If alive=0" - I'll assume this means that if the enemy is not alive. Moving on.

"For i = 100 to 0" This starts the For - Next loop, at 100, and wants it to go down to 0. I've tested it, and I'm pretty sure you can only go up (for i = 0 to 100)

"Fade Object Enemy,i" This tells the system to fade the object to the ambient light level of the engine. This may not be what you want, first of all.

I recommend the "Set Alpha Mapping On" command, as this actually fades it to become invisible. You also need to add a Sync command in the loop to update the screen while it's fading.

To do the 'for i = 100 to 0', you have to use a handy command called 'abs(value)'. It returns the positive form of a negative integer. Use this to 'count down'.

Better yet, compile and run the below program.
It should show you an example of fading.
Press the spacekey to fade.
Have fun!



EDIT: Wow, all that time I spent making that code and Virtual Nomad beat me to it

And if you want a small delay, use Virtual Nomad's code. Or just stuff in a small wait (like 50 or so) in my loop.

Programming? Not my Forte. But THAT is!
-insert picture of a KIA Forte here-
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 4th Sep 2009 22:53
Not that the original code would have worked....too quick, not updating the screen etc.

But has no one heard of STEP?

As in:
FOR x = 1000 to 0 STEP -1
BLAH
NEXT

It is useful in some circumstances! (Ok, not this one ^_^)

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
BowserYo
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location:
Posted: 4th Sep 2009 22:58
Thanks guys! The code works to perfection! I am incorporating a bit of both concepts! The abs will come in useful later on!

ßõw§€r¥¤
Darkowen
18
Years of Service
User Offline
Joined: 10th Jan 2006
Location:
Posted: 4th Sep 2009 23:51
I would just use a variable.

global playerfade=100
global playeralive=1

do

If playeralive=0

if playerfade>0

playerfade=playerfade-1

endif
endif

set alpha mapping on obj#,playerfade

sync
loop

Adding in the 'if playerfade>0' stops it from going past zero as this would cause a problem because the lowest it can go is zero.


Download the Roshi kart beta at http://www.evilpigeon.co.uk

Login to post a reply

Server time is: 2024-09-28 10:27:48
Your offset time is: 2024-09-28 10:27:48