function MainScene:onCreate()
printf("resource node = %s", tostring(self:getResourceNode()))
local size = cc.Director:getInstance():getWinSize()
local x = size.width
local y = size.height
local blue = cc.LayerColor:create(cc.c4b(0, 0, 255, 255))--注掉这行看不同的结果
local red = cc.LayerColor:create(cc.c4b(255, 0, 0, 255))
local green = cc.LayerColor:create(cc.c4b(0, 255, 0, 255))
local white = cc.LayerColor:create(cc.c4b(255, 255, 255, 255))
blue:setScale(0.5)
blue:setPosition(-x / 4, -y / 4)
red:setScale(0.5)
red:setPosition(x / 4, -y / 4)
green:setScale(0.5)
green:setPosition(-x / 4, y / 4)
white:setScale(0.5)
white:setPosition(x / 4, y / 4)
self:addChild(blue,10)
self:addChild(white,11)
self:addChild(green,12)
self:addChild(red,13)
local sprite = display.newSprite("ui_force_20001.png")
:move(display.center)
:addTo(self, 14)
:setPosition(0, 0)--注掉这行看不同的结果
local scheduler = cc.Director:getInstance():getScheduler()
local function getCurrentResult()
local x = size.width
local y = size.height
local pixelCount = 4
local i = 1
local strFmt = ""
--blue
local bPixels = gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixelCount)
for i=1,pixelCount do
local strTmp = string.format("%d:%d ",i,bPixels[i])
strFmt = strFmt .. strTmp
end
print(strFmt)
if nil ~= schedulEntry then
scheduler:unscheduleScriptEntry(schedulEntry)
end
end
if nil ~= schedulEntry then
scheduler:unscheduleScriptEntry(schedulEntry)
end
schedulEntry = scheduler:scheduleScriptFunc(getCurrentResult, 0.1, false)
end
可自行调整代码测试