Hello,
In my continuing struggle to learn both MTE and Corona SDK, I am trying to mimic the old style Super Mario Brothers.
I’ve got movement where I am happy with it and now I am ready to tackle breakable blocks.
The goal is simple:
When the player collides with a block that is tagged in Tiled as “breakable”, the block will bounce up a little (on Y axis only) and return back to it’s resting position.
Right now, the easiest way to do it that I can think of is to have each breakable block be a kinematic body. When the collision occurs between player and breakable block, setLinearVelocity will be called moving it up and then a timer with a small delay will fire reversing the linear velocity.
An invisible wall (newRect) will be created at Runtime under each block and set as static. This will return the breakable blocks to their original positions.
However, I am encountering a weird issue.
Box2D shows the physics bodies for the invisible wall, breakable blocks, and my character all correctly.
If I remove the invisible walls (comment them out), jumping and movement work just fine.
If I keep the walls in place, it only lets me jump about half the distance I’d expect.
So, to debug, I set the invisible walls as dynamic. Much to my surprise, the wall directly on top of the player came to rest well above my character (see screenshot) even though the bodies are correct.
Any ideas?
local myBreakableBlocks = {} local onBreakableProperty = function(event) myBreakableBlocks[#myBreakableBlocks + 1] = event.target:makeSprite() myBreakableBlocks[#myBreakableBlocks].bodyType = "kinematic" myBreakableBlocks[#myBreakableBlocks].name = "breakable" mte.updateTile({locX = event.target.locX, locY = event.target.locY, tile = 0, layer = event.target.layer}) local bottom = display.newRect(myBreakableBlocks[#myBreakableBlocks].levelPosX - (myBreakableBlocks[#myBreakableBlocks].width/2), myBreakableBlocks[#myBreakableBlocks].levelPosY + (myBreakableBlocks[#myBreakableBlocks].height / 2), myBreakableBlocks[#myBreakableBlocks].width, 5) bottom.isVisible = false mte.physics.addBody(bottom, "dynamic") end mte.addPropertyListener("breakable", onBreakableProperty)