Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Does shape:set work? — Gideros Forum

Does shape:set work?

MikeHartMikeHart Guru
edited February 2012 in General questions
During a tween that sizes a sprite, I want to set the position of the sprite's body and also try to set the shape of the body according to the current scale factor of the sprite. The shape is a circular one.

I do it like this:
local oncShotTweenChange = function(tween)
	local target = tween.target
	local body = target.xBody
 
	local x,y = target:getPosition()
	local scale = target:getScaleX()
	--print("scale:"..scale)
 
	--Set the position of the body
	body:setPosition(x,y)
 
	--Determine the shape of the body and set its radius.
	local shape = body.xShape
	shape:set(0,0,6*scale)
 
end
Doing a debugdraw doesn't change the size of the shape. What am I doing wrong?

Comments

  • atilimatilim Maintainer
    edited February 2012
    Hi,

    box2d manual says that:
    "Box2D does not keep a reference to the shape. It clones the data into a new b2Shape object." Therefore, you cannot access and change the internal cloned shape data.

    One possibility can be destroying and recreating the fixture with the new shape :-?
  • So the set command does not work? Or what is it for?
  • atilimatilim Maintainer
    edited February 2012
    It can be used to create more than one fixture with the same shape like:
    local edge = b2.EdgeShape.new()
     
    edge:set(....)
    body:createFixture({shape = edge})
    edge:set(...)
    body:createFixture({shape = edge})
    edge:set(...)
    body:createFixture({shape = edge})
    edge:set(...)
    body:createFixture({shape = edge})
     
    -- and so on
    (not a must-have feature)
Sign In or Register to comment.