Hi guys,
i have implemented a code for destroy the box after collision as seen below.
But i need to put another crack phase before the termination of box.
In new scenario;
Firstly, the object hits the vaulting box. Box and the object cracks. (That’s what i can’t implement as a new cracked version of box or object.)
Secondly, when The cracked box or object takes another hit. It should be destroyed.
I need your directions to make this happen. Can anyone help? Thanks in advance.
local onVaultingboxPostCollision = function( self, event )
if event.force \> 1.5 and self.isHit == false then
audio.play( monsterPoofSound )
self.isHit = true
print( "Box destroyed! Force: " .. event.force )
self.isVisible = false
self.isBodyActive = false
-- Poof code below --
if poofTween then transition.cancel( poofTween ); end
greenPoof.x = self.x; greenPoof.y = self.y
greenPoof.alpha = 0
greenPoof.isVisible = true
local fadePoof = function()
transition.to( greenPoof, { time=500, alpha=0 } )
end
poofTween = transition.to( greenPoof, { time=50, alpha=1.0, onComplete=fadePoof } )
self.parent:remove( self )
self = nil
local newScore = gameScore + mCeil(5000 \* event.force)
setScore( newScore )
end
end
--Vaulting Box 2
local vaultingbox2 = display.newImageRect( "vaultingbox2.png", 55, 45)
vaultingbox2.x = 613.5; vaultingbox2.y = 224.5
vaultingbox2.xScale = 1
vaultingbox2.yScale = 1
vaultingbox2.myName = "wood"
vaultingbox2.isHit = false
vaultingbox2.postCollision = onVaultingboxPostCollision
vaultingbox2:addEventListener( "postCollision", vaultingbox2 )
physics.addBody( vaultingbox2, "dynamic", {density = woodDensity, bounce = 0.2, friction = 0.3, shape=vaultingbox2Shape} )
levelGroup:insert( vaultingbox2 )
[import]uid: 34788 topic_id: 9630 reply_id: 309630[/import]