2013-07-20 33 views
0

嗨,我是Corona sdk的新手,想要一些幫助讓一些球隨機彈出屏幕,我不知道這樣的代碼,所以有人可能會給我有一段代碼可以讓球在屏幕上隨意彈跳而不會停止任何事情。當他們碰到牆時球也會朝相反的方向移動。如何使多個對象在電暈中彈跳sdk

謝謝你的幫助我感謝你一百萬。

我試過,但它不

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 

有人可以幫感謝

回答

0

你需要在你的遊戲中應用物理。

試試這個示例代碼,它有牆壁和一個球。

_W = display.contentWidth 
_H = display.contentHeight 

local physics = require("physics") 
physics.start() 
physics.setGravity(0,0) --To make everything float, zero gravity 

--Lets add walls 

local left_wall = display.newRect(0,0,1,_H) 
physics.addBody(left_wall,"static") 

local right_wall = display.newRect(_W-1,0,2,_H) 
physics.addBody(right_wall,"static") 

local top_wall = display.newRect(0,0,_W,2) 
physics.addBody(top_wall,"static") 

local bottom_wall = display.newRect(0,_H,_W,2) 
physics.addBody(bottom_wall,"static") 

local ball = display.newCircle(math.random(100,_W-100),math.random(100,_H-100),10) 
physics.addBody(ball,"dynamic",{bounce = 1, friction = 0}) 
ball:setLinearVelocity(900,1500)