QICI engine currently uses Arcade as physical system, and made some optimization for better performance.
Enable Arcade Physics
Arcade Physics has been integrated in QICI editor as a built-in plugin. To enable the plugin, just open PluginManager panel through menu Plugins->PluginManager, and check the Arcade Physics option.
Adding a RigidBody component to an object will put its motion under the control of Arcade physics system, such as gravity, collision, drag etc.
Notice: Only UIImage and Sprite can attach RigidBody component currently.
Notice: We made some restrictions in the use of RigidBody, just comply to these two points:
- Rotation set to rigidbody and it's parent node is not allowed.
- Movement applied to rigidbody's parent node is not allowed.
The mass of the rigibody, when two rigidbodies collide their mass is used in the calculation to determine the exchange of velocity.
var rigidbody = self.sprite1.getScript("qc.arcade.RigidBody"); // set mass of the rigidbody rigidbody1.mass = 100;
Whether allow the physics system to move this rigidbody.
// allow physics system to control the position of rigidbody rigidbody.moves = true;
Whether this rigidbody will not receive any impacts from other rigidbodies.
rigidbody.immovable = true;
Should the rigidbody collide with the world bounds? A RigidBody can be set to collide against the World bounds automatically and rebound back into the world if this is set to true. Otherwise it will leave the World.
rigidbody.collideWorldBounds = true;
Allow this rigidbody to be influenced by gravity?
The local gravity setting of the rigidbody. Defaults to x: 0, y: 0
// set influenced by gravity rigidbody.allowGravity = true; // set local gravity to (x:0, y:200) rigidbody.gravity.x = 0; rigidbody.gravity.y = 200;
The elasticity of the rigidbody when colliding, bounce.x/y = 1 means full rebound, bounce.x/y = 0.5 means 50% rebound velocity.
// 50% rebound when colliding rigidbody.bounce.x = 0.5; rigidbody.bounce.y = 0.5;
Velocity of the rigidbody.
The rate of change of the velocity.
The drag applied to the motion of the rigidbody.
rigidbody.velocity.x = 100; rigidbody.velocity.y = 50; rigidbody.acceleration.x = 10; rigidbody.acceleration.y = 5; rigidbody.drag.x = 5; rigidbody.drag.y = 5;
Allow this rigidbody to be rotated?
The rotation speed of the rigidbody. Measured in radians per second.
The rate of change of the angular velocity.
The drag applied to the rotation of the rigidbody.
// allow the rigidbody to rotate rigidbody.allowRotation = true; // set angular speed rigidbody.angularVelocity = 20; // set angular acceleration when rotation rigidbody.angularAcceleration = 5; // set drag when rotation rigidbody.angularDrag = 1;
Which directions collision is processed for this rigidbody.
rigidbody.checkCollision.up = true; rigidbody.checkCollision.down = true; rigidbody.checkCollision.left = true; rigidbody.checkCollision.right = true;
Number of discrete points for continuous collision detection, used to prevent fast moving objects from passing through other objects without detecting collisions. Higher ccdIterations value means better physical collision, however the greater performance overhead.