- var _camera = new Class({
- /* Construct a new camera */
- initialize: function( name, pos, scale, rot, size )
- {
- this.name = (name == undefined) ? 'camera' : name;
- this.view = new view();
- this.view.pos = (pos == undefined) ? vec2(0, 0) : pos;
- this.view.rotation = (rot == undefined) ? 0.0 : rot;
- this.view.scale = (scale == undefined) ? vec2(1, 1) : scale;
- this.view.size = (size == undefined) ? vec2(phoenix.getResolution().x, phoenix.getResolution().y) : size;
- this.draggable = false;
- this.dragging = false;
- this.dragStartPos = vec2();
- this.camDragStartPos = vec2();
- this.dragEndPos = vec2();
- this.uuid = core.getuuid();
- this.zoomAmount = 1.0;
- this.zoomSpeed = 0.05;
- this.zoomable = false;
- this.dragButton = 'both';
- this.shaking = false;
- this.shakedir = 1;
- this.__defineGetter__("pos", function(){ return vec2(this.view.pos); });
- this.__defineGetter__("scale", function(){ return this.view.scale; });
- this.__defineGetter__("rotation", function(){ return this.view.rotation; });
- this.__defineGetter__("size", function(){ return this.view.size; });
- this.__defineSetter__("pos", function(val){ this.view.pos = val; });
- this.__defineSetter__("rotation", function(val){ this.view.rotation = val; });
- this.__defineSetter__("scale", function(val){ this.view.scale = val; });
- this.__defineSetter__("size", function(val){ this.view.size = val; });
- events.connect( 'onMouseDown', this.onMouseDown.bind(this));
- events.connect( 'onMouseUp', this.onMouseUp.bind(this));
- events.connect( 'onMouseMove', this.onMouseMove.bind(this));
- events.connect('onMouseWheel', this.onMouseWheel.bind(this));
- },
- activate : function() {
- this.view.activate();
- },
- onMouseWheel : function(e) {
- if(this.zoomable == true) {
- this.zoomAmount -= ( e.dir * this.zoomSpeed );
- this.zoom( this.zoomAmount );
- }
- },
- onMouseDown : function(e) {
- var d = true;
- if( this.dragButton != 'both') {
- if(this.dragButton != e.button) {
- d = false;
- }
- }
- if(this.draggable == true && d == true) {
- this.dragging = true;
- this.dragStartPos = vec2(e);
- this.camDragStartPos = this.pos;
- }
- },
- onMouseMove : function(e) {
- if(this.draggable == true) {
- if(this.dragging == true) {
- var diff = vec2(e).directionTo( this.dragStartPos );
- newpos = this.camDragStartPos.subtract( diff );
- this.pos = newpos;
- }
- }
- },
- });