class 'Redblink' (Script)

function Redblink:__init() super()
end

function Redblink:on_attach()
  local scene=self:scene()
  self.left=scene:object('lightleft')
  self.right=scene:object('lightright')
  self.count=0
  self.timeright=2
  self.timeleft=2
  self.leftalpha=0
  self.rightalpha=1
  self.right:set_alpha(self.leftalpha)
  self.left:set_alpha(self.rightalpha)
end

function Redblink:on_update(dt)
  local leftitiration=self.timeleft/dt
  local rightitiration=self.timeright/dt
  self.count = self.count+1
   if self.count <leftitiration then
     self.leftalpha=self.leftalpha+1/leftitiration
     self.rightalpha=self.rightalpha-1/rightitiration
     self.right:set_alpha(self.rightalpha)
     self.left:set_alpha(self.leftalpha)
   else
    if self.count<leftitiration+rightitiration then
      self.leftalpha=self.leftalpha-1/leftitiration
     self.rightalpha=self.rightalpha+1/rightitiration
     self.right:set_alpha(self.rightalpha)
     self.left:set_alpha(self.leftalpha)
    else
    self.count=0
    end
  end
end