Hi everybody,
Just started to play with Corona for a while, looks very promising indeed, but I hit a major obstacle.
I just could not manage to get the collision event to report either object1 or object2, here are the codes I am struggling with:
_display.setStatusBar(display.HiddenStatusBar)
local background = display.newImage(“background.png”)
local obj1 = display.newImage(“object1.png”)
obj1.myName = “ball”
physics = require(“physics”);
physics.start()
physics.setGravity( 0, 0 )
physics.addBody(obj1, “dynamic”, {radius=25})
local leftWall = display.newRect(0, 0, 1, display.contentHeight)
leftWall:setFillColor(192, 255, 255)
leftWall.myName = “leftWall”
physics.addBody( leftWall, “static”)
local rightWall = display.newRect(display.contentWidth-1, 0, 10, display.contentHeight)
rightWall:setFillColor(192, 255, 255)
rightWall.myName = “rightWall”
physics.addBody( rightWall, “static”)
local bottomWall = display.newRect(0, display.contentHeight-1, display.contentWidth, 1)
bottomWall:setFillColor(192, 255, 255)
bottomWall.myName = “bottomWall”
physics.addBody( bottomWall, “static”)
local topWall = display.newRect(0, 0, display.contentWidth, 1)
topWall:setFillColor(192, 255, 255)
topWall.myName = “topWall”
physics.addBody( topWall, “static”)
local function bounceFromWall( event )
print( "event: " …event.name… "; object1: " …event.object1.myName… "; object2: " …event.object2.myName )
end
obj1:addEventListener(“collision”, bounceFromWall)
leftWall:addEventListener(“collision”, bounceFromWall)
rightWall:addEventListener(“collision”, bounceFromWall)
topWall:addEventListener(“collision”, bounceFromWall)
bottomWall:addEventListener(“collision”, bounceFromWall)
function moveRandomly()
obj1:setLinearVelocity( 100, 150);
end
timer.performWithDelay(500, moveRandomly, 1);_
It seems the bounceFromWall function could be triggered, but it just kept telling me “attempt to index field ‘object1’ (a nil value)”. Not just object1, but also object2, were not exposed from the ‘event’ object variable at all.
Anybody have ideas about that?
Jimmy [import]uid: 11908 topic_id: 33324 reply_id: 333324[/import]
