object:setLinearVelocity()

类型 函数
对象 刚体
physics.*
返回值
修订版本 版本 2024.3703
关键词 刚体, setLinearVelocity
另请参阅 object:getLinearVelocity()

概述

此函数接受刚体的线性速度的 **x** 和 **y** 分量,单位为像素/秒。

语法

object:setLinearVelocity( xVelocity, yVelocity )
xVelocity, yVelocity (必填)

数字. 分别为 **x** 和 **y** 方向上的速度值。

示例

-- Create a rectangle
local myRect = display.newRect( 0, 0, 100, 100 )

-- Add a body to the rectangle
physics.addBody( myRect, "dynamic" )

-- Set the linear velocity
myRect:setLinearVelocity( 10, 4 )