Hello everybody. In certain situations during game, I'd like to get the shape (polygon vertices) of fixture. There's no such method in LiquidFun library. Any suggestions?
In my case self.shape is a polygon. The problem is that I'm not sure if self.shape follows body rotation in game loop. Even if it does, I would need polygon in form of {x1,y1,x2,y2....xn,yn}, but type(self.shape) returns 'userdata' - probably kind of C pointer. Useless for me. thanxx anyway
I believe the shape follows the rotation of the body. A couple of things you can try: - try to store your {x1,y1,x2,y2....xn,yn} is a self.table so you can access it - or you could try unpack()
stage:addEventListener(Event.ENTER_FRAME, function()-- edit the step values if required. These are good defaults!
world:step(1/60, 8, 3)
ball:setPosition(ball.body:getPosition())
ball:setRotation(math.rad(ball.body:getAngle()))-- ROTATION HEREend)
ok, let's assume the shape is updated according to body rotation/position. But still I don't know the data structure of shape ball.poly for conversion to {x1,y1,x2,y2...} later in onEnterFrame loop.
Comments
thanxx anyway
A couple of things you can try:
- try to store your {x1,y1,x2,y2....xn,yn} is a self.table so you can access it
- or you could try unpack()
But still I don't know the data structure of shape ball.poly for conversion to {x1,y1,x2,y2...} later in onEnterFrame loop.
local poly = {-20,-20, 40,-20, 50,20, -25,30}
ball.body = world:createBody{type = b2.DYNAMIC_BODY}
ball.poly = b2.PolygonShape.new()
ball.poly:set(unpack(poly))
ball.fixture = ball.body:createFixture{shape = ball.poly, density = 1.0, friction = 0.1, restitution = 0.2}
...anyway, I already did it in other way.
Likes: MoKaLux