Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Hue fading with sprite.tone

hrmm, I'm not too sure what I'm trying to do is called. I have a sprite. On the update function of the scene I'm trying to make this sprite fade from -255(RGB) to 255 then back to -255 continuously. is there some way i can use Math::Sin() to do this?

this is my current code which creates an okay effect.
Code:
def update_command

    @sprite.tone = Tone.new(@spr,@spg,@spb)
    
        
    if @reverse != true
      @spr += 2
      @spg += 3
      @spb += 7
    else
      @spr -= 2
      @spg -= 3 
      @spb -= 7
    end
   
    if @spr >= 255 then
      @reverse = true
    end
    if @spr <= -255 then
      @reverse = false
    end
 
Code:
@sprite.tone = Tone.new(@spr, @spg, @spb)

@step = 1
@c = ((!@c.nil? && @c >= 359) ? 0 : [@c + @step, 359].min)
@spr = @spg = @spb = 255 * Math.sin((@c*Math::PI)/180)

I think that should do, but just note that sine calculations have more overhead than normal methods (like yours).
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top