performWithDelay bouncing object

I have an object (chickOne) which bounces around the screen, and I’m trying to delay its appearance. This is obviously not the way to do it :slight_smile: Can anyone suggest a strategy, an API or a document to read to achieve this? Thanks.

Kevin

[lua]
chickOne = display.newImage (“chicken.png”) – the chicken
chickOne.x = math.random( 55, 250)
chickOne.y = math.random( 55, 400)
chickOne:scale( .60, .60)
chickOne.isVisible = false – when chickOne appears it is invisible
localGroup:insert(chickOne)
local xPosChickOne,yPosChickOne = math.random( 20, 245),math.random( 20, 425)

function onMoveChickOne (event) – the bouncing code

chickOne.isVisible = true – when the delayed funct begins chickOne is visible

if chickOneVar ~= 1 then

xPosChickOne = xPosChickOne + ( 2.8 * chickSpeedX );
yPosChickOne = yPosChickOne + ( 2.2* chickSpeedY );

if (xPosChickOne > display.contentWidth - 20 or xPosChickOne < 20) then
chickSpeedX = chickSpeedX * -1;
end
if (yPosChickOne > display.contentHeight - 20 or yPosChickOne < 20) then
chickSpeedY = chickSpeedY * -1;

end

chickOne:translate( xPosChickOne - chickOne.x, yPosChickOne - chickOne.y)

end
end

– Runtime:addEventListener(“enterFrame”, onMoveChickOne)

timer.performWithDelay(
1000, onMoveChickOne )[/lua]
[import]uid: 96383 topic_id: 17021 reply_id: 317021[/import]

Have you tried using physics to bounce an object? It’s much less code and more realistic.

Please see the Physics SampleCode that comes bundled with the Corona download, and here’s the Physics documentation:

https://developer.anscamobile.com/reference/index/physics-engine [import]uid: 52430 topic_id: 17021 reply_id: 63926[/import]