Hi guys, I have a problem with Lua when I try to add physic on my object created with tiled…
this is my code but when I tap on the screen, Corona shows me this message:
ATTEMPT TO CALL METHOD ‘addEventListener’ (a nil value)
what’s the problem?
thx!
lime = require("lime.lime") local map = lime.loadMap("first.tmx") local visual = lime.createVisual(map) local physical = lime.buildPhysical(map) local onObject= function (object) display.newImage(object.playerImage, object.c, object.y) end map:addObjectListener("PlayerSpawn", onObject) require("physics") physics.start() local player={} local onPlayerSpawnObject = function(object) local layer = map:getTileLayer("Player") player = display.newImage(layer.group, "vx051.png") player.x = object.x player.y = object.y physics.addBody(player, { density = 1.0, friction = 0.3, bounce = 0.2 }) end map:addObjectListener("PlayerSpawn", onPlayerSpawnObject) local onTouch = function(event) player:applyLinearImpulse(0, -5, player.x, player.y) end player:addEventListener("touch", onTouch)