Corona detects the collision but when it calls the collision(fight) function it doesn’t pass a meaningful event object. I’m unable to access event.phase or event.target although the event object exists.
Here’s the code:
local version = 0 -- Hide status bar display.setStatusBar(display.HiddenStatusBar) -- Screen Coordinates centerX = display.contentCenterX centerY = display.contentCenterY screenLeft = display.screenOriginX screenWidth = display.contentWidth - screenLeft \* 2 screenRight = screenLeft + screenWidth screenTop = display.screenOriginY screenHeight = display.contentHeight - screenTop \* 2 screenBottom = screenTop + screenHeight display.contentWidth = screenWidth display.contentHeight = screenHeight local physics = require("physics") physics.setDrawMode("normal") local json = require("json") math.randomseed(os.time()); physics.start(); physics.setGravity( 0, 0 ) local function fight(event) ----- This is where its happening. event.phase return nil. print(event.phase); if ( event.phase == "began" ) then print( self.myName .. ": collision began with " .. event.other.myName ) end end local enemy; local floor = display.newRect(centerX, screenBottom, 10000, 50) floor.anchorX = 0.5; floor.anchorY = 1; local function spawn\_enemy() enemy = display.newRect(0, 0, 50, 100); enemy:setFillColor(.7) enemy.anchorY = 1; enemy.x = screenLeft; enemy.y = floor.y - floor.height; enemy.speed = -1; enemy.collision = fight; physics.addBody(enemy); enemy.isSleepingAllowed = false; enemy:addEventListener("collision", enemy); end player = display.newRect(0, 0, 50, 100); player:setFillColor(.7) player.anchorY = 1; player.x = screenRight; player.y = floor.y - floor.height; player.speed = 1; player.collision = fight; physics.addBody(player); player.isSleepingAllowed = false; player:addEventListener("collision", player); local walk = function( event ) --for i, v in ipairs(mob) do player.x = player.x - player.speed; enemy.x = enemy.x - enemy.speed; --end end Runtime:addEventListener( "enterFrame", walk); spawn\_enemy();
Look over my spaghetti code if any, I’ve tried just about everything I could come up with.
Any Suggestions?
Thanks