Hey,
Why appear this error? I was finding a possible solution but I not found nothing, please can you help me to resolved the problem?
This is the code, in “theory” when the bullet collision with piruleta1, this would be remove, only one. Thanks in advance!
----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- local math, physics = require("math"), require('physics') physics.start() physics.setGravity( 0, 0 ) display.setStatusBar( display.HiddenStatusBar ) local screenW, screenH = display.contentWidth, display.contentHeight local playerX, playerY = (screenW / 2), (screenH / 1) local player = display.newRect( 0, 0, 30, 30 ) player.x = playerX player.y = playerY local function onScreenTouch( event ) if (event.phase == "began") then speed = 100 deltaX = event.x - playerX deltaY = event.y - playerY normDeltaX = deltaX / math.sqrt(math.pow(deltaX,2) + math.pow(deltaY,2)) normDeltaY = deltaY / math.sqrt(math.pow(deltaX,2) + math.pow(deltaY,2)) angle = math.atan2( deltaY, deltaX ) \* 180 / math.pi -- angleT.text = angle bullet = display.newRect( 0, 0, 6, 6 ) bullet.x = playerX bullet.y = playerY physics.addBody( bullet) bullet.myName = "bala" bullet:setLinearVelocity( normDeltaX \* speed, normDeltaY \* speed ) end end local function onCollision( event ) if ( event.phase == "ended" ) then print( "objeto1: " .. event.object1.myName .. " onjeto2 " .. event.object2.myName ) if event.object1.myName == "piruleta1" then if( piruleta1.removeSelf ~= nil ) then piruleta1:removeSelf() bullet:removeSelf() end end end end Runtime:addEventListener( "collision", onCollision ) Runtime:addEventListener( "touch", onScreenTouch ) local function spawnObject() piruleta1 = display.newRect( 0, 0, 30, 30 ) piruleta1.x = math.random(10,50) piruleta1.y = math.random(10,50) physics.addBody( piruleta1, "static" ) piruleta1.myName = "piruleta1" end timer.performWithDelay(1,spawnObject,3)