Phaser.Utils.Debug = function (game){ this.game = game; this.sprite = null ; this.canvas = null ; this.baseTexture = null ; this.texture = null ; this.textureFrame = null ; this.context = null ; this.font = '14px Courier'; this.columnWidth = 100; this.lineHeight = 16; this.renderShadow = true ; this.currentX = 0; this.currentY = 0; this.currentAlpha = 1; this.dirty = false ; } ; Phaser.Utils.Debug.prototype = { boot: function (){ if (this.game.renderType === Phaser.CANVAS) { this.context = this.game.context; } else { this.canvas = Phaser.Canvas.create(this.game.width, this.game.height, '', true ); this.context = this.canvas.getContext('2d'); this.baseTexture = new PIXI.BaseTexture(this.canvas); this.texture = new PIXI.Texture(this.baseTexture); this.textureFrame = new Phaser.Frame(0, 0, 0, this.game.width, this.game.height, 'debug', this.game.rnd.uuid()); this.sprite = this.game.make.image(0, 0, this.texture, this.textureFrame); this.game.stage.addChild(this.sprite); } } , preUpdate: function (){ if (this.dirty && this.sprite) { this.context.clearRect(0, 0, this.game.width, this.game.height); this.dirty = false ; } } , start: function (x, y, color, columnWidth){ if (typeof x !== 'number') { x = 0; } if (typeof y !== 'number') { y = 0; } color = color || 'rgb(255,255,255)'; if (typeof columnWidth === 'undefined') { columnWidth = 0; } this.currentX = x; this.currentY = y; this.currentColor = color; this.currentAlpha = this.context.globalAlpha; this.columnWidth = columnWidth; if (this.sprite) { this.dirty = true ; } this.context.save(); this.context.setTransform(1, 0, 0, 1, 0, 0); this.context.strokeStyle = color; this.context.fillStyle = color; this.context.font = this.font; this.context.globalAlpha = 1; } , stop: function (){ this.context.restore(); this.context.globalAlpha = this.currentAlpha; if (this.sprite) { PIXI.updateWebGLTexture(this.baseTexture, this.game.renderer.gl); } } , line: function (){ var x = this.currentX; for (var i = 0; i < _AN_Read_length('length', arguments); i++ ){ if (this.renderShadow) { this.context.fillStyle = 'rgb(0,0,0)'; this.context.fillText(arguments[i], x + 1, this.currentY + 1); this.context.fillStyle = this.currentColor; } this.context.fillText(arguments[i], x, this.currentY); x += this.columnWidth; } this.currentY += this.lineHeight; } , soundInfo: function (sound, x, y, color){ this.start(x, y, color); this.line('Sound: ' + sound.key + ' Locked: ' + sound.game.sound.touchLocked); this.line('Is Ready?: ' + this.game.cache.isSoundReady(sound.key) + ' Pending Playback: ' + sound.pendingPlayback); this.line('Decoded: ' + sound.isDecoded + ' Decoding: ' + sound.isDecoding); this.line('Total Duration: ' + sound.totalDuration + ' Playing: ' + sound.isPlaying); this.line('Time: ' + sound.currentTime); this.line('Volume: ' + sound.volume + ' Muted: ' + sound.mute); this.line('WebAudio: ' + sound.usingWebAudio + ' Audio: ' + sound.usingAudioTag); if (sound.currentMarker !== '') { this.line('Marker: ' + sound.currentMarker + ' Duration: ' + sound.duration + ' (ms: ' + sound.durationMS + ')'); this.line('Start: ' + sound.markers[sound.currentMarker].start + ' Stop: ' + sound.markers[sound.currentMarker].stop); this.line('Position: ' + sound.position); } this.stop(); } , cameraInfo: function (camera, x, y, color){ this.start(x, y, color); this.line('Camera (' + camera.width + ' x ' + camera.height + ')'); this.line('X: ' + camera.x + ' Y: ' + camera.y); this.line('Bounds x: ' + camera.bounds.x + ' Y: ' + camera.bounds.y + ' w: ' + camera.bounds.width + ' h: ' + camera.bounds.height); this.line('View x: ' + camera.view.x + ' Y: ' + camera.view.y + ' w: ' + camera.view.width + ' h: ' + camera.view.height); this.stop(); } , timer: function (timer, x, y, color){ this.start(x, y, color); this.line('Timer (running: ' + timer.running + ' expired: ' + timer.expired + ')'); this.line('Next Tick: ' + timer.next + ' Duration: ' + timer.duration); this.line('Paused: ' + timer.paused + ' Length: ' + _AN_Read_length('length', timer)); this.stop(); } , pointer: function (pointer, hideIfUp, downColor, upColor, color){ if (pointer == null ) { return ; } if (typeof hideIfUp === 'undefined') { hideIfUp = false ; } downColor = downColor || 'rgba(0,255,0,0.5)'; upColor = upColor || 'rgba(255,0,0,0.5)'; if (hideIfUp === true && pointer.isUp === true ) { return ; } this.start(pointer.x, pointer.y - 100, color); this.context.beginPath(); this.context.arc(pointer.x, pointer.y, pointer.circle.radius, 0, Math.PI * 2); if (pointer.active) { this.context.fillStyle = downColor; } else { this.context.fillStyle = upColor; } this.context.fill(); this.context.closePath(); this.context.beginPath(); this.context.moveTo(pointer.positionDown.x, pointer.positionDown.y); this.context.lineTo(pointer.position.x, pointer.position.y); this.context.lineWidth = 2; this.context.stroke(); this.context.closePath(); this.line('ID: ' + pointer.id + " Active: " + pointer.active); this.line('World X: ' + pointer.worldX + " World Y: " + pointer.worldY); this.line('Screen X: ' + pointer.x + " Screen Y: " + pointer.y); this.line('Duration: ' + pointer.duration + " ms"); this.line('is Down: ' + pointer.isDown + " is Up: " + pointer.isUp); this.stop(); } , spriteInputInfo: function (sprite, x, y, color){ this.start(x, y, color); this.line('Sprite Input: (' + sprite.width + ' x ' + sprite.height + ')'); this.line('x: ' + sprite.input.pointerX().toFixed(1) + ' y: ' + sprite.input.pointerY().toFixed(1)); this.line('over: ' + sprite.input.pointerOver() + ' duration: ' + sprite.input.overDuration().toFixed(0)); this.line('down: ' + sprite.input.pointerDown() + ' duration: ' + sprite.input.downDuration().toFixed(0)); this.line('just over: ' + sprite.input.justOver() + ' just out: ' + sprite.input.justOut()); this.stop(); } , key: function (key, x, y, color){ this.start(x, y, color, 150); this.line('Key:', key.keyCode, 'isDown:', key.isDown); this.line('justPressed:', key.justPressed(), 'justReleased:', key.justReleased()); this.line('Time Down:', key.timeDown.toFixed(0), 'duration:', key.duration.toFixed(0)); this.stop(); } , inputInfo: function (x, y, color){ this.start(x, y, color); this.line('Input'); this.line('X: ' + this.game.input.x + ' Y: ' + this.game.input.y); this.line('World X: ' + this.game.input.worldX + ' World Y: ' + this.game.input.worldY); this.line('Scale X: ' + this.game.input.scale.x.toFixed(1) + ' Scale Y: ' + this.game.input.scale.x.toFixed(1)); this.line('Screen X: ' + this.game.input.activePointer.screenX + ' Screen Y: ' + this.game.input.activePointer.screenY); this.stop(); } , spriteBounds: function (sprite, color, filled){ var bounds = sprite.getBounds(); bounds.x += this.game.camera.x; bounds.y += this.game.camera.y; this.rectangle(bounds, color, filled); } , spriteInfo: function (sprite, x, y, color){ this.start(x, y, color); this.line('Sprite: ' + ' (' + sprite.width + ' x ' + sprite.height + ') anchor: ' + sprite.anchor.x + ' x ' + sprite.anchor.y); this.line('x: ' + sprite.x.toFixed(1) + ' y: ' + sprite.y.toFixed(1)); this.line('angle: ' + sprite.angle.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1)); this.line('visible: ' + sprite.visible + ' in camera: ' + sprite.inCamera); this.stop(); } , spriteCoords: function (sprite, x, y, color){ this.start(x, y, color, 100); if (sprite.name) { this.line(sprite.name); } this.line('x:', sprite.x.toFixed(2), 'y:', sprite.y.toFixed(2)); this.line('pos x:', sprite.position.x.toFixed(2), 'pos y:', sprite.position.y.toFixed(2)); this.line('world x:', sprite.world.x.toFixed(2), 'world y:', sprite.world.y.toFixed(2)); this.stop(); } , lineInfo: function (line, x, y, color){ this.start(x, y, color, 80); this.line('start.x:', line.start.x.toFixed(2), 'start.y:', line.start.y.toFixed(2)); this.line('end.x:', line.end.x.toFixed(2), 'end.y:', line.end.y.toFixed(2)); this.line('length:', _AN_Read_length('length', line).toFixed(2), 'angle:', line.angle); this.stop(); } , pixel: function (x, y, color, size){ size = size || 2; this.start(); this.context.fillStyle = color; this.context.fillRect(x, y, size, size); this.stop(); } , geom: function (object, color, filled, forceType){ if (typeof filled === 'undefined') { filled = true ; } if (typeof forceType === 'undefined') { forceType = 0; } color = color || 'rgba(0,255,0,0.4)'; this.start(); this.context.fillStyle = color; this.context.strokeStyle = color; if (object instanceof Phaser.Rectangle || forceType === 1) { if (filled) { this.context.fillRect(object.x - this.game.camera.x, object.y - this.game.camera.y, object.width, object.height); } else { this.context.strokeRect(object.x - this.game.camera.x, object.y - this.game.camera.y, object.width, object.height); } } else if (object instanceof Phaser.Circle || forceType === 2) { this.context.beginPath(); this.context.arc(object.x - this.game.camera.x, object.y - this.game.camera.y, object.radius, 0, Math.PI * 2, false ); this.context.closePath(); if (filled) { this.context.fill(); } else { this.context.stroke(); } } else if (object instanceof Phaser.Point || forceType === 3) { this.context.fillRect(object.x - this.game.camera.x, object.y - this.game.camera.y, 4, 4); } else if (object instanceof Phaser.Line || forceType === 4) { this.context.lineWidth = 1; this.context.beginPath(); this.context.moveTo((object.start.x + 0.5) - this.game.camera.x, (object.start.y + 0.5) - this.game.camera.y); this.context.lineTo((object.end.x + 0.5) - this.game.camera.x, (object.end.y + 0.5) - this.game.camera.y); this.context.closePath(); this.context.stroke(); } this.stop(); } , rectangle: function (object, color, filled){ if (typeof filled === 'undefined') { filled = true ; } color = color || 'rgba(0, 255, 0, 0.4)'; this.start(); if (filled) { this.context.fillStyle = color; this.context.fillRect(object.x - this.game.camera.x, object.y - this.game.camera.y, object.width, object.height); } else { this.context.strokeStyle = color; this.context.strokeRect(object.x - this.game.camera.x, object.y - this.game.camera.y, object.width, object.height); } this.stop(); } , text: function (text, x, y, color, font){ color = color || 'rgb(255,255,255)'; font = font || '16px Courier'; this.start(); this.context.font = font; if (this.renderShadow) { this.context.fillStyle = 'rgb(0,0,0)'; this.context.fillText(text, x + 1, y + 1); } this.context.fillStyle = color; this.context.fillText(text, x, y); this.stop(); } , quadTree: function (quadtree, color){ color = color || 'rgba(255,0,0,0.3)'; this.start(); var bounds = quadtree.bounds; if (_AN_Read_length('length', quadtree.nodes) === 0) { this.context.strokeStyle = color; this.context.strokeRect(bounds.x, bounds.y, bounds.width, bounds.height); this.text('size: ' + _AN_Read_length('length', quadtree.objects), bounds.x + 4, bounds.y + 16, 'rgb(0,200,0)', '12px Courier'); this.context.strokeStyle = 'rgb(0,255,0)'; for (var i = 0; i < _AN_Read_length('length', quadtree.objects); i++ ){ this.context.strokeRect(quadtree.objects[i].x, quadtree.objects[i].y, quadtree.objects[i].width, quadtree.objects[i].height); } } else { for (var i = 0; i < _AN_Read_length('length', quadtree.nodes); i++ ){ this.quadTree(quadtree.nodes[i]); } } this.stop(); } , body: function (sprite, color, filled){ if (sprite.body) { if (sprite.body.type === Phaser.Physics.ARCADE) { this.start(); Phaser.Physics.Arcade.Body.render(this.context, sprite.body, color, filled); this.stop(); } else if (sprite.body.type === Phaser.Physics.NINJA) { this.start(); Phaser.Physics.Ninja.Body.render(this.context, sprite.body, color, filled); this.stop(); } } } , bodyInfo: function (sprite, x, y, color){ if (sprite.body) { if (sprite.body.type === Phaser.Physics.ARCADE) { this.start(x, y, color, 210); Phaser.Physics.Arcade.Body.renderBodyInfo(this, sprite.body); this.stop(); } } } } ; Phaser.Utils.Debug.prototype.constructor = Phaser.Utils.Debug;