Hi thanks for the replies,
I am calling at the end just before the return, I shall post the whole file of code, it is quite long and I am not a pro developer so I apologise for the amateur nature of it
module(..., package.seeall)
-- Main function - MUST return a display.newGroup()
function new()
local localGroup = display.newGroup()
local mRand = math.random
-- Background
local background = display.newImage("images/fruit/background.png")
localGroup:insert(background)
local cloud = display.newImage("images/fruit/cloud.png")
cloud.x = 200
cloud.y = 150
--transition.to(cloud{time=10000, x=-20})
localGroup:insert(cloud)
local sun = display.newImage("images/sun/sunEyes.png")
sun.x = 70
sun.y = 80
localGroup:insert(sun)
local skate = display.newImage("images/fruit/skate.png")
skate.x = 160
skate.y = 350
skate.myName = "skate"
localGroup:insert(skate)
physics.addBody(skate, "static", { isSensor = true })
local strawberryPosition = display.newImage("images/fruit/strawberry3d.png")
strawberryPosition.x = mRand( 50, 270 )
strawberryPosition.y = -50
physics.addBody(strawberryPosition, { isSensor = true })
localGroup:insert(strawberryPosition)
local applePosition = display.newImage("images/fruit/apple3d.png")
applePosition.x = mRand( 50, 270 )
applePosition.y = -350
physics.addBody(applePosition, { isSensor = true })
localGroup:insert(applePosition)
local kiwiPosition = display.newImage("images/fruit/kiwi3d.png")
kiwiPosition.x = mRand( 50, 270 )
kiwiPosition.y = -650
physics.addBody(kiwiPosition, { isSensor = true })
localGroup:insert(kiwiPosition)
local pairPosition = display.newImage("images/fruit/pair3d.png")
pairPosition.x = mRand( 50, 270 )
pairPosition.y = -950
physics.addBody(pairPosition, { isSensor = true })
localGroup:insert(pairPosition)
local orangePosition = display.newImage("images/fruit/orange3d.png")
orangePosition.x = mRand( 50, 270 )
orangePosition.y = -1250
physics.addBody(orangePosition, { isSensor = true })
localGroup:insert(orangePosition)
local grapePosition = display.newImage("images/fruit/grapes3d.png")
grapePosition.x = mRand( 50, 270 )
grapePosition.y = -1550
physics.addBody(grapePosition, { isSensor = true })
localGroup:insert(grapePosition)
local pineapplePosition = display.newImage("images/fruit/pineapple3d.png")
pineapplePosition.x = mRand( 50, 270 )
pineapplePosition.y = -1850
physics.addBody(pineapplePosition, { isSensor = true })
localGroup:insert(pineapplePosition)
local bananaPosition = display.newImage("images/fruit/banana3d.png")
bananaPosition.x = mRand( 50, 270 )
bananaPosition.y = -2150
physics.addBody(bananaPosition, { isSensor = true })
localGroup:insert(bananaPosition)
local cherryPosition = display.newImage("images/fruit/cherries3d.png")
cherryPosition.x = mRand( 50, 270 )
cherryPosition.y = -2450
physics.addBody(cherryPosition, { isSensor = true })
localGroup:insert(cherryPosition)
local arrowLeft = display.newImage("images/fruit/arrow.png")
arrowLeft.x = 50
arrowLeft.y = 440
localGroup:insert(arrowLeft)
local arrowRight = display.newImage("images/fruit/arrow1.png")
arrowRight.x = 270
arrowRight.y = 440
localGroup:insert(arrowRight)
local backButton = display.newImage("images/squiback.png")
backButton.x = 20
backButton.y = 30
localGroup:insert(backButton)
local screenMessageStrawberry = display.newText( "Fraise", 160, 240, "Helvetica-Bold", 70)
screenMessageStrawberry:setTextColor( 0, 0, 255, 255 )
screenMessageStrawberry.xScale = 0.5
screenMessageStrawberry.yScale = 0.5
screenMessageStrawberry.xOrigin = 170
screenMessageStrawberry.yOrigin = 500
localGroup:insert(screenMessageStrawberry)
local screenMessageApple = display.newText( "Pomme", 160, 240, "Helvetica-Bold", 44)
screenMessageApple:setTextColor( 255, 255, 255, 255 )
screenMessageApple.alpha = 1.0
screenMessageApple.xScale = 0.5; screenMessageApple.yScale = 0.5
screenMessageApple.xOrigin = 170
screenMessageApple.yOrigin = 500
localGroup:insert(screenMessageApple)
local ScreenMessageKiwi = display.newText( "Kiwi", 160, 240, "Helvetica-Bold", 44)
ScreenMessageKiwi:setTextColor( 255, 0, 255, 255 )
ScreenMessageKiwi.alpha = 1.0
ScreenMessageKiwi.xScale = 0.5; ScreenMessageKiwi.yScale = 0.5
ScreenMessageKiwi.xOrigin = 170
ScreenMessageKiwi.yOrigin = 500
localGroup:insert( ScreenMessageKiwi )
local ScreenMessagePair = display.newText( "Poire", 160, 240, "Helvetica-Bold", 44)
ScreenMessagePair:setTextColor( 255, 255, 255, 255 )
ScreenMessagePair.alpha = 1.0
ScreenMessagePair.xScale = 0.5; ScreenMessagePair.yScale = 0.5
ScreenMessagePair.xOrigin = 170
ScreenMessagePair.yOrigin = 500
localGroup:insert( ScreenMessagePair )
local ScreenMessageOrange = display.newText( "Orange", 160, 240, "Helvetica-Bold", 44)
ScreenMessageOrange:setTextColor( 255, 255, 255, 255 )
ScreenMessageOrange.alpha = 1.0
ScreenMessageOrange.xScale = 0.5; ScreenMessageOrange.yScale = 0.5
ScreenMessageOrange.xOrigin = 170
ScreenMessageOrange.yOrigin = 500
localGroup:insert( ScreenMessageOrange )
local ScreenMessageGrape = display.newText( "Raisins", 160, 240, "Helvetica-Bold", 44)
ScreenMessageGrape:setTextColor( 255, 255, 255, 255 )
ScreenMessageGrape.alpha = 1.0
ScreenMessageGrape.xScale = 0.5; ScreenMessageGrape.yScale = 0.5
ScreenMessageGrape.xOrigin = 170
ScreenMessageGrape.yOrigin = 500
localGroup:insert( ScreenMessageGrape )
local ScreenMessagePinapple = display.newText( "Ananas", 160, 240, "Helvetica-Bold", 44)
ScreenMessagePinapple:setTextColor( 255, 255, 255, 255 )
ScreenMessagePinapple.alpha = 1.0
ScreenMessagePinapple.xScale = 0.5; ScreenMessagePinapple.yScale = 0.5
ScreenMessagePinapple.xOrigin = 170
ScreenMessagePinapple.yOrigin = 500
localGroup:insert( ScreenMessagePinapple )
local ScreenMessageBanana = display.newText( "banane", 160, 240, "Helvetica-Bold", 44)
ScreenMessageBanana:setTextColor( 255, 255, 255, 255 )
ScreenMessageBanana.alpha = 1.0
ScreenMessageBanana.xScale = 0.5; ScreenMessageBanana.yScale = 0.5
ScreenMessageBanana.xOrigin = 170
ScreenMessageBanana.yOrigin = 500
localGroup:insert( ScreenMessageBanana )
local ScreenMessageCherry = display.newText( "Cerries", 160, 240, "Helvetica-Bold", 44)
ScreenMessageCherry:setTextColor( 255, 255, 255, 255 )
ScreenMessageCherry.alpha = 1.0
ScreenMessageCherry.xScale = 0.5; ScreenMessageCherry.yScale = 0.5
ScreenMessageCherry.xOrigin = 170
ScreenMessageCherry.yOrigin = 500
localGroup:insert( ScreenMessageCherry )
local soundStrawberry = media.newEventSound( "sounds/fruit/fraisfra.wav" )
local soundApple = media.newEventSound( "sounds/fruit/pommefra.wav" )
local soundKiwi = media.newEventSound( "sounds/fruit/kiwifra.wav" )
local soundOrange = media.newEventSound( "sounds/fruit/orangefra.wav" )
local soundCherry = media.newEventSound( "sounds/fruit/cerisefra.wav" )
local soundBanana = media.newEventSound( "sounds/fruit/bananafra.wav" )
local soundPineapple = media.newEventSound( "sounds/fruit/ananasfra.wav" )
local soundGrapes = media.newEventSound( "sounds/fruit/raisinfra.wav" )
local soundPear = media.newEventSound( "sounds/fruit/poirefra.wav" )
local motionx = 0 --X Motion
local motiony = 0 -- Y Motion
local speed = 2 -- Speed
local function stop (event) --Statements to control when there is no
--touch
if "ended" == event.phase then --Check to see if the touch ended
motionx = 0
motiony = 0
end
end
Runtime:addEventListener("touch", stop ) --What activates the stop function
function move(event)
skate.x = skate.x + motionx
skate.y = skate.y + motiony
--text.text = speed
end
Runtime:addEventListener("enterFrame", move) --Every frame of the program will
function arrowLeft:touch()
motionx = -speed
motiony = 0
end
arrowLeft:addEventListener("touch", arrowLeft)
------
function arrowRight:touch()
motionx = speed
motiony = 0
end
arrowRight:addEventListener("touch", arrowRight)
function moveCloud(event)
transition.to(cloud, {time=12000, x=-100, y=150})
end
--cloud:addEventListener("touch", moveCloud)
function rotateSun(event)
if ( event.phase == "began" ) then
transition.to( sun, { time=1000, rotation=720})
end
end
--sun:addEventListener("touch", rotateSun)
-------------------------------------------------------------
-------------------------------------------------------------
local function onLocalCollision( self, event )
if ( event.phase == "began" ) then
media.playEventSound( soundStrawberry )
strawberryPosition:removeSelf()
strawberryPosition = nil
--This creates the word and then sends it upwards and fades is out
transition.to(screenMessageStrawberry, {time=3000, alpha=0, y=-50, transition = easing.linear})
end
end
strawberryPosition.collision = onLocalCollision
strawberryPosition:addEventListener( "collision", strawberryPosition )
local function onLocalCollisionApple( self, event )
if ( event.phase == "began" ) then
media.playEventSound( soundApple )
applePosition:removeSelf()
applePosition = nil
transition.to(screenMessageApple, {time=3000, alpha=0, y=-50, transition = easing.linear})
end
end
applePosition.collision = onLocalCollisionApple
applePosition:addEventListener( "collision", applePosition )
local function onLocalCollisionKiwi( self, event )
if ( event.phase == "began" ) then
media.playEventSound( soundKiwi )
kiwiPosition:removeSelf()
kiwiPosition = nil
transition.to(ScreenMessageKiwi, {time=3000, alpha=0, y=-50, transition = easing.linear})
end
end
kiwiPosition.collision = onLocalCollisionKiwi
kiwiPosition:addEventListener( "collision", kiwiPosition )
local function onLocalCollisionPair( self, event )
if ( event.phase == "began" ) then
media.playEventSound( soundPear )
pairPosition:removeSelf()
pairPosition = nil
transition.to(ScreenMessagePair, {time=3000, alpha=0, y=-50, transition = easing.linear})
end
end
pairPosition.collision = onLocalCollisionPair
pairPosition:addEventListener( "collision", pairPosition )
local function onLocalCollisionOrange( self, event )
if ( event.phase == "began" ) then
media.playEventSound( soundOrange )
orangePosition:removeSelf()
orangePosition = nil
transition.to(ScreenMessageOrange, {time=3000, alpha=0, y=-50, transition = easing.linear})
end
end
orangePosition.collision = onLocalCollisionOrange
orangePosition:addEventListener( "collision", orangePosition )
local function onLocalCollisionGrape( self, event )
if ( event.phase == "began" ) then
media.playEventSound( soundGrapes )
grapePosition:removeSelf()
grapePosition = nil
transition.to(ScreenMessageGrape, {time=3000, alpha=0, y=-50, transition = easing.linear})
end
end
grapePosition.collision = onLocalCollisionGrape
grapePosition:addEventListener( "collision", grapePosition )
local function onLocalCollisionPineapple( self, event )
if ( event.phase == "began" ) then
media.playEventSound( soundPineapple )
pineapplePosition:removeSelf()
pineapplePosition = nil
transition.to(ScreenMessagePinapple, {time=3000, alpha=0, y=-50, transition = easing.linear})
end
end
pineapplePosition.collision = onLocalCollisionPineapple
pineapplePosition:addEventListener( "collision", pineapplePosition )
local function onLocalCollisionBanana( self, event )
if ( event.phase == "began" ) then
media.playEventSound( soundBanana )
bananaPosition:removeSelf()
bananaPosition = nil
transition.to(ScreenMessageBanana, {time=3000, alpha=0, y=-50, transition = easing.linear})
end
end
bananaPosition.collision = onLocalCollisionBanana
bananaPosition:addEventListener( "collision", bananaPosition )
local function onLocalCollisionCherry( self, event )
if ( event.phase == "began" ) then
media.playEventSound( soundCherry )
cherryPosition:removeSelf()
cherryPosition = nil
transition.to(ScreenMessageCherry, {time=3000, alpha=0, y=-50, transition = easing.linear})
end
end
cherryPosition.collision = onLocalCollisionCherry
cherryPosition:addEventListener( "collision", cherryPosition )
local function back ( event )
if event.phase == "ended" then
director:changeScene("menu")
end
end
backButton:addEventListener("touch",back)
local goToLevel = function( event )
director:changeScene( "menu" )
end
local theTimer = timer.performWithDelay( 35000, goToLevel, 1 )
function clean(event)
Runtime:removeEventListener( "touch", move )
Runtime:removeEventListener( "enterFrame", stop )
backButton:removeEventListener("touch",back)
bananaPosition:removeEventListener( "collision", bananaPosition )
pineapplePosition:removeEventListener( "collision", pineapplePosition )
grapePosition:removeEventListener( "collision", grapePosition )
orangePosition:removeEventListener( "collision", orangePosition )
pairPosition:removeEventListener( "collision", pairPosition )
kiwiPosition:removeEventListener( "collision", kiwiPosition )
applePosition:removeEventListener( "collision", applePosition )
strawberryPosition:removeEventListener( "collision", strawberryPosition )
arrowLeft:removeEventListener("touch", arrowLeft)
arrowRight:removeEventListener("touch", arrowRight)
timer.cancel(theTimer)
collectgarbage("collect")
end
-- MUST return a display.newGroup()
return localGroup
end
Cheers again for helping
Chris [import]uid: 10697 topic_id: 11084 reply_id: 40355[/import]