Author Topic: surface:fade_in/out issue ?  (Read 646 times)

MetalZelda

  • Hero Member
  • *****
  • Posts: 508
    • View Profile
surface:fade_in/out issue ?
« on: January 05, 2017, 12:11:00 am »
Hello.

When fading a surface by using fade in or fade out, our goal is to have the surface's opacity to 255 or 0, but the opacity, is never at 0 or 255, is this intentionnal ?

Zefk

  • Sr. Member
  • ****
  • Posts: 492
  • Just helping Solarus
    • View Profile
    • Zelzec Business
Re: surface:fade_in/out issue ?
« Reply #1 on: January 05, 2017, 12:55:43 am »
It worked for me in the script below.

Code: Lua
  1. --[[
  2. 1.Activate fade with key "a"
  3. 2.Fade out with key "o"
  4. 3.Fade in with key "i"
  5. --]]
  6.  
  7. --Pass the game parameter to the script.
  8. local game = ...
  9.  
  10. --Creating surfaces for the images and loading in the images.
  11. local fade_img = sol.surface.create ("fade.png")
  12.  
  13. local fade = false
  14.  
  15. --Solarus key pressing function
  16. function sol.main:on_key_pressed(key)
  17.  
  18. --Pause the game
  19. game:set_paused(true)
  20.  
  21. --Activates images on key 'a'
  22.    if key == "a" then
  23.      fade = true
  24.    end
  25.  
  26. ----Activates fade in on key 'i'
  27.    if key == "i" then
  28.      fade_img:fade_in(100)
  29.    end
  30.  
  31. ----Activates fade out on key 'o'
  32.    if key == "o" then
  33.      fade_img:fade_out(100)
  34.    end
  35.  
  36. end -- end of key press function
  37.  
  38. --Function for drawing or showing images
  39. function sol.main:on_draw(screen)
  40.  
  41. --Show the fade image if true
  42.   if fade == true then
  43.     fade_img:draw(screen)
  44.   end
  45.  
  46. end -- end of draw function
  47.  
  48.  

I had some issues at first when the image would not fade out completely, but I thought I was just using surface:fade_in/out wrong.
« Last Edit: January 05, 2017, 01:01:04 am by Zefk »

MetalZelda

  • Hero Member
  • *****
  • Posts: 508
    • View Profile
Re: surface:fade_in/out issue ?
« Reply #2 on: January 07, 2017, 06:14:50 pm »
That's not how it looks on me, it is so random, sometimes it fade completely, sometimes not.

https://www.youtube.com/watch?v=KGXre9FlDKQ

Notice that the movement is the same, so it has the same duration whever it is called.

fading lifetime is set to 5, in and out
movement speed is constantly at 139
other objects (text) are moved along with the graphic's x and y

The text is drawn in a surface, so the fade effect can be played, however, it doesn't have the issue it seems ...

For a menu this is not a problem, but for in-game entities like npc or else, this could be problematic
« Last Edit: January 07, 2017, 06:16:34 pm by MetalZelda »

Diarandor

  • Hero Member
  • *****
  • Posts: 781
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: surface:fade_in/out issue ?
« Reply #3 on: January 07, 2017, 07:54:59 pm »
Maybe it's a bug. Or maybe some built-in code is not updating the transparencies in a smooth/continuous way for performance? (Or maybe both things.) If so, maybe Christopho can confirm it.

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1043
    • View Profile
Re: surface:fade_in/out issue ?
« Reply #4 on: January 07, 2017, 09:13:43 pm »
Looks like a bug.

Diarandor

  • Hero Member
  • *****
  • Posts: 781
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: surface:fade_in/out issue ?
« Reply #5 on: January 07, 2017, 09:38:37 pm »
@MetalZelda: could you open an issue in github for this? (Before this subject is forgotten...) Thanks!