I have declared the following variables for multi-element bodies png files in corona all are physics bodies
local h2 = h2.png complex body composed of element1, element2 and element3
h2.myName = “h”
local h1 = h1.png complex body composed of element1 and element2
h1.myName = “h”
local h0 = h0.png body composed of element1 only
h0.myName = “h”
local m2 = m2.png complex body composed of element1, element2 and element3
m2.myName = “m”
local m1 = m1.png complex body composed of element1 and element2
m1.myName = “m”
local m0 = m0.png body composed of element1 only
m0.myName = “m”
I need to setup some collision with image switching
( x,y coordinates of previous images will be recorded and assign to new image )
element1 in all cases refers to circle or rect depending on image
element2 and element3 whichever on presents in an image refers to a line
only element1 coming into contact with element2 or element3 triggers a collision
if element1 of h2 collides with element2 or element3 of m2 then m2 becomes m1
if element1 of h1 collides with element2 or element3 of m2 then m2 becomes m1
if element1 of m1 collides with element2 or element3 of h2 then h2 becomes h1
if element1 of m2 collides with element2 or element3 of h2 then h2 becomes h1
if element1 of h2 collides with element2 of m1 then m1 becomes m0
if element1 of h1 collides with element2 of m1 then m1 becomes m0
if element1 of m2 collides with element2 of h1 then h1 becomes h0
if element1 of m1 collides with element2 of h1 then h1 becomes h0
The collision is not giving any result on screen nothing happens here is the code below,
Is it possible to declare h0, h1, m0 and m1 without displaying the image first because
they should only appear after a collision but I think I need to declare them first since
they have different shapes from m2 and h2
[lua]local physics = require( “physics”)
physics.start()
physics.setDrawMode( “hybrid” )
display.setStatusBar (display.HiddenStatusBar)
–in this example h2 is a rectangle with 2 obliques lines on top, left line is hh1, right line is hh2
–Format is x, y , x , y , x, y , x , y
local rect = {-35, -71.5 , 39, -71.5 , 39.5, -31 , -36, -29.5}
local hh1 = { -22, -71.5 , -56.5, -121 , -55, -125.5 , -14, -71.5 }
local hh2 = { 52, -126.5 , 54.5, -122 , 26.5, -72 , 21, -71.5 }
– m2 is a cricle with 2 obliques lines on top, left line is mh1, right line is mh2
local circle = { 10, -65.5 , 26, -58.5 , 36.5, -48 , 42.5, -34 , 42.5, -16 , 26, 8.5 , -22, -58.5 , -6, -65.5 }
local mh1 = { -72.5, -126 , -24.5, -57 , -29.5, -55 , -78, -123.5 , -78.5, -128 }
local mh2 = { 96.5, -124 , 38, -47.5 , 33, -52.5 , 89.5, -124 , 95, -127.5 }
local h0 = display.newImage(“h0.png”)
h0.x = 70 h0.y = 320
h0.myName = “h”
physics.addBody(h0, “static”,
{ density=10.0, friction=0.6, bounce=0.5, shape=rect})
local h1 = display.newImage(“h1.png”, 50, 62)
h1.x = 240 h1.y = 320
h1.myName = “h”
physics.addBody(h1, “static”,
{ density=10.0, friction=0.6, bounce=0.5, shape=rect},
{ density=10.0, friction=0.6, bounce=0.5, shape=hh1}
)
local h2 = display.newImage(“h2.png”, 50, 62)
h2.x = 410 h2.y = 320
h2.myName = “h”
h2.isHero = true
physics.addBody(h2, “static”,
{ density=10.0, friction=0.6, bounce=0.5, shape=rect},
{ density=10.0, friction=0.6, bounce=0.5, shape=hh1},
{ density=10.0, friction=0.6, bounce=0.5, shape=hh2}
)
local m0 = display.newImage(“m0.png”, 50, 62)
m0.x = 70 m0.y = 160
m0.myName = “m”
physics.addBody(m0, “static”,
{ density=10.0, friction=0.6, bounce=0.5, shape=circle})
local m1 = display.newImage(“m1.png”, 50, 62)
m1.x = 220 m1.y = 160
m1.myName = “m”
physics.addBody(m1, “static”,
{ density=10.0, friction=0.6, bounce=0.5, shape=circle},
{ density=10.0, friction=0.6, bounce=0.5, shape=mh1}
)
local m2 = display.newImage(“m2.png”, 50, 62)
m2.x = 360 m2.y = 160
m2.myName = “m”
physics.addBody(m2, “static”,
{ density=10.0, friction=0.6, bounce=0.5, shape=circle},
{ density=10.0, friction=0.6, bounce=0.5, shape=mh1},
{ density=10.0, friction=0.6, bounce=0.5, shape=mh2}
)
–if element1 of h2 collides with element2 or element3 of m2 then m2 becomes m1
function handleCollision(event)
if (((event.object1 == h2.rect) and (event.object2 == m2.mh1)) or ((event.object2 == h2.rect) and (event.object1 == m2.mh2))) then
m2 = display.newImage(“m1.png”, m2.x, m2.y)
end
end
Runtime:addEventListener(“collision”, handleCollision) [import]uid: 43696 topic_id: 9493 reply_id: 309493[/import]


