在Corona SDK-621中添加了一对关于图形的颜色特效:着色和色调渐变!
1.着色
现在你可以通过调用setFillColor()方法来给图像对象着色。你传进来的颜色就像是一个固定的对象,在Corona中我们把它解释为着色。参数的个数决定如何解析这些数字。如果你传进了1个或2个那决定的就是灰度,如果是3个或4个那决定的是颜色:
image:setFillColor( gray )
image:setFillColor( gray, alpha )
image:setFillColor( red, green, blue )
image:setFillColor( red, green, blue, alpha )
这里有一个简单的例子,以HelloWorld作为例子来说明如何使用它。4次加载world.jpg。第一次是正常的,后面3次使用了不同的着色:
local w,h = display.contentWidth*0.5, display.contentHeight*0.5
local halfW,halfH = 0.5*w, 0.5*h
local background = display.newImageRect( "world.jpg", w,h )
background:translate( halfW, halfH )
local dw = w + halfW
local dh = h + halfH
local background = display.newImageRect( "world.jpg", w,h )
background:setFillColor( 255, 255, 0 )
background:translate( dw, halfH )
local background = display.newImageRect( "world.jpg", w,h )
background:setFillColor( 255, 255, 0 )
background:translate( halfW, dh )
local background = display.newImageRect( "world.jpg", w,h )
background:setFillColor( 255, 0, 255 )
background:translate( dw, dh )
2.色调渐变
现在你可以使用graphics.newGradient()为文本对象和固定的长方形(也就是纯粹的rects,而不是圆形的rects)。通过调用graphics.newGradient()你创建一个新的色调对象。你可以通过text:setTextColor()和rect:setFillColor()来调用这个对象。
下面的代码演示了一个垂直方向的色调渐变,从黄色渐变到(几乎是)一条白色:
local myText =
display.newText( "Hello, World!", 0, 0, native.systemFont, 40 )
myText.x = display.contentWidth * 0.5
myText.y = display.contentWidth * 0.25
local g = graphics.newGradient( { 255, 255, 0 }, { 200 }, "down" )
myText:setTextColor( g )