├── .eslintrc.yml ├── .gitignore ├── .npmignore ├── README.md ├── app ├── assets │ ├── index.html │ ├── invaders │ │ ├── NOLICENSE │ │ ├── bullet.png │ │ ├── enemy-bullet.png │ │ ├── explode.png │ │ ├── invader.png │ │ ├── invader32x32x4.png │ │ ├── player.png │ │ └── starfield.png │ ├── screenshot1.png │ └── screenshot2.png ├── example.coffee └── plugin.coffee ├── bower.json ├── brunch-config.coffee ├── dist ├── .gitignore ├── SceneGraph.js ├── example.js ├── example │ └── vendor.js ├── index.html ├── invaders │ ├── NOLICENSE │ ├── bullet.png │ ├── enemy-bullet.png │ ├── explode.png │ ├── invader.png │ ├── invader32x32x4.png │ ├── player.png │ └── starfield.png ├── screenshot1.png └── screenshot2.png └── package.json /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | env: 2 | browser: yes 3 | extends: 'eslint:recommended' 4 | globals: 5 | Phaser: no 6 | rules: 7 | indent: 8 | - 'off' 9 | linebreak-style: 10 | - error 11 | - unix 12 | no-console: 13 | - error 14 | - allow: 15 | - group 16 | - groupCollapsed 17 | - groupEnd 18 | - log 19 | no-shadow: 20 | - error 21 | no-unused-vars: 22 | - error 23 | quotes: 24 | - error 25 | - double 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Numerous always-ignore extensions 2 | *.diff 3 | *.err 4 | *.orig 5 | *.log 6 | *.rej 7 | *.swo 8 | *.swp 9 | *.vi 10 | *~ 11 | *.sass-cache 12 | 13 | # OS or Editor folders 14 | .DS_Store 15 | .cache 16 | .project 17 | .settings 18 | .tmproj 19 | nbproject 20 | Thumbs.db 21 | 22 | # NPM packages folder. 23 | node_modules/ 24 | 25 | # Brunch folder for temporary files. 26 | tmp/ 27 | 28 | # Bower stuff. 29 | bower_components/ 30 | 31 | version.json 32 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | *.coffee 2 | *.html 3 | *.png 4 | app/ 5 | bower.json 6 | bower_components/ 7 | dist/invaders 8 | example.js 9 | version.json 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Prints the display tree. [Demo](https://samme.github.io/phaser-plugin-scene-graph/) 2 | 3 | Install 4 | ------- 5 | 6 | If not using `npm` or `bower`, add [SceneGraph.js](dist/SceneGraph.js) after phaser.js. 7 | 8 | Use 👾 9 | --- 10 | 11 | ```javascript 12 | game.plugins.add(Phaser.Plugin.SceneGraph); 13 | ``` 14 | 15 | Debug Canvas 16 | ------------ 17 | 18 | ![Print on the debug canvas](https://samme.github.io/phaser-plugin-scene-graph/screenshot1.png) 19 | 20 | ```javascript 21 | game.debug.renderGraph(obj, x, y, font, lineHeight); 22 | ``` 23 | 24 | Console 25 | ------- 26 | 27 | ![Print to the browser console](https://samme.github.io/phaser-plugin-scene-graph/screenshot2.png) 28 | 29 | ```javascript 30 | game.debug.graph() // everything; or 31 | 32 | game.debug.graph(obj) // 1 object & descendants 33 | 34 | game.debug.graph(obj, { // options: 35 | collapse: true, 36 | filter: null, // function (obj) -> true | false 37 | map: null, // function (obj) -> "description" 38 | skipDead: false, 39 | skipNonexisting: false 40 | }); 41 | ``` 42 | 43 | Configure (optional) 44 | --------- 45 | 46 | ```javascript 47 | game.plugins.add(Phaser.Plugin.SceneGraph, { 48 | css: { 49 | dead: "text-decoration: line-through", 50 | nonexisting: "color: gray", 51 | nonrenderable: "background: rgba(127, 127, 127, 0.125)", 52 | invisible: "background: rgba(0, 0, 0, 0.25)" 53 | }, 54 | quiet: false 55 | }); 56 | ``` 57 | 58 | Tips 59 | ---- 60 | 61 | Name your groups and emitters: 62 | 63 | ```javascript 64 | group.name = "invaders" 65 | 66 | emitter.name = "stars" 67 | ``` 68 | 69 | For a quick look at a game in progress, run in the console: 70 | 71 | ```javascript 72 | (function(game) { 73 | game.load 74 | .script( 75 | "SceneGraph", 76 | "https://cdn.jsdelivr.net/npm/phaser-plugin-scene-graph@1.1.0/dist/SceneGraph.js", 77 | function() { 78 | game.plugins.add(Phaser.Plugin.SceneGraph).graph(); 79 | } 80 | ) 81 | .start(); 82 | })(window.game || Phaser.GAMES[0]); 83 | ``` 84 | -------------------------------------------------------------------------------- /app/assets/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | Phaser Scene Graph plugin 10 |
11 |
12 |
13 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/assets/invaders/NOLICENSE: -------------------------------------------------------------------------------- 1 | Copyright Warning 2 | ================= 3 | 4 | Do not use any of the graphics or music found in this folder in your own games. 5 | 6 | You are free to use them for testing and prototypes, but do not release them in a commercial game. 7 | That includes games sold on MarketJS, or any game running advertisements such as via Google or Leadbolt. 8 | 9 | Why? because lots of the graphics in here come from commercial games themselves. 10 | 11 | For example sprites borrowed from Xenon 2, Metal Slug, Dig Dug and various console and Amiga games. 12 | 13 | These graphics are still owned by their copyright holders, and using them in something seen to be making money 14 | is a really bad idea on your part, ok? 15 | 16 | Plus, it's just not cool. 17 | -------------------------------------------------------------------------------- /app/assets/invaders/bullet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/app/assets/invaders/bullet.png -------------------------------------------------------------------------------- /app/assets/invaders/enemy-bullet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/app/assets/invaders/enemy-bullet.png -------------------------------------------------------------------------------- /app/assets/invaders/explode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/app/assets/invaders/explode.png -------------------------------------------------------------------------------- /app/assets/invaders/invader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/app/assets/invaders/invader.png -------------------------------------------------------------------------------- /app/assets/invaders/invader32x32x4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/app/assets/invaders/invader32x32x4.png -------------------------------------------------------------------------------- /app/assets/invaders/player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/app/assets/invaders/player.png -------------------------------------------------------------------------------- /app/assets/invaders/starfield.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/app/assets/invaders/starfield.png -------------------------------------------------------------------------------- /app/assets/screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/app/assets/screenshot1.png -------------------------------------------------------------------------------- /app/assets/screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/app/assets/screenshot2.png -------------------------------------------------------------------------------- /app/example.coffee: -------------------------------------------------------------------------------- 1 | {Phaser} = this 2 | 3 | {ADD} = Phaser.blendModes 4 | 5 | aliens = undefined 6 | bullets = undefined 7 | bulletTime = 0 8 | cursors = undefined 9 | enemyBullet = undefined 10 | enemyBullets = undefined 11 | explosions = undefined 12 | fireButton = undefined 13 | firingTimer = 0 14 | lives = undefined 15 | livingEnemies = [] 16 | player = undefined 17 | score = 0 18 | scoreString = "" 19 | scoreText = undefined 20 | starfield = undefined 21 | stateText = undefined 22 | 23 | init = -> 24 | {debug} = game 25 | debug.font = "16px monospace" 26 | debug.lineHeight = 25 27 | game.clearBeforeRender = no 28 | unless game.sceneGraphPlugin 29 | game.sceneGraphPlugin = game.plugins.add Phaser.Plugin.SceneGraph 30 | return 31 | 32 | preload = -> 33 | game.load.path = "invaders/" 34 | game.load.image "bullet", "bullet.png" 35 | game.load.image "enemyBullet", "enemy-bullet.png" 36 | game.load.spritesheet "invader", "invader32x32x4.png", 32, 32 37 | game.load.image "ship", "player.png" 38 | game.load.spritesheet "kaboom", "explode.png", 128, 128 39 | game.load.image "starfield", "starfield.png" 40 | return 41 | 42 | create = -> 43 | {debug, world} = game 44 | world.setBounds 0, 0, 800, 600 45 | debug.bounds = new Phaser.Rectangle 800, 0, game.width - world.width, game.height 46 | # The scrolling starfield background 47 | starfield = game.add.tileSprite(0, 0, 800, 600, "starfield") 48 | # Our bullet group 49 | bullets = game.add.group world, "bullets" 50 | bullets.enableBody = true 51 | bullets.physicsBodyType = Phaser.Physics.ARCADE 52 | bullets.createMultiple 10, "bullet" 53 | bullets.setAll "anchor.x", 0.5 54 | bullets.setAll "anchor.y", 1 55 | bullets.setAll "blendMode", ADD 56 | bullets.setAll "outOfBoundsKill", true 57 | bullets.setAll "checkWorldBounds", true 58 | # The enemy's bullets 59 | enemyBullets = game.add.group world, "enemyBullets" 60 | enemyBullets.enableBody = true 61 | enemyBullets.physicsBodyType = Phaser.Physics.ARCADE 62 | enemyBullets.createMultiple 10, "enemyBullet" 63 | enemyBullets.setAll "anchor.x", 0.5 64 | enemyBullets.setAll "anchor.y", 1 65 | enemyBullets.setAll "blendMode", ADD 66 | enemyBullets.setAll "outOfBoundsKill", true 67 | enemyBullets.setAll "checkWorldBounds", true 68 | # The hero! 69 | player = game.add.sprite(400, 500, "ship") 70 | player.anchor.setTo 0.5, 0.5 71 | game.physics.enable player, Phaser.Physics.ARCADE 72 | # The baddies! 73 | aliens = game.add.group world, "aliens" 74 | aliens.enableBody = true 75 | aliens.physicsBodyType = Phaser.Physics.ARCADE 76 | createAliens() 77 | style = align: "center", fill: "white", font: "24px monospace" 78 | # The score 79 | scoreString = "Score: " 80 | scoreText = game.add.text(10, 10, scoreString + score, style) 81 | scoreText.name = "scoreText" 82 | # Lives 83 | lives = game.add.group world, "lives" 84 | livesText = game.add.text game.world.width - 100, 10, "Lives", style 85 | livesText.name = "livesText" 86 | # Text 87 | stateText = game.add.text(game.world.centerX, game.world.centerY, " ", style) 88 | stateText.name = "stateText" 89 | stateText.anchor.setTo 0.5, 0.5 90 | stateText.visible = false 91 | i = 0 92 | while i < 3 93 | ship = lives.create(game.world.width - 100 + 30 * i, 60, "ship") 94 | ship.anchor.setTo 0.5, 0.5 95 | ship.angle = 90 96 | ship.alpha = 0.5 97 | i++ 98 | # An explosion pool 99 | explosions = game.add.group world, "explosions" 100 | explosions.createMultiple 10, "kaboom" 101 | explosions.setAll "blendMode", ADD 102 | explosions.forEach setupInvader, this 103 | # And some controls to play the game with 104 | cursors = game.input.keyboard.createCursorKeys() 105 | fireButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR) 106 | return 107 | 108 | createAliens = -> 109 | y = 0 110 | while y < 4 111 | x = 0 112 | while x < 10 113 | alien = aliens.create(x * 48, y * 50, "invader") 114 | alien.anchor.setTo 0.5, 0.5 115 | alien.animations.add "fly", [0, 1, 2, 3], 20, true 116 | alien.play "fly" 117 | alien.body.moves = false 118 | x++ 119 | y++ 120 | aliens.x = 100 121 | aliens.y = 50 122 | # All this does is basically start the invaders moving. Notice we"re moving the Group they belong to, rather than the invaders directly. 123 | tween = game.add.tween(aliens).to({ x: 200 }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true) 124 | # When the tween loops it calls descend 125 | tween.onLoop.add descend, this 126 | return 127 | 128 | setupInvader = (invader) -> 129 | invader.anchor.x = 0.5 130 | invader.anchor.y = 0.5 131 | invader.animations.add "kaboom" 132 | return 133 | 134 | descend = -> 135 | aliens.y += 10 136 | return 137 | 138 | update = -> 139 | # Scroll the background 140 | starfield.tilePosition.y += 1 141 | if player.alive 142 | # Reset the player, then check for movement keys 143 | player.body.velocity.setTo 0, 0 144 | if cursors.left.isDown 145 | player.body.velocity.x = -200 146 | else if cursors.right.isDown 147 | player.body.velocity.x = 200 148 | # Firing? 149 | if fireButton.isDown 150 | fireBullet() 151 | if game.time.now > firingTimer 152 | enemyFires() 153 | # Run collision 154 | game.physics.arcade.overlap bullets, aliens, collisionHandler, null, this 155 | game.physics.arcade.overlap enemyBullets, player, enemyHitsPlayer, null, this 156 | return 157 | 158 | render = -> 159 | {debug} = game 160 | x = debug.bounds.left 161 | y = debug.bounds.top 162 | lineHeight = 25 163 | debug.text "game.debug.renderGraph()", x, y += lineHeight, "white", debug.font 164 | debug.text "------------------------", x, y += lineHeight, "white", debug.font 165 | debug.renderGraph game.world, x, y += lineHeight, debug.font, 25 166 | y = 350 167 | debug.text "colors:", x, y += lineHeight, "white", debug.font 168 | game.sceneGraphPlugin.renderColors x + 80, y, debug.font, 25 169 | debug.text " 170 | Phaser v#{Phaser.VERSION} 171 | Plugin v#{Phaser.Plugin.SceneGraph.VERSION} 172 | ", 20, 580, "#808080" 173 | return 174 | 175 | collisionHandler = (bullet, alien) -> 176 | # When a bullet hits an alien we kill them both 177 | bullet.kill() 178 | alien.kill() 179 | # Increase the score 180 | score += 20 181 | scoreText.text = scoreString + score 182 | # And create an explosion :) 183 | explosion = explosions.getFirstExists(false) 184 | explosion.reset alien.body.x, alien.body.y 185 | explosion.play "kaboom", 30, false, true 186 | if aliens.countLiving() == 0 187 | score += 1000 188 | scoreText.text = scoreString + score 189 | enemyBullets.callAll "kill", this 190 | stateText.text = "VICTORY\n\n[restart]" 191 | stateText.visible = true 192 | #the "click to restart" handler 193 | game.input.onTap.addOnce restart, this 194 | return 195 | 196 | enemyHitsPlayer = (_player, bullet) -> 197 | bullet.kill() 198 | live = lives.getFirstAlive() 199 | if live 200 | live.kill() 201 | # And create an explosion :) 202 | explosion = explosions.getFirstExists(false) 203 | explosion.reset _player.body.x, _player.body.y 204 | explosion.play "kaboom", 30, false, true 205 | # When the player dies 206 | if lives.countLiving() < 1 207 | _player.kill() 208 | enemyBullets.callAll "kill" 209 | stateText.text = "GAME OVER\n\n[restart]" 210 | stateText.visible = true 211 | #the "click to restart" handler 212 | game.input.onTap.addOnce restart, this 213 | return 214 | 215 | enemyFires = -> 216 | # Grab the first bullet we can from the pool 217 | enemyBullet = enemyBullets.getFirstExists(false) 218 | livingEnemies.length = 0 219 | aliens.forEachAlive (alien) -> 220 | # put every living enemy in an array 221 | livingEnemies.push alien 222 | return 223 | if enemyBullet and livingEnemies.length > 0 224 | random = game.rnd.integerInRange(0, livingEnemies.length - 1) 225 | # randomly select one of them 226 | shooter = livingEnemies[random] 227 | # And fire the bullet from this enemy 228 | enemyBullet.reset shooter.body.x, shooter.body.y 229 | game.physics.arcade.moveToObject enemyBullet, player, 120 230 | firingTimer = game.time.now + 2000 231 | return 232 | 233 | fireBullet = -> 234 | # To avoid them being allowed to fire too fast we set a time limit 235 | if game.time.now > bulletTime 236 | # Grab the first bullet we can from the pool 237 | bullet = bullets.getFirstExists(false) 238 | if bullet 239 | # And fire it 240 | bullet.reset player.x, player.y + 8 241 | bullet.body.velocity.y = -400 242 | bulletTime = game.time.now + 200 243 | return 244 | 245 | restart = -> 246 | # A new level starts 247 | # resets the life count 248 | lives.callAll "revive" 249 | # and brings the aliens back from the dead :) 250 | aliens.removeAll() 251 | createAliens() 252 | # revives the player 253 | player.revive() 254 | # hides the text 255 | stateText.visible = false 256 | return 257 | 258 | game = new (Phaser.Game)(1200, 600, Phaser.CANVAS, "phaser-example", 259 | init: init 260 | preload: preload 261 | create: create 262 | update: update 263 | render: render) 264 | -------------------------------------------------------------------------------- /app/plugin.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | Scene Graph plugin {!major!}.{!minor!}.{!maintenance!} for Phaser 3 | ### 4 | 5 | "use strict" 6 | 7 | {freeze, seal} = Object 8 | 9 | Phaser = Phaser or @Phaser or window.Phaser or require? "phaser" 10 | 11 | throw new Error "Couldn't find `Phaser` or require 'phaser'" unless Phaser 12 | 13 | PIXI = PIXI or @PIXI or window.PIXI or require? "pixi" 14 | 15 | throw new Error "Couldn't find `PIXI` or require 'pixi'" unless PIXI 16 | 17 | if Phaser.BitmapData 18 | Phaser.BitmapData::toString = -> "[Phaser.BitmapData]" 19 | 20 | if Phaser.RenderTexture 21 | Phaser.RenderTexture::toString = -> "[Phaser.RenderTexture]" 22 | 23 | if Phaser.Video 24 | Phaser.Video::toString = -> "[Phaser.Video]" 25 | 26 | PIXI.Texture::toString = -> "[PIXI.Texture]" 27 | 28 | freeze class Phaser.Plugin.SceneGraph extends Phaser.Plugin 29 | 30 | {group, groupCollapsed, groupEnd, log} = console 31 | 32 | none = -> 33 | 34 | log = log.bind console 35 | group = if group then group.bind(console) else log 36 | groupEnd = if group then groupEnd.bind(console) else none 37 | groupCollapsed = if groupCollapsed then groupCollapsed.bind(console) else group 38 | 39 | _join = [] 40 | 41 | join = (arr, str) -> 42 | _join.length = index = 0 43 | for item in arr when item or item is 0 44 | _join[index] = item 45 | index += 1 46 | _join.join str 47 | 48 | @config = freeze 49 | colors: freeze 50 | nonexisting: "#808080" 51 | invisible: "#b0b0b0" 52 | empty: "#d381c3" 53 | allExist: "#a1c659" 54 | someExist: "#fda331" 55 | noneExist: "#fc6d24" 56 | nonrenderable: "#505050" 57 | dead: "#fb0120" 58 | 59 | css: freeze 60 | dead: "text-decoration: line-through" 61 | nonexisting: "color: gray" 62 | nonrenderable: "background: rgba(127, 127, 127, 0.125)" 63 | invisible: "background: rgba(0, 0, 0, 0.25)" 64 | quiet: no 65 | 66 | @types = types = { 0: "SPRITE", 1: "BUTTON", 2: "IMAGE", 3: "GRAPHICS", 4: "TEXT", 5: "TILESPRITE", 6: "BITMAPTEXT", 7: "GROUP", 8: "RENDERTEXTURE", 9: "TILEMAP", 10: "TILEMAPLAYER", 11: "EMITTER", 12: "POLYGON", 13: "BITMAPDATA", 14: "CANVAS_FILTER", 15: "WEBGL_FILTER", 16: "ELLIPSE", 17: "SPRITEBATCH", 18: "RETROFONT", 19: "POINTER", 20: "ROPE", 21: "CIRCLE", 22: "RECTANGLE", 23: "LINE", 24: "MATRIX", 25: "POINT", 26: "ROUNDEDRECTANGLE", 27: "CREATURE", 28: "VIDEO"} 67 | 68 | @VERSION = "{!major!}.{!minor!}.{!maintenance!}" 69 | 70 | @addTo = (game) -> 71 | game.plugins.add this 72 | 73 | name: "Scene Graph Plugin" 74 | 75 | # Hooks 76 | 77 | init: (settings) -> 78 | {extend} = Phaser.Utils 79 | @config = extend yes, {}, @constructor.config 80 | seal @config 81 | extend yes, @config, settings if settings 82 | unless @config.quiet 83 | log "%s v%s 👾", @name, @constructor.VERSION 84 | log "Use `game.debug.graph()` or `game.debug.graph(obj)`" 85 | @printStyles() 86 | Phaser.Utils.Debug::graph = @graph.bind this 87 | Phaser.Utils.Debug::renderGraph = @renderGraph.bind this 88 | Phaser.Utils.Debug::renderGraphMultiple = @renderGraphMultiple.bind this 89 | return 90 | 91 | # Helpers 92 | 93 | color: (obj, total) -> 94 | {colors} = @config 95 | {length} = obj 96 | hasTotal = total? 97 | switch 98 | when obj.exists is no then colors.nonexisting 99 | when obj.visible is no then colors.invisible 100 | when length is 0 then colors.empty 101 | when hasTotal and total is length then colors.allExist 102 | when total is 0 then colors.noneExist 103 | when hasTotal then colors.someExist 104 | when obj.renderable is no then colors.nonrenderable 105 | when obj.alive is no then colors.dead 106 | 107 | css: (obj) -> 108 | {css} = @config 109 | [ 110 | css.invisible if obj.visible is false 111 | css.nonexisting if obj.exists is false 112 | css.nonrenderable if obj.renderable is false 113 | css.dead if obj.alive is false 114 | ].join ";" 115 | 116 | getKey: getKey = (obj) -> 117 | {key} = obj 118 | switch 119 | when !key then null 120 | when key.key then getKey key 121 | else key 122 | 123 | getName: getName = (obj) -> 124 | {frame, frameName, name} = obj 125 | key = getKey obj 126 | join [name, join [key, frameName, frame], "."], " " 127 | 128 | graph: (obj = @game.stage, options = { 129 | collapse: yes 130 | filter: null 131 | map: null 132 | skipDead: no, 133 | skipNonexisting: no 134 | }) -> 135 | {collapse, filter, map, skipDead, skipNonexisting} = options 136 | {alive, children, exists} = obj 137 | 138 | return if (skipDead and not alive) or 139 | (skipNonexisting and not exists) or 140 | (filter and not filter obj) 141 | 142 | hasChildren = children?.length > 0 143 | method = if hasChildren then (if collapse then groupCollapsed else group) else log 144 | description = (if map then map else @map).call null, obj, obj.total 145 | 146 | method "%c#{description}", @css obj 147 | @graph child, options for child in children if hasChildren 148 | groupEnd() if hasChildren 149 | return 150 | 151 | map: (obj, total) -> 152 | {children, constructor, type} = obj 153 | 154 | longName = getName obj 155 | length = children?.length or 0 # Button, Group, Sprite, Text … 156 | hasLength = obj.length? # Group, Emitter, Line(!) 157 | hasLess = total? and total < length 158 | type = types[type] 159 | count = 160 | if hasLess then "(#{total}/#{length})" 161 | else if hasLength then "(#{length})" 162 | else "" 163 | 164 | join [(constructor?.name or type), longName, count], " " 165 | 166 | printStyles: -> 167 | log "Objects are styled:" 168 | for name, style of @config.css 169 | log "%c#{name}", style 170 | return 171 | 172 | renderColors: (x = 0, y = 0, font = @game.debug.font, lineHeight = @game.debug.lineHeight) -> 173 | {debug} = @game 174 | for name, color of @config.colors 175 | debug.text name, x, y, color, font 176 | y += lineHeight 177 | return 178 | 179 | renderGraph: (obj = @game.world, x = 0, y = 0, font = @game.debug.font, lineHeight = @game.debug.lineHeight) -> 180 | @renderObj obj, x, y, font 181 | x += lineHeight 182 | y += lineHeight 183 | 184 | @renderGraphMultiple obj.children, x, y, font, lineHeight 185 | return 186 | 187 | renderGraphMultiple: (objs, x = 0, y = 0, font = @game.debug.font, lineHeight = @game.debug.lineHeight) -> 188 | for obj in objs 189 | @renderObj obj, x, y, font 190 | y += lineHeight 191 | return 192 | 193 | renderObj: (obj, x, y, font) -> 194 | {total} = obj 195 | @game.debug.text @map(obj, total), x, y, @color(obj, total), font 196 | return 197 | 198 | module?.exports = Phaser.Plugin.SceneGraph 199 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "phaser-plugin-scene-graph", 3 | "description": "Prints the display tree", 4 | "main": "dist/SceneGraph.js", 5 | "dependencies": { 6 | "phaser": "^2.6.2" 7 | }, 8 | "authors": [ 9 | "samme" 10 | ], 11 | "license": "MIT", 12 | "homepage": "https://samme.github.io/phaser-plugin-scene-graph/", 13 | "private": true, 14 | "ignore": [ 15 | "**/.*", 16 | "node_modules", 17 | "bower_components", 18 | "test", 19 | "tests", 20 | "*.coffee", 21 | "*.html", 22 | "*.png", 23 | "app/", 24 | "dist/invaders", 25 | "dist/example.js", 26 | "package.json", 27 | "version.json" 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /brunch-config.coffee: -------------------------------------------------------------------------------- 1 | module.exports = 2 | files: 3 | javascripts: 4 | joinTo: 5 | 'SceneGraph.js': 'app/plugin.coffee', 6 | 'example.js': 'app/example.coffee', 7 | 'example/vendor.js': 'bower_components/phaser/build/phaser.js' 8 | modules: 9 | definition: no 10 | wrapper: no 11 | npm: 12 | enabled: no 13 | overrides: 14 | production: 15 | optimize: no 16 | paths: 17 | public: 'dist' 18 | plugins: 19 | coffeescript: 20 | bare: no 21 | version: 22 | fileRegExp: /\.(js|html)$/ 23 | sourceMaps: no 24 | -------------------------------------------------------------------------------- /dist/.gitignore: -------------------------------------------------------------------------------- 1 | # Numerous always-ignore extensions 2 | *.diff 3 | *.err 4 | *.orig 5 | *.log 6 | *.rej 7 | *.swo 8 | *.swp 9 | *.vi 10 | *~ 11 | *.sass-cache 12 | 13 | # OS or Editor folders 14 | .DS_Store 15 | .cache 16 | .project 17 | .settings 18 | .tmproj 19 | nbproject 20 | Thumbs.db 21 | 22 | # NPM packages folder. 23 | node_modules/ 24 | 25 | # Brunch folder for temporary files. 26 | tmp/ 27 | 28 | # Bower stuff. 29 | bower_components/ 30 | -------------------------------------------------------------------------------- /dist/SceneGraph.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Scene Graph plugin 1.1.0 for Phaser 4 | */ 5 | 6 | (function() { 7 | "use strict"; 8 | var PIXI, Phaser, freeze, seal, 9 | extend1 = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, 10 | hasProp = {}.hasOwnProperty; 11 | 12 | freeze = Object.freeze, seal = Object.seal; 13 | 14 | Phaser = Phaser || this.Phaser || window.Phaser || (typeof require === "function" ? require("phaser") : void 0); 15 | 16 | if (!Phaser) { 17 | throw new Error("Couldn't find `Phaser` or require 'phaser'"); 18 | } 19 | 20 | PIXI = PIXI || this.PIXI || window.PIXI || (typeof require === "function" ? require("pixi") : void 0); 21 | 22 | if (!PIXI) { 23 | throw new Error("Couldn't find `PIXI` or require 'pixi'"); 24 | } 25 | 26 | if (Phaser.BitmapData) { 27 | Phaser.BitmapData.prototype.toString = function() { 28 | return "[Phaser.BitmapData]"; 29 | }; 30 | } 31 | 32 | if (Phaser.RenderTexture) { 33 | Phaser.RenderTexture.prototype.toString = function() { 34 | return "[Phaser.RenderTexture]"; 35 | }; 36 | } 37 | 38 | if (Phaser.Video) { 39 | Phaser.Video.prototype.toString = function() { 40 | return "[Phaser.Video]"; 41 | }; 42 | } 43 | 44 | PIXI.Texture.prototype.toString = function() { 45 | return "[PIXI.Texture]"; 46 | }; 47 | 48 | freeze(Phaser.Plugin.SceneGraph = (function(superClass) { 49 | var _join, getKey, getName, group, groupCollapsed, groupEnd, join, log, none, types; 50 | 51 | extend1(SceneGraph, superClass); 52 | 53 | function SceneGraph() { 54 | return SceneGraph.__super__.constructor.apply(this, arguments); 55 | } 56 | 57 | group = console.group, groupCollapsed = console.groupCollapsed, groupEnd = console.groupEnd, log = console.log; 58 | 59 | none = function() {}; 60 | 61 | log = log.bind(console); 62 | 63 | group = group ? group.bind(console) : log; 64 | 65 | groupEnd = group ? groupEnd.bind(console) : none; 66 | 67 | groupCollapsed = groupCollapsed ? groupCollapsed.bind(console) : group; 68 | 69 | _join = []; 70 | 71 | join = function(arr, str) { 72 | var i, index, item, len; 73 | _join.length = index = 0; 74 | for (i = 0, len = arr.length; i < len; i++) { 75 | item = arr[i]; 76 | if (!(item || item === 0)) { 77 | continue; 78 | } 79 | _join[index] = item; 80 | index += 1; 81 | } 82 | return _join.join(str); 83 | }; 84 | 85 | SceneGraph.config = freeze({ 86 | colors: freeze({ 87 | nonexisting: "#808080", 88 | invisible: "#b0b0b0", 89 | empty: "#d381c3", 90 | allExist: "#a1c659", 91 | someExist: "#fda331", 92 | noneExist: "#fc6d24", 93 | nonrenderable: "#505050", 94 | dead: "#fb0120" 95 | }), 96 | css: freeze({ 97 | dead: "text-decoration: line-through", 98 | nonexisting: "color: gray", 99 | nonrenderable: "background: rgba(127, 127, 127, 0.125)", 100 | invisible: "background: rgba(0, 0, 0, 0.25)" 101 | }), 102 | quiet: false 103 | }); 104 | 105 | SceneGraph.types = types = { 106 | 0: "SPRITE", 107 | 1: "BUTTON", 108 | 2: "IMAGE", 109 | 3: "GRAPHICS", 110 | 4: "TEXT", 111 | 5: "TILESPRITE", 112 | 6: "BITMAPTEXT", 113 | 7: "GROUP", 114 | 8: "RENDERTEXTURE", 115 | 9: "TILEMAP", 116 | 10: "TILEMAPLAYER", 117 | 11: "EMITTER", 118 | 12: "POLYGON", 119 | 13: "BITMAPDATA", 120 | 14: "CANVAS_FILTER", 121 | 15: "WEBGL_FILTER", 122 | 16: "ELLIPSE", 123 | 17: "SPRITEBATCH", 124 | 18: "RETROFONT", 125 | 19: "POINTER", 126 | 20: "ROPE", 127 | 21: "CIRCLE", 128 | 22: "RECTANGLE", 129 | 23: "LINE", 130 | 24: "MATRIX", 131 | 25: "POINT", 132 | 26: "ROUNDEDRECTANGLE", 133 | 27: "CREATURE", 134 | 28: "VIDEO" 135 | }; 136 | 137 | SceneGraph.VERSION = "1.1.0"; 138 | 139 | SceneGraph.addTo = function(game) { 140 | return game.plugins.add(this); 141 | }; 142 | 143 | SceneGraph.prototype.name = "Scene Graph Plugin"; 144 | 145 | SceneGraph.prototype.init = function(settings) { 146 | var extend; 147 | extend = Phaser.Utils.extend; 148 | this.config = extend(true, {}, this.constructor.config); 149 | seal(this.config); 150 | if (settings) { 151 | extend(true, this.config, settings); 152 | } 153 | if (!this.config.quiet) { 154 | log("%s v%s 👾", this.name, this.constructor.VERSION); 155 | log("Use `game.debug.graph()` or `game.debug.graph(obj)`"); 156 | this.printStyles(); 157 | } 158 | Phaser.Utils.Debug.prototype.graph = this.graph.bind(this); 159 | Phaser.Utils.Debug.prototype.renderGraph = this.renderGraph.bind(this); 160 | Phaser.Utils.Debug.prototype.renderGraphMultiple = this.renderGraphMultiple.bind(this); 161 | }; 162 | 163 | SceneGraph.prototype.color = function(obj, total) { 164 | var colors, hasTotal, length; 165 | colors = this.config.colors; 166 | length = obj.length; 167 | hasTotal = total != null; 168 | switch (false) { 169 | case obj.exists !== false: 170 | return colors.nonexisting; 171 | case obj.visible !== false: 172 | return colors.invisible; 173 | case length !== 0: 174 | return colors.empty; 175 | case !(hasTotal && total === length): 176 | return colors.allExist; 177 | case total !== 0: 178 | return colors.noneExist; 179 | case !hasTotal: 180 | return colors.someExist; 181 | case obj.renderable !== false: 182 | return colors.nonrenderable; 183 | case obj.alive !== false: 184 | return colors.dead; 185 | } 186 | }; 187 | 188 | SceneGraph.prototype.css = function(obj) { 189 | var css; 190 | css = this.config.css; 191 | return [obj.visible === false ? css.invisible : void 0, obj.exists === false ? css.nonexisting : void 0, obj.renderable === false ? css.nonrenderable : void 0, obj.alive === false ? css.dead : void 0].join(";"); 192 | }; 193 | 194 | SceneGraph.prototype.getKey = getKey = function(obj) { 195 | var key; 196 | key = obj.key; 197 | switch (false) { 198 | case !!key: 199 | return null; 200 | case !key.key: 201 | return getKey(key); 202 | default: 203 | return key; 204 | } 205 | }; 206 | 207 | SceneGraph.prototype.getName = getName = function(obj) { 208 | var frame, frameName, key, name; 209 | frame = obj.frame, frameName = obj.frameName, name = obj.name; 210 | key = getKey(obj); 211 | return join([name, join([key, frameName, frame], ".")], " "); 212 | }; 213 | 214 | SceneGraph.prototype.graph = function(obj, options) { 215 | var alive, child, children, collapse, description, exists, filter, hasChildren, i, len, map, method, skipDead, skipNonexisting; 216 | if (obj == null) { 217 | obj = this.game.stage; 218 | } 219 | if (options == null) { 220 | options = { 221 | collapse: true, 222 | filter: null, 223 | map: null, 224 | skipDead: false, 225 | skipNonexisting: false 226 | }; 227 | } 228 | collapse = options.collapse, filter = options.filter, map = options.map, skipDead = options.skipDead, skipNonexisting = options.skipNonexisting; 229 | alive = obj.alive, children = obj.children, exists = obj.exists; 230 | if ((skipDead && !alive) || (skipNonexisting && !exists) || (filter && !filter(obj))) { 231 | return; 232 | } 233 | hasChildren = (children != null ? children.length : void 0) > 0; 234 | method = hasChildren ? (collapse ? groupCollapsed : group) : log; 235 | description = (map ? map : this.map).call(null, obj, obj.total); 236 | method("%c" + description, this.css(obj)); 237 | if (hasChildren) { 238 | for (i = 0, len = children.length; i < len; i++) { 239 | child = children[i]; 240 | this.graph(child, options); 241 | } 242 | } 243 | if (hasChildren) { 244 | groupEnd(); 245 | } 246 | }; 247 | 248 | SceneGraph.prototype.map = function(obj, total) { 249 | var children, constructor, count, hasLength, hasLess, length, longName, type; 250 | children = obj.children, constructor = obj.constructor, type = obj.type; 251 | longName = getName(obj); 252 | length = (children != null ? children.length : void 0) || 0; 253 | hasLength = obj.length != null; 254 | hasLess = (total != null) && total < length; 255 | type = types[type]; 256 | count = hasLess ? "(" + total + "/" + length + ")" : hasLength ? "(" + length + ")" : ""; 257 | return join([(constructor != null ? constructor.name : void 0) || type, longName, count], " "); 258 | }; 259 | 260 | SceneGraph.prototype.printStyles = function() { 261 | var name, ref, style; 262 | log("Objects are styled:"); 263 | ref = this.config.css; 264 | for (name in ref) { 265 | style = ref[name]; 266 | log("%c" + name, style); 267 | } 268 | }; 269 | 270 | SceneGraph.prototype.renderColors = function(x, y, font, lineHeight) { 271 | var color, debug, name, ref; 272 | if (x == null) { 273 | x = 0; 274 | } 275 | if (y == null) { 276 | y = 0; 277 | } 278 | if (font == null) { 279 | font = this.game.debug.font; 280 | } 281 | if (lineHeight == null) { 282 | lineHeight = this.game.debug.lineHeight; 283 | } 284 | debug = this.game.debug; 285 | ref = this.config.colors; 286 | for (name in ref) { 287 | color = ref[name]; 288 | debug.text(name, x, y, color, font); 289 | y += lineHeight; 290 | } 291 | }; 292 | 293 | SceneGraph.prototype.renderGraph = function(obj, x, y, font, lineHeight) { 294 | if (obj == null) { 295 | obj = this.game.world; 296 | } 297 | if (x == null) { 298 | x = 0; 299 | } 300 | if (y == null) { 301 | y = 0; 302 | } 303 | if (font == null) { 304 | font = this.game.debug.font; 305 | } 306 | if (lineHeight == null) { 307 | lineHeight = this.game.debug.lineHeight; 308 | } 309 | this.renderObj(obj, x, y, font); 310 | x += lineHeight; 311 | y += lineHeight; 312 | this.renderGraphMultiple(obj.children, x, y, font, lineHeight); 313 | }; 314 | 315 | SceneGraph.prototype.renderGraphMultiple = function(objs, x, y, font, lineHeight) { 316 | var i, len, obj; 317 | if (x == null) { 318 | x = 0; 319 | } 320 | if (y == null) { 321 | y = 0; 322 | } 323 | if (font == null) { 324 | font = this.game.debug.font; 325 | } 326 | if (lineHeight == null) { 327 | lineHeight = this.game.debug.lineHeight; 328 | } 329 | for (i = 0, len = objs.length; i < len; i++) { 330 | obj = objs[i]; 331 | this.renderObj(obj, x, y, font); 332 | y += lineHeight; 333 | } 334 | }; 335 | 336 | SceneGraph.prototype.renderObj = function(obj, x, y, font) { 337 | var total; 338 | total = obj.total; 339 | this.game.debug.text(this.map(obj, total), x, y, this.color(obj, total), font); 340 | }; 341 | 342 | return SceneGraph; 343 | 344 | })(Phaser.Plugin)); 345 | 346 | if (typeof module !== "undefined" && module !== null) { 347 | module.exports = Phaser.Plugin.SceneGraph; 348 | } 349 | 350 | }).call(this); 351 | 352 | -------------------------------------------------------------------------------- /dist/example.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var ADD, Phaser, aliens, bulletTime, bullets, collisionHandler, create, createAliens, cursors, descend, enemyBullet, enemyBullets, enemyFires, enemyHitsPlayer, explosions, fireBullet, fireButton, firingTimer, game, init, lives, livingEnemies, player, preload, render, restart, score, scoreString, scoreText, setupInvader, starfield, stateText, update; 3 | 4 | Phaser = this.Phaser; 5 | 6 | ADD = Phaser.blendModes.ADD; 7 | 8 | aliens = void 0; 9 | 10 | bullets = void 0; 11 | 12 | bulletTime = 0; 13 | 14 | cursors = void 0; 15 | 16 | enemyBullet = void 0; 17 | 18 | enemyBullets = void 0; 19 | 20 | explosions = void 0; 21 | 22 | fireButton = void 0; 23 | 24 | firingTimer = 0; 25 | 26 | lives = void 0; 27 | 28 | livingEnemies = []; 29 | 30 | player = void 0; 31 | 32 | score = 0; 33 | 34 | scoreString = ""; 35 | 36 | scoreText = void 0; 37 | 38 | starfield = void 0; 39 | 40 | stateText = void 0; 41 | 42 | init = function() { 43 | var debug; 44 | debug = game.debug; 45 | debug.font = "16px monospace"; 46 | debug.lineHeight = 25; 47 | game.clearBeforeRender = false; 48 | if (!game.sceneGraphPlugin) { 49 | game.sceneGraphPlugin = game.plugins.add(Phaser.Plugin.SceneGraph); 50 | } 51 | }; 52 | 53 | preload = function() { 54 | game.load.path = "invaders/"; 55 | game.load.image("bullet", "bullet.png"); 56 | game.load.image("enemyBullet", "enemy-bullet.png"); 57 | game.load.spritesheet("invader", "invader32x32x4.png", 32, 32); 58 | game.load.image("ship", "player.png"); 59 | game.load.spritesheet("kaboom", "explode.png", 128, 128); 60 | game.load.image("starfield", "starfield.png"); 61 | }; 62 | 63 | create = function() { 64 | var debug, i, livesText, ship, style, world; 65 | debug = game.debug, world = game.world; 66 | world.setBounds(0, 0, 800, 600); 67 | debug.bounds = new Phaser.Rectangle(800, 0, game.width - world.width, game.height); 68 | starfield = game.add.tileSprite(0, 0, 800, 600, "starfield"); 69 | bullets = game.add.group(world, "bullets"); 70 | bullets.enableBody = true; 71 | bullets.physicsBodyType = Phaser.Physics.ARCADE; 72 | bullets.createMultiple(10, "bullet"); 73 | bullets.setAll("anchor.x", 0.5); 74 | bullets.setAll("anchor.y", 1); 75 | bullets.setAll("blendMode", ADD); 76 | bullets.setAll("outOfBoundsKill", true); 77 | bullets.setAll("checkWorldBounds", true); 78 | enemyBullets = game.add.group(world, "enemyBullets"); 79 | enemyBullets.enableBody = true; 80 | enemyBullets.physicsBodyType = Phaser.Physics.ARCADE; 81 | enemyBullets.createMultiple(10, "enemyBullet"); 82 | enemyBullets.setAll("anchor.x", 0.5); 83 | enemyBullets.setAll("anchor.y", 1); 84 | enemyBullets.setAll("blendMode", ADD); 85 | enemyBullets.setAll("outOfBoundsKill", true); 86 | enemyBullets.setAll("checkWorldBounds", true); 87 | player = game.add.sprite(400, 500, "ship"); 88 | player.anchor.setTo(0.5, 0.5); 89 | game.physics.enable(player, Phaser.Physics.ARCADE); 90 | aliens = game.add.group(world, "aliens"); 91 | aliens.enableBody = true; 92 | aliens.physicsBodyType = Phaser.Physics.ARCADE; 93 | createAliens(); 94 | style = { 95 | align: "center", 96 | fill: "white", 97 | font: "24px monospace" 98 | }; 99 | scoreString = "Score: "; 100 | scoreText = game.add.text(10, 10, scoreString + score, style); 101 | scoreText.name = "scoreText"; 102 | lives = game.add.group(world, "lives"); 103 | livesText = game.add.text(game.world.width - 100, 10, "Lives", style); 104 | livesText.name = "livesText"; 105 | stateText = game.add.text(game.world.centerX, game.world.centerY, " ", style); 106 | stateText.name = "stateText"; 107 | stateText.anchor.setTo(0.5, 0.5); 108 | stateText.visible = false; 109 | i = 0; 110 | while (i < 3) { 111 | ship = lives.create(game.world.width - 100 + 30 * i, 60, "ship"); 112 | ship.anchor.setTo(0.5, 0.5); 113 | ship.angle = 90; 114 | ship.alpha = 0.5; 115 | i++; 116 | } 117 | explosions = game.add.group(world, "explosions"); 118 | explosions.createMultiple(10, "kaboom"); 119 | explosions.setAll("blendMode", ADD); 120 | explosions.forEach(setupInvader, this); 121 | cursors = game.input.keyboard.createCursorKeys(); 122 | fireButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); 123 | }; 124 | 125 | createAliens = function() { 126 | var alien, tween, x, y; 127 | y = 0; 128 | while (y < 4) { 129 | x = 0; 130 | while (x < 10) { 131 | alien = aliens.create(x * 48, y * 50, "invader"); 132 | alien.anchor.setTo(0.5, 0.5); 133 | alien.animations.add("fly", [0, 1, 2, 3], 20, true); 134 | alien.play("fly"); 135 | alien.body.moves = false; 136 | x++; 137 | } 138 | y++; 139 | } 140 | aliens.x = 100; 141 | aliens.y = 50; 142 | tween = game.add.tween(aliens).to({ 143 | x: 200 144 | }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true); 145 | tween.onLoop.add(descend, this); 146 | }; 147 | 148 | setupInvader = function(invader) { 149 | invader.anchor.x = 0.5; 150 | invader.anchor.y = 0.5; 151 | invader.animations.add("kaboom"); 152 | }; 153 | 154 | descend = function() { 155 | aliens.y += 10; 156 | }; 157 | 158 | update = function() { 159 | starfield.tilePosition.y += 1; 160 | if (player.alive) { 161 | player.body.velocity.setTo(0, 0); 162 | if (cursors.left.isDown) { 163 | player.body.velocity.x = -200; 164 | } else if (cursors.right.isDown) { 165 | player.body.velocity.x = 200; 166 | } 167 | if (fireButton.isDown) { 168 | fireBullet(); 169 | } 170 | if (game.time.now > firingTimer) { 171 | enemyFires(); 172 | } 173 | game.physics.arcade.overlap(bullets, aliens, collisionHandler, null, this); 174 | game.physics.arcade.overlap(enemyBullets, player, enemyHitsPlayer, null, this); 175 | } 176 | }; 177 | 178 | render = function() { 179 | var debug, lineHeight, x, y; 180 | debug = game.debug; 181 | x = debug.bounds.left; 182 | y = debug.bounds.top; 183 | lineHeight = 25; 184 | debug.text("game.debug.renderGraph()", x, y += lineHeight, "white", debug.font); 185 | debug.text("------------------------", x, y += lineHeight, "white", debug.font); 186 | debug.renderGraph(game.world, x, y += lineHeight, debug.font, 25); 187 | y = 350; 188 | debug.text("colors:", x, y += lineHeight, "white", debug.font); 189 | game.sceneGraphPlugin.renderColors(x + 80, y, debug.font, 25); 190 | debug.text("Phaser v" + Phaser.VERSION + " Plugin v" + Phaser.Plugin.SceneGraph.VERSION, 20, 580, "#808080"); 191 | }; 192 | 193 | collisionHandler = function(bullet, alien) { 194 | var explosion; 195 | bullet.kill(); 196 | alien.kill(); 197 | score += 20; 198 | scoreText.text = scoreString + score; 199 | explosion = explosions.getFirstExists(false); 200 | explosion.reset(alien.body.x, alien.body.y); 201 | explosion.play("kaboom", 30, false, true); 202 | if (aliens.countLiving() === 0) { 203 | score += 1000; 204 | scoreText.text = scoreString + score; 205 | enemyBullets.callAll("kill", this); 206 | stateText.text = "VICTORY\n\n[restart]"; 207 | stateText.visible = true; 208 | game.input.onTap.addOnce(restart, this); 209 | } 210 | }; 211 | 212 | enemyHitsPlayer = function(_player, bullet) { 213 | var explosion, live; 214 | bullet.kill(); 215 | live = lives.getFirstAlive(); 216 | if (live) { 217 | live.kill(); 218 | } 219 | explosion = explosions.getFirstExists(false); 220 | explosion.reset(_player.body.x, _player.body.y); 221 | explosion.play("kaboom", 30, false, true); 222 | if (lives.countLiving() < 1) { 223 | _player.kill(); 224 | enemyBullets.callAll("kill"); 225 | stateText.text = "GAME OVER\n\n[restart]"; 226 | stateText.visible = true; 227 | game.input.onTap.addOnce(restart, this); 228 | } 229 | }; 230 | 231 | enemyFires = function() { 232 | var random, shooter; 233 | enemyBullet = enemyBullets.getFirstExists(false); 234 | livingEnemies.length = 0; 235 | aliens.forEachAlive(function(alien) { 236 | livingEnemies.push(alien); 237 | }); 238 | if (enemyBullet && livingEnemies.length > 0) { 239 | random = game.rnd.integerInRange(0, livingEnemies.length - 1); 240 | shooter = livingEnemies[random]; 241 | enemyBullet.reset(shooter.body.x, shooter.body.y); 242 | game.physics.arcade.moveToObject(enemyBullet, player, 120); 243 | firingTimer = game.time.now + 2000; 244 | } 245 | }; 246 | 247 | fireBullet = function() { 248 | var bullet; 249 | if (game.time.now > bulletTime) { 250 | bullet = bullets.getFirstExists(false); 251 | if (bullet) { 252 | bullet.reset(player.x, player.y + 8); 253 | bullet.body.velocity.y = -400; 254 | bulletTime = game.time.now + 200; 255 | } 256 | } 257 | }; 258 | 259 | restart = function() { 260 | lives.callAll("revive"); 261 | aliens.removeAll(); 262 | createAliens(); 263 | player.revive(); 264 | stateText.visible = false; 265 | }; 266 | 267 | game = new Phaser.Game(1200, 600, Phaser.CANVAS, "phaser-example", { 268 | init: init, 269 | preload: preload, 270 | create: create, 271 | update: update, 272 | render: render 273 | }); 274 | 275 | }).call(this); 276 | 277 | -------------------------------------------------------------------------------- /dist/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | Phaser Scene Graph plugin 10 |
11 |
12 |
13 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /dist/invaders/NOLICENSE: -------------------------------------------------------------------------------- 1 | Copyright Warning 2 | ================= 3 | 4 | Do not use any of the graphics or music found in this folder in your own games. 5 | 6 | You are free to use them for testing and prototypes, but do not release them in a commercial game. 7 | That includes games sold on MarketJS, or any game running advertisements such as via Google or Leadbolt. 8 | 9 | Why? because lots of the graphics in here come from commercial games themselves. 10 | 11 | For example sprites borrowed from Xenon 2, Metal Slug, Dig Dug and various console and Amiga games. 12 | 13 | These graphics are still owned by their copyright holders, and using them in something seen to be making money 14 | is a really bad idea on your part, ok? 15 | 16 | Plus, it's just not cool. 17 | -------------------------------------------------------------------------------- /dist/invaders/bullet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/dist/invaders/bullet.png -------------------------------------------------------------------------------- /dist/invaders/enemy-bullet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/dist/invaders/enemy-bullet.png -------------------------------------------------------------------------------- /dist/invaders/explode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/dist/invaders/explode.png -------------------------------------------------------------------------------- /dist/invaders/invader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/dist/invaders/invader.png -------------------------------------------------------------------------------- /dist/invaders/invader32x32x4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/dist/invaders/invader32x32x4.png -------------------------------------------------------------------------------- /dist/invaders/player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/dist/invaders/player.png -------------------------------------------------------------------------------- /dist/invaders/starfield.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/dist/invaders/starfield.png -------------------------------------------------------------------------------- /dist/screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/dist/screenshot1.png -------------------------------------------------------------------------------- /dist/screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samme/phaser-plugin-scene-graph/f1688f40b839f96788598a96b6b4d156c2a8474f/dist/screenshot2.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "phaser-plugin-scene-graph", 3 | "description": "Prints the display tree", 4 | "homepage": "https://samme.github.io/phaser-plugin-scene-graph/", 5 | "bugs": { 6 | "url": "https://github.com/samme/phaser-plugin-scene-graph/issues" 7 | }, 8 | "author": "samme", 9 | "version": "1.1.0", 10 | "license": "MIT", 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/samme/phaser-plugin-scene-graph.git" 14 | }, 15 | "scripts": { 16 | "start": "brunch watch --server", 17 | "build": "brunch build --production", 18 | "preversion": "eslint dist/*.js", 19 | "version": "npm run build && git add app dist --all", 20 | "pub": "np", 21 | "postpublish": "git subtree push --prefix dist origin gh-pages" 22 | }, 23 | "dependencies": { 24 | "phaser": "^2.6.2" 25 | }, 26 | "devDependencies": { 27 | "auto-reload-brunch": "^2.0.0", 28 | "coffee-script-brunch": "^2.0.0", 29 | "javascript-brunch": "^2.0.0", 30 | "jstransformer-coffee-script": "^1.0.0", 31 | "jstransformer-markdown": "^1.1.0", 32 | "jstransformer-stylus": "^1.0.0", 33 | "jstransformer-verbatim": "^1.0.0", 34 | "uglify-js-brunch": "^2.0.0", 35 | "version-brunch": "^1.0.1" 36 | }, 37 | "main": "dist/SceneGraph.js", 38 | "keywords": [ 39 | "phaser", 40 | "phaser-plugin" 41 | ] 42 | } 43 | --------------------------------------------------------------------------------