2012-02-10 41 views
0

我在防止球開始移動之後遇到了麻煩,因爲它已跳到Ractangle上。矩形以恆定速度向左移動。球跟在屏幕後面。當球在矩形上跳躍時,它從矩形的下落中獲得速度。 Pleace幫助!Corona sdk阻止球的移動

下面是我的一些代碼:

--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() 

回答

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運動'?

+0

對不起,我多數民衆贊成不是我想知道的。我所做的是這樣的:\t \t - 每幀事件來移動元件 \t本地tPrevious = system.getTimer() \t本地功能移動(事件) \t \t --prevent速度/運動球 \t \t VX,VY =球:getLinearVelocity()\t \t 如果\t VX <0,則 \t \t \t球:setLinearVelocity(0,0) \t \t \t \t \t端 \t \t \t 如果\t VX> 0,那麼 \t \t \t球:setLinearVelocity(0,0) \t \t 端\t \t 端 \t - 開始一切移動 \t運行時間:的addEventListener( 「enterFrame」,移動); 它的作用是檢查每個幀的球的速度,如果它大於或小於0,它也回退0。 – Spoeken 2012-02-13 10:28:16