I have a game application. so far I have created two separate movie objects i.e. Player1 and Player2. Now when Player 1 punches to player2 then I want collission event /action but my below code is not detecting collission event. please help.
local physics = require(“physics”)
physics.start()
physics.setGravity(0, 20)
display.setStatusBar( display.HiddenStatusBar )
– Load external Lua libraries (from project directory)
local movieclip = require( “movieclip” )
local ui = require( “ui” )
– Load background
local background = display.newImage(“Test2.png”)
background:scale(0.48, 0.64 )
background.x = 250
background.y = 160
foreground = display.newGroup()
– Initialize a second cube anim (this time by creating the image table dynamically)
imageTable = {}
for i = 1,3 do
table.insert( imageTable, “Hero” … i … “.png” )
end
myAnim = movieclip.newAnim( imageTable )
foreground:insert( myAnim )
myAnim.x = 195
myAnim.y = 230
myAnim:scale(0.35, 0.35 )
local myAnim1 = movieclip.newAnim{ “Enemy1.png”, “Enemy2.png”, “Enemy3.png”, “Enemy4.png”, “Enemy5.png”, “Enemy6.png”, “Enemy7.png”,“Enemy8.png”,“Enemy9.png”,“Enemy10.png”, “Enemy11.png”, “Enemy12.png”, “Enemy13.png”, “Enemy14.png”, “Enemy15.png”, “Enemy16.png”,“Enemy17.png”,“Enemy18.png”,“Enemy19.png”,“Enemy20.png”,“Enemy21.png”}
myAnim1.x = 210
myAnim1.y = 210
myAnim1:scale(0.4, 0.4 )
local function launchAttack1()
myAnim:playTest{ startFrame=1, endFrame=3, loop=1}
myAnim1:play{ startFrame=1, endFrame=21, loop=1}
end
local resetButton = ui.newButton{
default = “coconut.png”,
over = “coconut.png”,
x = 400,
y = 280,
onPress = launchAttack1,
text = “P”,
emboss = true
}
myAnim1.collision = onLocalCollision
myAnim1:addEventListener( “collision”, myAnim1 )
– Take care of collisions
local function onLocalCollision( self, event )
if ( event.phase == “began” ) then
print( self.myName … ": collision began with " … event.other.myName )
elseif ( event.phase == “ended” ) then
print( self.myName … ": collision ended with " … event.other.myName )
end
end
thanks in advance [import]uid: 80396 topic_id: 13592 reply_id: 313592[/import]
[import]uid: 52491 topic_id: 13592 reply_id: 50151[/import]