如何使多个对象在Corona SDK左右反弹 [英] how to make multiple objects bounce around in Corona sdk

查看:226
本文介绍了如何使多个对象在Corona SDK左右反弹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我是新来电晕的SDK,想一些帮助,还可以做些球反弹在屏幕上随机的,我不知道code此所以可能有人给我一张$ C $的C,它会使球随意在屏幕上跳动与出停止或任何东西。此外,当他们打墙球会去相反的方向。

Hey guys I am new to Corona sdk and would like some help with make some balls to bounce around the screen randomly, I don't know the code for this so could someone give me a piece of code that would make the balls bounce randomly around the screen with out stopping or anything. Also when they hit the wall the ball would go in opposite direction.

感谢你帮我谢谢你一百万。

Thanks for you help I thank you a million.

我试过,但它不工作

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

有人可以帮感谢

推荐答案

您需要在您的游戏应用物理学。

You need to apply physics in your game.

试试这个样本code,它有墙壁和一球。

Try this sample code, it has walls and a ball.

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

这篇关于如何使多个对象在Corona SDK左右反弹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆