I want to move text objects around the screen each on random direction. I have code witch can move one object at a time. How I can modify this code? Loop?
[lua]local screenLeft = display.screenOriginX
local screenWidth = display.contentWidth - screenLeft * 2
local screenRight = screenLeft + screenWidth
local screenTop = display.screenOriginY
local screenHeight = display.contentHeight - screenTop * 2
local screenBottom = screenTop + screenHeight
display.contentWidth = screenWidth
display.contentHeight = screenHeight
local xDirection
local yDirection
local xSpeed = 4
local ySpeed = 4
function randomDirection()
repeat
xDirection = math.random(-1, 1)
yDirection = math.random(-1, 1)
until xDirection ~= 0 and yDirection ~= 0
return xDirection, yDirection
end
randomDirection()
local text1 = display.newText(“Hello”, 100, 200, native.systemFont, 34 )
–local text2 = display.newText(“World”, 160, 250, native.systemFont, 34 )
local function animate(event)
local xPos = text1.x + ( xSpeed * xDirection );
local yPos = text1.y + ( ySpeed * yDirection );
if ( xPos > screenRight or xPos < screenLeft ) then
xDirection = xDirection * -1;
end
if ( yPos > screenBottom or yPos < screenTop) then
yDirection = yDirection * -1;
end
text1:translate( xPos - text1.x, yPos - text1.y)
end
Runtime:addEventListener( “enterFrame”, animate )[/lua]
Sorry, I have no idea why my code align in one line without spaces between text.