Solved - Smooth color / opacity transition

Started by MetalZelda, January 14, 2016, 02:26:16 PM

Previous topic - Next topic
January 14, 2016, 02:26:16 PM Last Edit: January 14, 2016, 10:16:00 PM by MetalZelda
Hi.

So, today I was working on the Time System that is heavily based on Majora's Mask.
But, I am facing a problem, I want the tone between hours / minutes to have a smooth transition, fill_color just set the new color immediatly on the surface.

The script bellow is the Time system's Tone manager, everything you'll see is already declared in other script, the tone work perfectly, but I don't know how I could make tone value to increase smoothly and though, make the tone progress smooth

Code (lua) Select
local game = ...
local tone_manager = {}
local tone_timer

-- Day/Night system - Tone.

function game:start_tone_system()
  sol.menu.start(self:get_map(), tone_manager, false)
end

function tone_manager:on_started()
  self.game = game
 
  self.tone_surface = sol.surface.create(320,240)
  self.surface_opacity = 0
  self.target_opacity = 0
  self.color_r, self.color_g, self.color_b, self.color_alpha = 0, 0, 0, 0

  self:check()
end

function tone_manager:set_new_tone(r,g,b,a,o)
  if r ~= nil then
   self.color_r = r
  else
   self.color_r = 0
  end

  if g ~= nil then
   self.color_g = g
  else
   self.color_g = 0
  end
 
  if b ~= nil then
   self.color_b = b
  else
   self.color_b = 0
  end
 
  if a ~= nil then
   self.color_alpha = a
  else
   self.color_a = 0
  end
 
  if o ~= nil then
   self.target_opacity = o
  else
   self.target_opacity = 0
  end
print(self.color_r, self.color_g, self.color_b, self.color_alpha)
end

function tone_manager:get_target_tone()
return self.color_r, self.color_g, self.color_b, self.color_alpha
end

function tone_manager:get_target_opacity()
return self.target_opacity
end

-- Checks if the tone need to be updated
-- and updates it if necessary.
function tone_manager:check()
local minute = self.game:get_value("current_minute")
local hour = self.game:get_value("current_hour")
local world = self.game:get_map():get_world() or nil

  if world ~= "outside" then
    self.time_system = false
  else
    self.time_system = true
print("outside")
  end
 
   if (hour == 24 or hour == 0) and minute >= 0 and minute <= 30 then -- test, from midnight to 0:30
    self:set_new_tone(0, 0, 64,0, 150)
  else
self.tone_surface:set_opacity(0)
    self.tone_surface:fill_color{0,0,64}
  end
 
  -- Schedule the next check.
  sol.timer.start(self, self.game:get_value("time_flow") / 4, function()
    self:check()
  if self.time_system and self.game.is_new_map then
    self:rebuild_tone()
    self.game.is_new_map = false
  end
  end)
end

function tone_manager:rebuild_tone()
tone_timer = sol.timer.start(self.game:get_map(), self.game:get_value("time_flow") / 30, function()
self.tone_surface:set_opacity(self.target_opacity)
        self.tone_surface:fill_color{self.color_r, self.color_g, self.color_b, self.color_a}
return true
end)
end

function tone_manager:on_finished()
  sol.timer.stop_all(self)
  tone_timer:stop()
end

function tone_manager:on_draw(dst_surface)
  self.tone_surface:draw(dst_surface,0,0)
end

return tone_manager




This is the current result, the transition and clock work, but the color change is immediate ...


Any help would be welcome


January 14, 2016, 03:12:05 PM #2 Last Edit: January 14, 2016, 10:09:36 PM by MetalZelda
Hmmm, yes, that might be handy, thanks, gonna try it now

Okay, so based on your script I succeeded to make the time system to work.

Another last thing : Do you have any good tool / website that display rgba color ? This is something completly messy ...

Anyway, this is the result, the script is completed, the clock work correctly and the tone change every 30 minutes in-game, the tone is disabled when the player is somewhere else then the exterior. The tone is memorized and placed back when restarting the game / changing world