如何在 corona sdk 中移动对象时更改其透明度?

我正在尝试创建一个可拖动的正方形,它会在靠近屏幕中心时逐渐变得透明(从两侧不可见到完全可见,如下面的图片所示)

enter image description here

enter image description here

enter image description here

点赞
用户3872374
用户3872374

你可以使用 alphatransition 来实现这个功能,尝试下面的代码,它应该可以工作... 下面的代码会在移动时,将正方形的不透明度从0%变为100%,时间为1.5

display.setDefault( "background", 80/255 )
local square = display.newRect(  0, display.contentHeight/2, 100, 100 )
square.anchorChildren = true
square:setFillColor( 255,255,0 )
square.alpha = 0

local w,h = display.contentWidth, display.contentHeight

transition.moveTo( square, { x = w/2, y = h/2, time=1500 , alpha = 1.0} )
2017-09-26 16:27:06