require "box2d"
ice = Core.class(Sprite)
function ice:init(world, x, y, scale, xScale, yScale, strength)
local ice = Bitmap.new(Texture.new("images/ice.png"))
ice:setScale(scale) --
ice:setScaleX(xScale)
ice:setScaleY(yScale)
ice:setAnchorPoint(0.5,0.5)
self:addChild(ice)
--create box2d physical object
local body = world:createBody{type = b2.DYNAMIC_BODY}
body:setPosition(x, y)
body:setAngle(ice:getRotation() * math.pi/180)
local poly = b2.PolygonShape.new()
poly:setAsBox(ice:getWidth()/2, ice:getHeight()/2)
body:createFixture{shape = poly, density = 0.5,
friction = 0.01, restitution = 0.3}
self.body = body
self.body.type = "ice"
self.body.strength = strength
ice.body.bitmap = ice --
self.strength = 100 --
end |
and in my level 1 lua, in an on begin contact function I have this
if bodyA.strength == 90 then
print("crack image")
-- Replace image with "cracked" version of image
bodyA.bitmap:setTexture(Texture.new("images/crackedice.png", true))
elseif bodyA.strength == 80 then
bodyA.bitmap:setTexture(Texture.new("images/crackedice2.png", true))
elseif bodyA.strength == 70 then
bodyA.bitmap:setTexture(Texture.new("images/crackedice3.png", true))
end |
However, when I hit the ice, the image does not change. This logic worked, however once I implemented scene manager it stopped working. Any ideas?
Thanks.
Comments
if bodyA is an instance of ice I'd say it won't "break" since its strenght is 100, and this value it's not included in your if ..then statements.
Note: And you can highlight your code in forum as below, just fyi