The display.colorSample() function does not work correctly

Hello!

The display.colorSample() function does not work correctly.

More details:

JSON = require('json')
CX, CY = display.contentCenterX, display.contentCenterY

local rect = display.newRect(CX, CY, 100, 100)

timer.performWithDelay(1000, function()
    
    display.colorSample(CX, CY,
    function(event)

        local r, g, b = event.r, event.g, event.b
        r, g, b = tonumber(r)*255, tonumber(g)*255, tonumber(b)*255

        print(r, g, b, JSON.encode(event))

    end)

end, 1)

Output: 0 0 0 {“y”:512,“x”:384,“name”:“colorSample”,“r”:0,“a”:0,“g”:0,“b”:0}

But I assumed that there would be 1 1 1 {“y”:512,“x”:384,“name”:“colorSample”,“r”:1,“a”:1,“g”:1"b":1}, since the rect object is still white color

Your code, in isolation as posted, is working for me as expected.

Have you test it on an empty project?

@C2G
Your code is working for me as expected.
I tested with Solar2D Simulator 2024.3704

No, project not empty. But I don’t understand what this could be related to…

I have already tested the code in an empty project, but the problem remains the same

I have updated Solar 2D to the latest version and everything works, but when building in .apk it gives an error. Well, that’s a completely different story…

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.