Hi to all.
As I understand from "Collision detection" example, 2 bodies after creation collide without additional code, I mean box2d do it for me?
In my game one circleShape object must push another, but it passes through instead.
This is my main.lua. (My code a little bit rough)
local function is32bit()
return string.dump(is32bit):byte(9) == 4
end
if is32bit() then
require("tntvpad32")
else
require("tntvpad64")
end
require "box2d"
b2.setScale(10)
--background
local background = Bitmap.new(Texture.new("Images/background.JPG"))
background:setAnchorPoint(0.5, 0.5)
stage:addChild(background)
world = b2.World.new(0, 0)
--start create player
local startX = 10--application:getDeviceHeight()/2
local startY = 10--application:getDeviceWidth()/2
player_spr = Bitmap.new(Texture.new("Images/1-up.png"))
player_spr:setAnchorPoint(0.5, 0.5)
player_spr:setPosition(startX, startY)
local radius = player_spr:getWidth()/2
player_body = world:createBody{type = b2.KINEMATIC_BODY, position = {x = startX, y = startY}}
player_body.name = "player"
local player_shp = b2.CircleShape.new(startX, startY, radius)
player_body:createFixture{shape = player_shp, density = 1, restitution = 0.2, friction = 0.3}
stage:addChild(player_spr)
--create enemy
enemy_spr = Bitmap.new(Texture.new("Images/2-up.png"))
enemy_spr:setAnchorPoint(0.5, 0.5)
enemy_spr:setPosition(200, 200)
enemy_body = world:createBody{type = b2.DYNAMIC_BODY, position = {x = 200, y = 200}}
enemy_body.name = "enemy"
local enemy_shp = b2.CircleShape.new(200, 200, radius)
enemy_body:createFixture{shape = enemy_shp, density = 1, restitution = 0.2, friction = 0.3}
stage:addChild(enemy_spr)
--VPAD
local vPad = CTNTVirtualPad.new(stage, "Images/tntskinpad", PAD.STICK_SINGLE,PAD.BUTTONS_NONE, 20, 2)
vPad:setJoyStyle(PAD.COMPO_LEFTPAD, PAD.STYLE_CLASSIC)
vPad:setJoyAsAnalog(PAD.COMPO_LEFTPAD, false)
vPad:setHideMode(PAD.MODE_NOHIDE)
vPad:start()
vPad:addEventListener(PAD.LEFTPAD_EVENT, move, self)
function onEnterFrame()
world:step(1/60, 8, 3)
enemy_spr:setPosition(enemy_body:getPosition())
end
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
One more interesting fact: if I change in "Collision detection" example 31 line from PolygonShape.new() to CircleShape.new(x, y, 40) and comment 32 line, then one circle began to fall down into infinity=)
Thanks in advance.
Comments
And thx for tip with DebugDraw.
Likes: zvardin