/** * R3.GraphicsRuntime.Impact * @param apiGraphicsRuntimeImpact * @constructor */ R3.GraphicsRuntime.Impact = function( apiGraphicsRuntimeImpact ) { if (R3.Utils.UndefinedOrNull(apiGraphicsRuntimeImpact)) { apiGraphicsRuntimeImpact = { graphicsType : R3.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS }; } R3.API.GraphicsRuntime.Impact.call( this, apiGraphicsRuntimeImpact ); R3.GraphicsRuntime.call( this, this ); }; R3.GraphicsRuntime.Impact.prototype = Object.create(R3.GraphicsRuntime.prototype); R3.GraphicsRuntime.Impact.prototype.constructor = R3.GraphicsRuntime.Impact; /** * Create R3.GraphicsRuntime.Impact Instance * @returns {*} */ R3.GraphicsRuntime.Impact.prototype.createInstance = function() { this.instance = ig; /** * We override the game load to lookup the canvas from our r3 and not the DOM, since our canvas * does not necessarily live inside the DOM */ ig.System.inject({ init : function( canvasId, fps, width, height, scale ) { this.fps = fps; this.clock = new ig.Timer(); this.canvas = R3.EntityManager.Instance.findComponentById(canvasId).instance; this.resize( width, height, scale ); this.context = this.canvas.getContext('2d'); this.getDrawPos = ig.System.drawMode; // Automatically switch to crisp scaling when using a scale // other than 1 if( this.scale !== 1 ) { ig.System.scaleMode = ig.System.SCALE.CRISP; } ig.System.scaleMode( this.canvas, this.context ); } }); /** * We override image loading to specify that it loads from cross-origins */ ig.Image.inject({ load: function( loadCallback ) { if( this.loaded ) { if( loadCallback ) { loadCallback( this.path, true ); } return; } else if( !this.loaded && ig.ready ) { this.loadCallback = loadCallback || null; this.data = new Image(); this.data.crossOrigin = 'anonymous'; this.data.onload = this.onload.bind(this); this.data.onerror = this.onerror.bind(this); this.data.src = ig.prefix + this.path + ig.nocache; } else { ig.addResource( this ); } ig.Image.cache[this.path] = this; } }); R3.GraphicsRuntime.prototype.createInstance.call(this); }; /** * Update GraphicsRuntime.Impact Instance */ R3.GraphicsRuntime.Impact.prototype.updateInstance = function(property) { R3.GraphicsRuntime.prototype.updateInstance.call(this, property); }; /** * * @returns {R3.API.GraphicsRuntime.Impact} */ R3.GraphicsRuntime.Impact.prototype.toApiObject = function() { var apiGraphicsRuntime = R3.GraphicsRuntime.prototype.toApiObject.call(this); var apiGraphicsRuntimeImpact = new R3.API.GraphicsRuntime.Impact( apiGraphicsRuntime ); return apiGraphicsRuntimeImpact; };