i’ve broken it up into small functions so you can see what each is doing
[lua]local obj
obj = display.newImage(“ball.png”)
obj.x = 100
obj.y = 100
local currentObjectType = “ball”
local function changeObjectTo(objType)
obj:removeSelf()
obj = display.newImage(objType…".png")
currentObjectType = objType
end
local function checkBall()
if(obj.y < display.contentHeight/2) then
changeObjectTo(“square”)
end
end
local function checkSquare()
if(obj.y < 0) then
obj.y=display.contentHeight()
changeObjectTo(“ball”)
end
end
local function moveObject()
obj.y=obj.y-1
end
local function checkObject()
if(currentObjectType == “ball”) then
checkBall()
elseif(currentObjectType==“square”) then
checkSquare()
end
end
local function onEnterFrame(event)
moveObject()
checkObject()
end
Runtime:addEventListener(“enterFrame”, onEnterFrame)[/lua] [import]uid: 6645 topic_id: 5460 reply_id: 18428[/import]