Smooth camera movement
Move the camera smoothly to a target position
Here we move the camera towards a target position, with constant speed. The camera has 3 coordinates: change x and y to pan, change z to zoom. When the wade app is started, the camera is at {x:0, y:0, z: 1}
App = function()
{
var zoomIn = true;
this.load = function()
{
wade.loadImage('/snippets/samples/back.jpg');
wade.loadImage('/snippets/samples/cc_logo.png');
};
this.init = function()
{
// create 2 objects and add them to the scene
var background = new SceneObject(new Sprite('/snippets/samples/back.jpg'));
wade.addSceneObject(background);
var logo = new SceneObject(new Sprite('/snippets/samples/cc_logo.png'));
wade.addSceneObject(logo);
// tell wade to move the camera again when it's finished moving
this.onCameraMoveComplete = this.moveCamera;
// start moving the camera
this.moveCamera();
};
this.moveCamera = function()
{
// choose a target
var target = zoomIn? {x: (Math.random() - 0.5) * 200, y: (Math.random() - 0.5) * 150, z: Math.random() * 5} : {x:0, y: 0, z: 1};
// move camera towards target
wade.moveCamera(target, 100);
};
};
Your code was executed successfully!