Hello everyone,
I would like to create my first game with tutorial - click
Unfortunately, I have some errors, but I don’t know how to fix that. Can you look at my code? Here is one of files:
display.setStatusBar(display.HiddenStatusBar) local storyboard = require "storyboard" storyboard.gotoScene("game")
here is the second:
-- requires local physics = require "physics" physics.start() local storyboard = require "storyboard" local scene = storyboard.newScene() -- background function scene:createScene(event) local screenGroup = self.view local background = display.newImage("bg.png") city1 = display.newImage("city1.png") city1.x = 0 city1.y = 120 city1.speed = 1 city2 = display.newImage("city1.png") city2.x = 480 city2.y = 120 city2.speed = 1 city3 = display.newImage("city2.png") city3.x = 0 city3.y = 420 city3.speed = 2 city4 = display.newImage("city2.png") city4.x = 480 city4.y = 420 city4.speed = 2 jet = display.newImage("redJet.png") jet.x = 100 jet.y = 100 physics.addBody(jet, "dynamic", {density=.1, bounce=0.1, friction=.2, radius=12}) end function scrollCity(self, event) if self.x \< -477 then self.x = 480 else self.x = self.x - self.speed end end function activateJets(self, event) self:applyForce(0, -1.5, self.x, self.y) end function touchScreen(event) -- print("touch") if event.phase == "began" then jet.enterFrame = activateJets Runtime:addEventListener("enterFrame", jet) end if event.phase == "ended" then Runtime:removeEventListener("enterFrame", jet) end end function scene:enterScene(event) Runtime:addEventListener("touch", touchScreen) city1.enterFrame = scrollCity Runtime:addEventListener("enterFrame", city1) city2.enterFrame = scrollCity Runtime:addEventListener("enterFrame", city2) city3.enterFrame = scrollCity Runtime:addEventListener("enterFrame", city3) city4.enterFrame = scrollCity Runtime:addEventListener("enterFrame", city4) end function scene:exitScene(event) end function scene:destroyScene(event) end scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) return scene
Error’s screen:
My code is the same like code in the tutorial. What’s wrong? What should I do?
Greetings,
Angela