corona - Changing display Image when interacting to other display -


i'm new in corona , i'm trying make simple game android. have 2 display "ball" , "stone" both of them have added physics, i'm trying detect or check if ball touches stone change image of ball.

any thought highly appreciated.

steps given below -

local physics = require( "physics" ) physics.start()

local firstobject = display.newimage( "bkg_ firstobject.png" ) firstobject.x = display.contentwidth / 2 firstobject.y = 100

local secondobject = display.newimage( "bkg_secondobject.png" ) secondobject.x = display.contentwidth / 2 secondobject.y = 400 secondobject.myname = "secondobject"

physics.addbody( secondobject, "static", { friction=0.6, bounce=0.4 } )

local box1 = display.newimage( "crate.png" ) box1.x = 180; crate1.y = -50 box1.myname = "first box"

local box2 = display.newimage( "crate.png" ) box2.x = 180; crate2.y = -150 box2.myname = "second crate"

physics.addbody( box1, { density=3.0, friction=0.5, bounce=0.3 } ) physics.addbody( box2, { density=3.0, friction=0.5, bounce=0.3 } )

---- method 1: use table listeners (local method)

local function methodofcollision( self, event )      if ( event.phase == "began" )      elseif ( event.phase == "ended" )      end end 

crate1.collision = methodofcollision crate1:addeventlistener( "collision", crate1 )

crate2.collision = methodofcollision crate2:addeventlistener( "collision", crate2 )

---- method 2: use runtime listener (global method)

local function onglobalcollision( event )      if ( event.phase == "began" )      elseif ( event.phase == "ended" )      end end 

runtime:addeventlistener( "collision", onglobalcollision )

this answer may you.


Comments