电晕sdk防止球的x移动

时间:2012-02-10 15:47:47

标签: game-physics corona

我在防止球跳到Ractangle后开始移动时遇到了麻烦。矩形以恒定速度向左移动。球跟随屏幕。当球在矩形上跳跃时,它会从矩形的下落中获得速度。请求帮助!

以下是我的一些代码:

--make a box
local box1 = display.newRect( 600, 220, 20, 20 )
box1:setFillColor(255,255,255)
physics.addBody( box1, "static", { friction=0, bounce=0.0 } )

-- make a ball (off-screen) and position it
local ball = display.newImage( "ball.png", 20, 20 )
ball.x, ball.y = 100, 200


-- add physics to the ball
physics.addBody( ball, { density = 1.0, friction = 0, bounce = 0, radius = 19 } )

--rotate the ball
local function rotateBall()
ball.rotation = -365
transition.to( ball, { time=1000, rotation=365, onComplete=rotateBall} )

end
rotateBall()

1 个答案:

答案 0 :(得分:0)

如果我理解正确

  • 你试图使球在往复方向上无限旋转
  • 让球反弹

以下代码适用于此:

local physics=require("physics")
physics.start()

--make a box
local box1 = display.newRect( 50, 420, 150, 150 )
box1:setFillColor(255,255,255)
physics.addBody( box1, "static", { friction=0, bounce=0.0 } )

-- make a ball (off-screen) and position it
local ball = display.newImage( "scnGame_bird.png", 20, 20 )
ball.x, ball.y = 100, 200


-- add physics to the ball
physics.addBody( ball, { density = 1.0, friction = 0, bounce = 0.8, radius = 19 } )

--rotate the ball

--ball.rotation = -365
local rotateBallReverse
local function rotateBall()
    transition.to( ball, { time=1000, rotation=365, onComplete=rotateBallReverse} )
end

rotateBallReverse = function()
    transition.to( ball, { time=1000, rotation=-365, onComplete=rotateBall} )
end
rotateBall()

对于其他人来说,'阻止x运动'是什么意思?