Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
bug report — Gideros Forum

bug report

alexzhengalexzheng Guru
edited December 2011 in General questions
self.body:applyLinearImpulse(-1500, -6000, self:getX(), self:getY())
has no effect on nexus s running in the player or iphone.
I works on the pc.

Comments

  • atilimatilim Maintainer
    Hi,

    Can you try this small example:
    require "box2d"
     
    local scale = b2.getScale()
     
    local world = b2.World.new(0, 10, true)
     
    local body = world:createBody({type = b2.DYNAMIC_BODY, position = {x = 160, y = 0}})
    local shape = b2.CircleShape.new(0, 0, 30)
    body:createFixture({shape = shape, density = 1})
     
    local function onEnterFrame()
    	world:step(1/60, 8, 3)
    end
     
    stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
     
    local function applyLinearImpulse()
    	local x, y = body:getPosition()
    	body:applyLinearImpulse(0, -20, x/scale, y/scale)
    end
     
    stage:addEventListener(Event.MOUSE_DOWN, applyLinearImpulse)
     
    local debugDraw = b2.DebugDraw.new()
    world:setDebugDraw(debugDraw)
    stage:addChild(debugDraw)
    In my tests, it works on PC, iOS and Android.

    Note: We realized that applyLinearImpulse and applyForce functions don't consider physics scale. It's a bug and now fixed. To overcome this issue, I get the physics scale and apply it to applyLinearImpulse.
  • alexzhengalexzheng Guru
    edited December 2011
    hi,
    I tried your code, and It works on both pc and phone device.
    finally, I got the answer.
    here is the code example reproduce the issue
    the code work well on pc but not on my nexus s.


    require "box2d"

    local scale = b2.getScale()

    local world = b2.World.new(0, 10, true)


    --add ground
    local ground = world:createBody({})

    ground.name = "ground"

    local shape = b2.EdgeShape.new(0, application:getLogicalHeight(), application:getLogicalWidth(), application:getLogicalHeight())
    ground:createFixture({shape = shape, density = 0})

    local body = world:createBody({type = b2.DYNAMIC_BODY, fixedRotation = true, position = {x = 160, y = application:getLogicalHeight()}})

    --[[
    local shape = b2.CircleShape.new(0, 0, 30)
    body:createFixture({shape = shape, density = 1})

    shape = b2.CircleShape.new(30, 0, 60)
    body:createFixture({shape = shape, density = 1})
    ]]

    local shape = b2.PolygonShape.new()
    shape:setAsBox(20, 20, 0, 0, 0)
    body:createFixture{shape = shape, density = 1}

    shape = b2.PolygonShape.new()
    shape:setAsBox(20, 10, 0, 20, 0) ------notice here, the fourth param should less than 20, or it will be hold by the ground
    body:createFixture{shape = shape, density = 1}

    local function onEnterFrame()
    world:step(1/60, 8, 3)
    end

    stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)

    local function applyLinearImpulse()
    local x, y = body:getPosition()
    print(scale)
    body:applyLinearImpulse(0, -20, x/scale, y/scale)
    end

    stage:addEventListener(Event.MOUSE_DOWN, applyLinearImpulse)

    local debugDraw = b2.DebugDraw.new()
    world:setDebugDraw(debugDraw)
    stage:addChild(debugDraw)


  • atilimatilim Maintainer
    You're right. For this case box2d at desktop and mobile behaves differently. Currently I cannot predict the main reason. It's an interesting case and I'll investigate more.
  • btw,I found setAngle is missed for body.
  • atilimatilim Maintainer
    Thank you. I've added this function.
Sign In or Register to comment.