1

嘿伙计们,我想在屏幕上放两个或更多的乒乓球,让它们弹起来。我希望乒乓球游戏与传统的乒乓球风格游戏有点不同,让球拍收集球并且球可以在屏幕周围弹跳我不希望球疯狂弹跳它希望它让球弹跳在一个缓慢而漂亮的后殿周围。我试图让墙将球推向相反的方向。你们能帮忙吗谢谢

这是代码

 function update(event)
    -- Ball Movement
    ball.x = ball.x + xSpeed
    ball.y = ball.y + ySpeed


if(ball.x < 0) then ball.x = ball.x + 3 xSpeed = -xSpeed end--Left
if((ball.x + ball.width) > display.contentWidth) then ball.x = ball.x - 3 xSpeed = -xSpeed end--Right
if(ball.y < 0) then ySpeed = -ySpeed end--Up
--if(ball.y > 0) then ySpeed = ySpeed end--Up

if((ball.y + ball.width) > display.contentWidth) then ball.y = ball.x + 300 ySpeed = -20
 end--Right

end



function bounce(e)
    ySpeed = -5
    -- Paddle Collision, check the which side of the paddle the ball hits, left, right
    if((ball.x + ball.width * 0.5) < paddle.x) then
        xSpeed = -5
    elseif((ball.x + ball.width * 0.5) >= paddle.x) then
        xSpeed = 5
    end
end


paddle:addEventListener('collision', bounce)    

Runtime:addEventListener('enterFrame', update)

这段代码对我不起作用,谁能给我一些有效的代码。此代码的另一个问题是球会粘在墙上。我想让多个球在撞到墙上时反弹并朝相反的方向移动。我来自游戏沙拉中的游戏沙拉编程,当球与墙壁发生胶体时,我会使用改变速度,但在电晕中它更难,我无法弄清楚我被卡住了。我是 Corona 的新手,我阅读了论坛和教程,但没有运气。

我很想得到一些帮助,谢谢... :)

4

1 回答 1

1

It's hard and inefficient to achieve that in this way. You should use physics libraries functions for this kind of purposes. You should create physic objects with { friction = 0 } property and then you can change ball's speed with density part. After creating objects you should use applyForce functions to start movements of balls.

于 2013-07-24T00:07:29.610 回答