How to make an object move randomly on the screen ?
e.g.I want to make flies that would be moving on the screen here and there? [import]uid: 45566 topic_id: 24459 reply_id: 324459[/import]
Hey there, try running this code;
[lua]–The background
local bg = display.newRect( 0, 0, 320, 480 )
bg:setFillColor(0, 215, 255)
–Add a fly
local fly = display.newCircle( 160, 160, 10 )
fly:setFillColor(0, 0, 0)
–Move fly randomly
local function moveFly()
transition.to(fly, {x=math.random(20,320), y=math.random(20,460), onComplete=moveFly})
end
moveFly()[/lua]
Peach
[import]uid: 52491 topic_id: 24459 reply_id: 98949[/import]