I have an issue. I am trying to get some clouds that I have designed scrolling in the background on all of my menu pages. I found in the sample code the following piece of code and tried it in my menu.lua file and it works but when i touch a button on the screen plenty of errors keep coming up.
-- a bunch of clouds
-- change the y value on tree[1].x = 20; tree[1].y = 110 to set height
local tree = {}
tree[1] = display.newImage( "images/cloud 6.png" )
tree[1].xScale = 0.7; tree[1].yScale = 0.7
tree[1]:setReferencePoint( display.BottomCenterReferencePoint )
tree[1].x = 20; tree[1].y = 110
tree[1].dx = 0.1
tree[2] = display.newImage( "images/cloud 3.png" )
tree[2].xScale = 0.6; tree[2].yScale = 0.6
tree[2]:setReferencePoint( display.BottomCenterReferencePoint )
tree[2].x = 120; tree[2].y = 140
tree[2].dx = 0.2
tree[3] = display.newImage( "images/cloud 1.png" )
tree[3].xScale = 0.8; tree[3].yScale = 0.8
tree[3]:setReferencePoint( display.BottomCenterReferencePoint )
tree[3].x = 200; tree[3].y = 160
tree[3].dx = 0.1
tree[4] = display.newImage( "images/cloud 2.png" )
tree[4].xScale = 0.5; tree[4].yScale = 0.5
tree[4]:setReferencePoint( display.BottomCenterReferencePoint )
tree[4].x = baseline; tree[4].y = 130
tree[4].dx = 0.4
tree[5] = display.newImage( "images/cloud 2\_2.png" )
tree[5].xScale = 0.6; tree[5].yScale = 0.8
tree[5]:setReferencePoint( display.BottomCenterReferencePoint )
tree[5].x = 300; tree[5].y = 140
tree[5].dx = 0.2
tree[6] = display.newImage( "images/cloud 4.png" )
tree[6].xScale = 0.9; tree[5].yScale = 0.5
tree[6]:setReferencePoint( display.BottomCenterReferencePoint )
tree[6].x = 320; tree[6].y = 130
tree[6].dx = 0.6
tree[7] = display.newImage( "images/cloud 5.png" )
tree[7].xScale = 0.4; tree[7].yScale = 0.4
tree[7]:setReferencePoint( display.BottomCenterReferencePoint )
tree[7].x = 380; tree[7].y = 160
tree[7].dx = 0.7
-- A per-frame event to move the elements
local tPrevious = system.getTimer()
local function move(event)
local tDelta = event.time - tPrevious
tPrevious = event.time
local xOffset = ( 0.2 \* tDelta )
local i
for i = 1, #tree, 1 do
tree[i].x = tree[i].x - tree[i].dx \* tDelta \* 0.2
if (tree[i].x + tree[i].contentWidth) \< 0 then
tree[i]:translate( 480 + tree[i].contentWidth \* 2, 0 )
end
end
end
-- Start everything moving
Runtime:addEventListener( "enterFrame", move );
I error I get says that there is an error in line 95 which is the following line. “tree[i].x = tree[i].x - tree[i].dx * tDelta * 0.2”
but i have tried everything.
Is there a way to stop this when i tap the button. I have been told to stop a runtime and they gave me a piece of code to try but it just didn’t work.
If there is no way of stopping the erros popping up (i will post the error below) is there something else i an do to get some clouds to move in the background?
The error i get back is:
\document path//corona projectRuntime Error
\document path//menu.lua:95: attempt to perform arithmetic on field ‘x’ stack traceback
This error keeps repeating itself.
I really need some help. I am so close to finishing this project and this is one of the last things i need to do.
Thanks
Ryan [import]uid: 111430 topic_id: 26579 reply_id: 326579[/import]