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.

AppGameKit Classic Chat / how do i fade a sprite??

Author
Message
kirtn14
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 8th Sep 2011 18:58
i cant find this code anywhere plaese help. how do i fade a sprite?

kirtnicholls
Crystal Noir
AGK Bronze Backer
13
Years of Service
User Offline
Joined: 7th Sep 2011
Location: France
Posted: 8th Sep 2011 20:15
Hello....

May be you can try to fade a sprite playing with alpha with the SetSpriteColorAlpha command.
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 8th Sep 2011 20:35
SetSpriteColorAlpha(spriteNum, alpha)

0 alpha is fully transparent, 255 is fully opaque.
kirtn14
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 8th Sep 2011 20:44
Thanks also do you know how to set a time gap between each code? I want to make it so that when one sprite hits another it one the sprite bounces off and the sprite that is hit no longer exists

kirtnicholls
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 8th Sep 2011 21:06 Edited at: 9th Sep 2011 15:58
Replace the spriteID with the number of the sprite you are working with.

for f = 255 to 0 step -1
      SetSpriteColorAlpha(spriteID, f)
      sync()
      sleep(f)
next f

It may take a second or two to start doing its thing.
If it gives you any trouble then take the sleep(f) line out.


Here is another way that won't pause your main loop...

Global mlc
mlc = 0
Global f
f = 255

// main loop
do
    mlc = mlc + 1
    If mlc > 9
        mlc = 0
        f = f - 1
        if f < 0 then f = 0
        SetSpriteColorAlpha(spriteID, f)
    endif
sync()
loop


Now, the reduction of f is only happening every tenth time through the main loop thanks to the main loop counter (mlc).
Depending on the speed of your main loop, you would adjust the number 9 in the 'if mlc > 9' line, so it would do it more or less often.
Or, you could take off more than 1 in the fade as in... f = f - 5

Setting the 9 to 3 and the 1 to 5 seems to work nicely in my test.
Give that a whirl and see what happens.

Login to post a reply

Server time is: 2024-11-23 12:08:51
Your offset time is: 2024-11-23 12:08:51