Fabio
Fabio

Reputation: 3067

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?

Upvotes: 0

Views: 151

Answers (2)

Chomu
Chomu

Reputation: 224

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)

Upvotes: 0

Lukis
Lukis

Reputation: 652

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 }

Upvotes: 0

Related Questions