简体   繁体   中英

Corona SDK: transition.to and transition.moveBy not working

I have the need to use transition.moveBy in my app when I press a button, but when I call it I get:

Attempt to call field 'moveBy' (a nil value)

I have even tried to copy the sample code from the documentation, which is inside the function randomFunction:

local function randomFunction( ... )
    square = display.newRect( 0, 0, 100, 100 )
    transition.moveBy( square, { x=100, y=100, time=2000 } )
end

randomBtn = widget.newButton{
    labelColor = { default={255}, over={128} },
        width=57, height=55,
        onRelease = randomFunction
    }

How can I fix this?

Try this:

local widget = require( "widget" )

local function randomFunction( ... )
    local square = display.newRect( 0, 0, 100, 100 )
    transition.moveBy( square, { x=100, y=100, time=2000 } ) end

local randomBtn = widget.newButton{
    label = "my button",
    labelColor = { default={1,0.5,0.5}, over={0,0.5,0.5} },
    width=57, height=55,
    onRelease = randomFunction }

You did not declare the label text. So there is no visible button. Try to use Lukis answer. Just add the following line after declaring the square rectangle. So your rectangle color will be red and will also be visible.

square:setFillColor(255,0,0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM