物理
1. 精灵
1.2. 扭力
Torque is the force that causes rotation. Use applyTorque
to non-imperatively affect the sprite's rotation.
In this example, the robot rolls slower going uphill than it does going downhill.
let robot, floor1, floor2;
function setup() {
new Canvas(500, 250);
world.gravity.y = 10;
robot = new Sprite(250, 0, 50);
robot.debug = true;
floor1 = new Sprite(400, 100, 500, 5, 's');
floor1.rotation = -10;
floor2 = new Sprite(890, 100, 500, 5, 's');
floor2.rotation = 10;
}
function draw() {
background(16);
robot.applyTorque(3);
camera.pos = robot.pos;
}