Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Tint bug - SOLVED - not a bug!

edited March 2015 in Bugs Posts: 318

Hi, I've been trying to tint a sprite to no avail.

The code I'm using in the draw function is

        tint(255,255,255,255)
        sprite("Project:rocka",self.x,self.y,self.w,self.h)

And nothing happens. Am I missing something or is this function redundant now?

Thanks,
The Major

Tagged:

Comments

  • Did you try tinting it to a different color? That works for me...I wonder why white doesn't work anymore? I could try coding you a function that takes a sprite as an argument and tints it to white if you really needed it.

  • Posts: 175

    If you trying tint to white it wont tint your image

  • Posts: 318

    Ah I see @lupino8211 that makes sense.

    So I've changed the tint to 255,255,5,255 which is a hello and it tints every object below that too in terms of depth

  • edited March 2015 Posts: 318

    Thanks @TheSoldierKing it's a flash I'm trying to build in when you shoot something like the old arcade and 8bit shooters the object flashes white briefly per hit

  • Here ya go, as well as with an example that shows how to use it.

    -- Example
    
    -- Use this function to perform your initial setup
    function setup()
        img1 = readImage("Planet Cute:Character Boy")
        img2 = tintImage(img1)
        frame = 0
        curImg = img1
    end
    
    -- This function gets called once every frame
    function draw()
        -- This sets a dark background color 
        background(0,0,0)
    
        -- This sets the line thickness
        strokeWidth(5)
        -- Do your drawing here
        if frame<60 or frame>70 then 
            curImg = img1
        else curImg = img2
        end
        sprite(curImg, WIDTH/2, HEIGHT/2)
        frame = frame + 1
        text(math.floor(1/DeltaTime), WIDTH-10, HEIGHT-10)
    end
    
    function tintImage(img)
        local i = img
        local w,h = spriteSize(img)
        local endImg = image(w,h)
        local col = color()
        for x=1,w do
            for y=1,h do
                col.r,col.g,col.b,col.a = i:get(x,y)
                if col.a~=0 then
                    col.r,col.g,col.b = 255, 255, 255
                end
                endImg:set(x,y,col)
            end
        end
        return endImg
    end
    
    
  • edited March 2015 Posts: 192

    Just as a side note, you probably want to make a new image in setup rather than calling this function every frame, as with large images this might cause crashes due to lack of memory. Also, it would ruin your framerate.
    EDIT: I just tried calling it in draw(), I got a framerate of 8. Yeah, don't do that. Create a new image in setup and change it when you need to.

  • Posts: 2,020

    You already have a thread on this subject. I just posted a solution in the other thread.

  • Posts: 318

    Hey @TheSoldierKing thanks for exploring I think I saw tint as a one line option to keep the code down. I Think you're right about a new image. I'll do that.

    Hey @yojimbo2000 you're right although over in that thread I was trying to tint a mesh and over here a sprite. I'll go take a look.

    Thanks to you both for the explorations and explanations!!

Sign In or Register to comment.