Improved Oversimplified.Settings.SetCamera() by setting it to pass an options object instead of parameters.

This commit is contained in:
Robbie Antenesse 2016-04-06 12:46:36 -06:00
parent e03607b581
commit 760bb5c9b1
1 changed files with 12 additions and 22 deletions

View File

@ -27,35 +27,25 @@ It is important that this is done first at the time the game is loaded because t
Be sure that the objectToFollow has already been created in the current room. Can be referenced with a variable. Be sure that the objectToFollow has already been created in the current room. Can be referenced with a variable.
objectToFollow, hBorder, and vBorder are optional arguments, but if you want to set hBorder and vBorder, there must be an objectToFollow. objectToFollow, hBorder, and vBorder are optional arguments, but if you want to set hBorder and vBorder, there must be an objectToFollow.
*/ */
Oversimplified.Settings.SetCamera = function (width, height, objectToFollow, hBorder, vBorder) { Oversimplified.Settings.SetCamera = function (options) {
hBorder = typeof hBorder !== 'undefined' ? hBorder : Oversimplified.camera.hBorder; Oversimplified.camera.width = typeof options.width !== 'undefined' ? options.width : Oversimplified.camera.width;
vBorder = typeof vBorder !== 'undefined' ? vBorder : Oversimplified.camera.vBorder; Oversimplified.camera.height = typeof options.height !== 'undefined' ? options.height : Oversimplified.camera.height;
Oversimplified.SetCanvasToCameraSize();
Oversimplified.camera.x = typeof options.x !== 'undefined' ? options.x : Oversimplified.camera.x;
Oversimplified.camera.y = typeof options.y !== 'undefined' ? options.y : Oversimplified.camera.y;
if (typeof width !== 'undefined') { if (typeof options.objectToFollow !== 'undefined') {
Oversimplified.camera.width = width; if (options.objectToFollow.name) {
} else { Oversimplified.camera.Follow(options.objectToFollow);
if (Oversimplified.DEBUG.showMessages) console.log("You must specify a width in function Oversimplified.Settings.SetCamera()");
return false;
}
if (typeof height !== 'undefined') {
Oversimplified.camera.height = height;
} else {
if (Oversimplified.DEBUG.showMessages) console.log("You must specify a height in function Oversimplified.Settings.SetCamera()");
return false;
}
if (typeof objectToFollow !== 'undefined') {
if (objectToFollow.name) {
Oversimplified.camera.Follow(objectToFollow);
} else { } else {
if (Oversimplified.DEBUG.showMessages) console.log("Oversimplified.Settings.SetCamera()'s objectToFollow argument must be a Oversimplified.GameObject."); if (Oversimplified.DEBUG.showMessages) console.log("Oversimplified.Settings.SetCamera()'s objectToFollow argument must be a Oversimplified.GameObject.");
} }
} }
Oversimplified.camera.hBorder = hBorder; Oversimplified.camera.hBorder = (typeof options.hBorder !== 'undefined') ? options.hBorder : Oversimplified.camera.hBorder;
Oversimplified.camera.vBorder = vBorder; Oversimplified.camera.vBorder = (typeof options.vBorder !== 'undefined') ? options.vBorder : Oversimplified.camera.vBorder;
Oversimplified.SetCanvasToCameraSize();
} }
// Convenient alias for Settings. // Convenient alias for Settings.
Oversimplified.S = Oversimplified.Settings; Oversimplified.S = Oversimplified.Settings;