[英]CORONA : physics, object changes its (x,y)
I've added my object ( a ball) and when it collide with an object the ball start changing it x an y position even if I apply force just on it y position (up and down) 我已经添加了一个对象(一个球),当它与一个对象碰撞时,即使我只是在它的y位置(上下)上施加了力,球也开始将其更改为y位置
local physics = require "physics"
physics.start()
--physics.setContinuous( false )
ball = display.newImage("ball.png") --MAIN OBJECT
ball.x = 100; ball.y = 100
physics.addBody(ball, "dynamic", {density=.05, bounce=0.1, friction=.2, radius=12})
screenGroup:insert(ball)
ball.myName = "ball"
function activateBall(self, event) --APPLY FORCE FUNCTION
self:applyForce(0, -1.5, self.x, self.y)
end
function onCollision (event) --BALL COLLIDES WITH JUST THIS OBSTACLES
if (event.object1.myName == "obst1") or (event.object1.myName == "obst2") then
storyboard.gotoScene("restart", "fade", 400)
audio.stop()
end
I want the ball to keep it position without starting to move randomly . 我希望球保持它的位置而不开始随机移动。
A quick solution would be to simply reset the balls x position in every frame. 一种快速的解决方案是简单地重置每帧中的x球位置。
local ballListener = function( event )
ball.x = 100
end
Runtime:addEventListener( "enterFrame", ballListener )
Maybe before applyForce()
you can setLinearVelocity()
for x value to 0, for y to the value you getLinearVelocity()
for y value, and then applyForce()
you want to. 也许在
applyForce()
之前,可以将x值的setLinearVelocity()
为0,将y的值getLinearVelocity()
为getLinearVelocity()
的值设置为y,然后再设置applyForce()
。 Probably that resets the x velocity you could have after collision. 可能会重置碰撞后的x速度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.