From 95374339b92468e0ac116ff477728e44e11445b8 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Wed, 11 Sep 2013 17:32:53 +0100 Subject: [PATCH] Added a Sample Plugin and tested out the Plugin Manager. Working great :) --- Phaser.sublime-workspace | 936 +++++--------------------------------- Plugins/SamplePlugin.js | 37 ++ examples/plugin1.php | 44 ++ src/core/Game.js | 1 + src/core/Plugin.js | 24 +- src/core/PluginManager.js | 86 ++-- src/gameobjects/Bullet.js | 364 +++++++++++++++ src/loader/Cache.js | 30 ++ 8 files changed, 631 insertions(+), 891 deletions(-) create mode 100644 Plugins/SamplePlugin.js create mode 100644 examples/plugin1.php create mode 100644 src/gameobjects/Bullet.js diff --git a/Phaser.sublime-workspace b/Phaser.sublime-workspace index 2c65ab5a..d5ee964a 100644 --- a/Phaser.sublime-workspace +++ b/Phaser.sublime-workspace @@ -3,6 +3,46 @@ { "selected_items": [ + [ + "pl", + "plugin" + ], + [ + "pix", + "pixelPerfectAlpha (variable)" + ], + [ + "check", + "checkPixel (function)" + ], + [ + "FO", + "FOLLOW_LOCKON (variable)" + ], + [ + "F", + "FOLLOW_TOPDOWN_TIGHT (variable)" + ], + [ + "FOL", + "FOLLOW_PLATFORMER (variable)" + ], + [ + "atari", + "atari1" + ], + [ + "cam", + "camSpeed" + ], + [ + "render", + "renderer" + ], + [ + "set", + "setUpRenderer" + ], [ "_cro", "_cropRect" @@ -11,10 +51,6 @@ "_crop", "_cropUUID" ], - [ - "render", - "renderTexture" - ], [ "_tex", "_textures" @@ -147,18 +183,10 @@ "ha", "head" ], - [ - "set", - "setTo" - ], [ "setA", "setAlpha" ], - [ - "check", - "checkExists" - ], [ "remove", "removeAll (function)" @@ -355,10 +383,6 @@ "show", "showBounds" ], - [ - "cam", - "cameraVisible" - ], [ "up", "updateBounds" @@ -490,75 +514,11 @@ [ "AU", "RENDERER_AUTO" - ], - [ - "visi", - "visibilityChange" - ], - [ - "onlo", - "onLoadRenderCallback (variable)" - ], - [ - "onPr", - "onPreRenderCallback" - ], - [ - "onl", - "onLoadUpdateCallback" - ], - [ - "onp", - "onPausedCallback (variable)" - ], - [ - "onload", - "onLoadUpdateCallback (variable)" ] ] }, "buffers": [ - { - "file": "src/gameobjects/Sprite.js", - "settings": - { - "buffer_size": 17891, - "line_ending": "Windows" - } - }, - { - "file": "examples/crop3.php", - "settings": - { - "buffer_size": 812, - "line_ending": "Windows" - } - }, - { - "file": "/D/wamp/www/pixi.js/examples/example 14 - Masking/index.html", - "settings": - { - "buffer_size": 3387, - "line_ending": "Windows" - } - }, - { - "file": "src/core/World.js", - "settings": - { - "buffer_size": 5455, - "line_ending": "Windows" - } - }, - { - "file": "src/core/Group.js", - "settings": - { - "buffer_size": 19172, - "line_ending": "Windows" - } - } ], "build_system": "", "command_palette": @@ -588,23 +548,71 @@ }, "file_history": [ + "/D/wamp/www/phaser/plugins/SamplePlugin.js", + "/D/wamp/www/phaser/src/core/Plugin.js", + "/D/wamp/www/phaser/examples/plugin1.php", + "/D/wamp/www/phaser/src/core/Game.js", + "/D/wamp/www/phaser/src/core/PluginManager.js", + "/D/wamp/www/phaser/examples/js.php", + "/D/wamp/www/phaser/src/animation/FrameData.js", + "/D/wamp/www/phaser/src/loader/Cache.js", + "/D/wamp/www/phaser/src/physics/arcade/Body.js", + "/D/wamp/www/phaser/src/gameobjects/Bullet.js", + "/D/wamp/www/phaser/examples/pixelpick3.php", + "/D/wamp/www/phaser/src/input/InputHandler.js", + "/D/wamp/www/phaser/src/input/Input.js", + "/D/wamp/www/phaser/src/gameobjects/Sprite.js", + "/D/wamp/www/phaser/src/utils/Debug.js", + "/D/wamp/www/phaser/src/core/Stage.js", + "/D/wamp/www/phaser/examples/sprite3.php", + "/D/wamp/www/phaser/examples/world.php", + "/D/wamp/www/phaser/src/core/Camera.js", + "/D/wamp/www/phaser/examples/camerafollow.php", + "/D/wamp/www/phaser/examples/tilesprite2.php", + "/D/wamp/www/phaser/src/math/Math.js", + "/D/wamp/www/phaser/src/core/Group.js", + "/D/wamp/www/phaser/src/core/Signal.js", + "/D/wamp/www/phaser/src/geom/Circle.js", + "/D/wamp/www/phaser/src/geom/Rectangle.js", + "/D/wamp/www/phaser/src/sound/Sound.js", + "/D/wamp/www/phaser/src/sound/SoundManager.js", + "/D/wamp/www/phaser/src/utils/Color.js", + "/D/wamp/www/phaser/src/core/World.js", + "/D/wamp/www/phaser/src/core/LinkedList.js", "/D/wamp/www/phaser/src/gameobjects/GameObjectFactory.js", + "/D/wamp/www/phaser/examples/group1.php", + "/D/wamp/www/phaser/src/geom/Point.js", + "/D/wamp/www/phaser/src/input/Pointer.js", + "/D/wamp/www/phaser/src/particles/arcade/Emitter.js", + "/D/wamp/www/phaser/src/physics/arcade/ArcadePhysics.js", + "/D/wamp/www/phaser/src/system/StageScaleMode.js", + "/D/wamp/www/phaser/src/gameobjects/BitmapText.js", + "/D/wamp/www/phaser/src/core/StateManager.js", + "/D/wamp/www/phaser/src/animation/Parser.js", + "/D/wamp/www/phaser/src/animation/AnimationManager.js", + "/D/wamp/www/phaser/src/animation/Animation.js", + "/D/wamp/www/phaser/TS Source/World.ts", + "/D/wamp/www/phaser/examples/sound1.php", + "/D/wamp/www/phaser/src/input/Touch.js", + "/D/wamp/www/phaser/examples/fullscreen.php", + "/D/wamp/www/phaser/src/loader/Loader.js", + "/D/wamp/www/pixi.js/examples/example 14 - Masking/index.html", + "/D/wamp/www/phaser/examples/crop3.php", + "/D/wamp/www/phaser/src/system/Canvas.js", + "/D/ws/manukura/kiwi/components/dom/Gradient.js", + "/D/wamp/www/phaser/examples/invaders.php", "/D/wamp/www/phaser/src/pixi/textures/Texture.js", "/D/wamp/www/phaser/src/pixi/textures/BaseTexture.js", - "/D/wamp/www/phaser/src/animation/Animation.js", "/D/wamp/www/phaser/examples/rendertexture.php", "/D/wamp/www/pixi.js/examples/example 11 - RenderTexture/index.html", "/D/wamp/www/phaser/src/gameobjects/RenderTexture.js", "/D/wamp/www/phaser/src/pixi/textures/RenderTexture.js", "/D/wamp/www/phaser/src/animation/Frame.js", - "/D/wamp/www/phaser/src/loader/Cache.js", "/D/wamp/www/phaser/src/tilemap/Tile.js", "/D/wamp/www/phaser/examples/tilemap.php", "/D/wamp/www/phaser/src/tilemap/Tilemap.js", "/D/wamp/www/phaser/src/tilemap/TilemapLayer.js", - "/D/wamp/www/phaser/src/utils/Color.js", "/D/wamp/www/phaser/TS Tests/tilemaps/csv tilemap.ts", - "/D/wamp/www/phaser/examples/js.php", "/D/wamp/www/phaser/TS Source/tilemap/Tile.js", "/D/wamp/www/phaser/TS Source/tilemap/TilemapLayer.js", "/D/wamp/www/phaser/TS Source/tilemap/Tilemap.js", @@ -612,9 +620,7 @@ "/D/wamp/www/phaser/TS Source/loader/Cache.ts", "/D/wamp/www/phaser/examples/sprite_extend.php", "/D/wamp/www/phaser/src/gameobjects/TileSprite.js", - "/D/wamp/www/phaser/src/gameobjects/Sprite.js", "/D/wamp/www/phaser/TS Source/gameobjects/ScrollZone.js", - "/D/wamp/www/phaser/src/core/World.js", "/D/wamp/www/phaser/TS Source/display/CSS3Filters.js", "/D/wamp/www/phaser/plugins/CSS3Filters.js", "/D/wamp/www/phaser/src/pixi/loaders/BitmapFontLoader.js", @@ -622,43 +628,15 @@ "/D/wamp/www/phaser/src/gameobjects/Graphics.js", "/D/wamp/www/phaser/src/gameobjects/BitmapFont.js", "/D/wamp/www/phaser/src/loader/Parser.js", - "/D/wamp/www/phaser/src/loader/Loader.js", "/D/wamp/www/pixi.js/examples/example 10 - Text/index.html", - "/D/wamp/www/phaser/src/animation/Parser.js", "/D/wamp/www/phaser/examples/assets/fonts/desyrel.xml", - "/D/wamp/www/phaser/examples/fullscreen.php", - "/D/wamp/www/phaser/src/system/StageScaleMode.js", - "/D/wamp/www/phaser/src/core/Game.js", "/D/wamp/www/phaser/src/time/Time.js", "/D/wamp/www/phaser/src/tween/Tween.js", "/D/wamp/www/phaser/src/tween/TweenManager.js", - "/D/wamp/www/phaser/src/core/Stage.js", - "/D/wamp/www/phaser/src/sound/SoundManager.js", "/D/wamp/www/phaser/src/core/State.js", - "/D/wamp/www/phaser/src/core/StateManager.js", - "/D/wamp/www/phaser/src/input/Pointer.js", - "/D/wamp/www/phaser/src/input/Touch.js", "/D/wamp/www/phaser/src/input/Keyboard.js", - "/D/wamp/www/phaser/src/input/InputHandler.js", - "/D/wamp/www/phaser/src/input/Input.js", - "/D/wamp/www/phaser/src/geom/Circle.js", - "/D/wamp/www/phaser/src/geom/Point.js", - "/D/wamp/www/phaser/src/geom/Rectangle.js", - "/D/wamp/www/phaser/src/core/Signal.js", - "/D/wamp/www/phaser/src/core/Plugin.js", - "/D/wamp/www/phaser/src/core/PluginManager.js", - "/D/wamp/www/phaser/src/core/Group.js", - "/D/wamp/www/phaser/src/core/LinkedList.js", - "/D/wamp/www/phaser/src/core/Camera.js", - "/D/wamp/www/phaser/src/animation/FrameData.js", "/D/wamp/www/phaser/src/gameobjects/Events.js", - "/D/wamp/www/phaser/src/animation/AnimationManager.js", - "/D/wamp/www/phaser/src/system/Canvas.js", "/D/wamp/www/phaser/examples/input2.php", - "/D/wamp/www/phaser/examples/sound1.php", - "/D/wamp/www/phaser/src/sound/Sound.js", - "/D/wamp/www/phaser/src/utils/Debug.js", - "/D/wamp/www/phaser/examples/invaders.php", "/D/wamp/www/phaser/src/input/MSPointer.js", "/D/wamp/www/phaser/src/pixi/renderers/canvas/CanvasRenderer.js", "/D/wamp/www/phaser/src/pixi/renderers/webgl/WebGLRenderer.js", @@ -671,13 +649,10 @@ "/D/wamp/www/phaser/examples/bringToTop3.php", "/D/wamp/www/phaser/examples/bring to top2.php", "/D/wamp/www/phaser/examples/bring to top.php", - "/D/wamp/www/phaser/src/math/Math.js", "/D/wamp/www/phaser/src/utils/Utils.js", - "/D/wamp/www/phaser/src/particles/arcade/Emitter.js", "/D/wamp/www/phaser/examples/particles.php", "/D/wamp/www/phaser/examples/assets/sprites/pixi_monsters.json", "/D/wamp/www/phaser/src/particles/Particles.js", - "/D/wamp/www/phaser/src/physics/arcade/Body.js", "/D/wamp/www/phaser/src/math/RandomDataGenerator.js", "/D/wamp/www/phaser/src/particles/arcade/ArcadeParticles.js", "/D/wamp/www/phaser/src/system/Device.js", @@ -700,22 +675,7 @@ "/D/wamp/www/phaser/examples/js_full.php", "/D/wamp/www/phaser/examples/bring top top2.php", "/D/wamp/www/phaser/TS Tests/input/bring to top.ts", - "/D/wamp/www/phaser/examples/touch1.php", - "/D/wamp/www/phaser/TS Source/utils/DebugUtils.js", - "/D/wamp/www/phaser/TS Source/gameobjects/Events.js", - "/D/wamp/www/phaser/TS Source/input/InputHandler.ts", - "/D/wamp/www/phaser/TS Source/input/InputHandler.js", - "/D/wamp/www/phaser/examples/linkedlist1.php", - "/D/wamp/www/phaser/src/pixi/display/DisplayObjectContainer.js", - "/D/wamp/www/phaser/src/pixi/display/DisplayObject.js", - "/D/wamp/www/phaser/examples/quadtree2.php", - "/D/wamp/www/phaser/examples/body3.php", - "/D/wamp/www/phaser/examples/body2.php", - "/D/wamp/www/phaser/src/math/QuadTree.js", - "/D/wamp/www/phaser/examples/anchor1.php", - "/D/wamp/www/phaser/src/physics/arcade/ArcadePhysics.js", - "/D/wamp/www/phaser/TS Source/core/Group.ts", - "/D/wamp/www/phaser/TS Source/core/Group.js" + "/D/wamp/www/phaser/examples/touch1.php" ], "find": { @@ -723,9 +683,10 @@ }, "find_in_files": { - "height": 0.0, + "height": 90.0, "where_history": [ + "D:\\wamp\\www\\phaser\\src", "D:\\wamp\\www\\phaser\\src\\pixi", "D:\\wamp\\www\\phaser\\src\\input", "D:\\wamp\\www\\phaser\\src\\physics\\advanced", @@ -754,6 +715,31 @@ "case_sensitive": true, "find_history": [ + "Phaser.Sprite", + "mummy", + "checkBody", + ": ", + "tempSprite", + "disk", + "drag", + "dragPixelPerfect", + "last", + "edge", + "targetY", + "targetX", + "center.", + "screenView", + "temp", + "this.camSpeed", + "8", + "4", + "for(", + "if(", + ",\n\n enumerable: true,\n configurable: true", + " },\n\n enumerable: true,\n configurable: true\n", + "document", + "getAudioURL", + "onSoundUnlock", "tempSprite", "texture", "width", @@ -856,32 +842,7 @@ "_iNext", "entity", "ship", - "displayObject", - "this", - "interactiveItems", - "PIXI.visibleCount", - "vcount", - "childLast", - "bounds", - "body.bounds", - "right", - "x", - "_iPrev", - "first", - "child1", - "displayObject", - "_container", - "'),", - "),", - "background", - " = value", - "keys", - "path", - "bounds", - ");\n", - "checkAlive", - "alive", - "launch" + "displayObject" ], "highlight": true, "in_selection": false, @@ -889,6 +850,8 @@ "regex": false, "replace_history": [ + "Phaser.Bullet", + "for (", "if (", "for (", "if (", @@ -1000,661 +963,8 @@ "groups": [ { - "selected": 3, "sheets": [ - { - "buffer": 0, - "file": "src/gameobjects/Sprite.js", - "settings": - { - "buffer_size": 17891, - "regions": - { - }, - "selection": - [ - [ - 16650, - 16650 - ] - ], - "settings": - { - "codeintel": true, - "codeintel_config": - { - "JavaScript": - { - "codeintel_max_recursive_dir_depth": 2, - "codeintel_scan_files_in_project": false, - "javascriptExtraPaths": - [ - ] - }, - "PHP": - { - "codeintel_max_recursive_dir_depth": 5, - "codeintel_scan_files_in_project": false, - "phpExtraPaths": - [ - ] - }, - "Python": - { - "env": - { - } - } - }, - "codeintel_enabled_languages": - [ - "JavaScript", - "Mason", - "XBL", - "XUL", - "RHTML", - "SCSS", - "Python", - "HTML", - "Ruby", - "Python3", - "XML", - "Sass", - "XSLT", - "Django", - "HTML5", - "Perl", - "CSS", - "Twig", - "Less", - "Smarty", - "Node.js", - "Tcl", - "TemplateToolkit", - "PHP" - ], - "codeintel_live": true, - "codeintel_live_enabled_languages": - [ - "JavaScript", - "Mason", - "XBL", - "XUL", - "RHTML", - "SCSS", - "Python", - "HTML", - "Ruby", - "Python3", - "XML", - "Sass", - "XSLT", - "Django", - "HTML5", - "Perl", - "CSS", - "Twig", - "Less", - "Smarty", - "Node.js", - "Tcl", - "TemplateToolkit", - "PHP" - ], - "codeintel_max_recursive_dir_depth": 10, - "codeintel_scan_exclude_dir": - { - "JavaScript": - [ - "/build/", - "/min/" - ] - }, - "codeintel_scan_files_in_project": true, - "codeintel_selected_catalogs": - [ - "PyWin32", - "jQuery", - "Rails" - ], - "codeintel_snippets": true, - "codeintel_syntax_map": - { - "Python Django": "Python" - }, - "sublime_auto_complete": true, - "syntax": "Packages/JavaScript/JavaScript.tmLanguage", - "tab_size": 4, - "translate_tabs_to_spaces": true - }, - "translation.x": 0.0, - "translation.y": 8910.0, - "zoom_level": 1.0 - }, - "type": "text" - }, - { - "buffer": 1, - "file": "examples/crop3.php", - "settings": - { - "buffer_size": 812, - "regions": - { - }, - "selection": - [ - [ - 695, - 695 - ] - ], - "settings": - { - "codeintel": true, - "codeintel_config": - { - "JavaScript": - { - "codeintel_max_recursive_dir_depth": 2, - "codeintel_scan_files_in_project": false, - "javascriptExtraPaths": - [ - ] - }, - "PHP": - { - "codeintel_max_recursive_dir_depth": 5, - "codeintel_scan_files_in_project": false, - "phpExtraPaths": - [ - ] - }, - "Python": - { - "env": - { - } - } - }, - "codeintel_enabled_languages": - [ - "JavaScript", - "Mason", - "XBL", - "XUL", - "RHTML", - "SCSS", - "Python", - "HTML", - "Ruby", - "Python3", - "XML", - "Sass", - "XSLT", - "Django", - "HTML5", - "Perl", - "CSS", - "Twig", - "Less", - "Smarty", - "Node.js", - "Tcl", - "TemplateToolkit", - "PHP" - ], - "codeintel_live": true, - "codeintel_live_enabled_languages": - [ - "JavaScript", - "Mason", - "XBL", - "XUL", - "RHTML", - "SCSS", - "Python", - "HTML", - "Ruby", - "Python3", - "XML", - "Sass", - "XSLT", - "Django", - "HTML5", - "Perl", - "CSS", - "Twig", - "Less", - "Smarty", - "Node.js", - "Tcl", - "TemplateToolkit", - "PHP" - ], - "codeintel_max_recursive_dir_depth": 10, - "codeintel_scan_exclude_dir": - { - "JavaScript": - [ - "/build/", - "/min/" - ] - }, - "codeintel_scan_files_in_project": true, - "codeintel_selected_catalogs": - [ - "PyWin32", - "jQuery", - "Rails" - ], - "codeintel_snippets": true, - "codeintel_syntax_map": - { - "Python Django": "Python" - }, - "sublime_auto_complete": true, - "syntax": "Packages/PHP/PHP.tmLanguage", - "tab_size": 4, - "translate_tabs_to_spaces": true - }, - "translation.x": 0.0, - "translation.y": 0.0, - "zoom_level": 1.0 - }, - "type": "text" - }, - { - "buffer": 2, - "file": "/D/wamp/www/pixi.js/examples/example 14 - Masking/index.html", - "settings": - { - "buffer_size": 3387, - "regions": - { - }, - "selection": - [ - [ - 488, - 488 - ] - ], - "settings": - { - "codeintel": true, - "codeintel_config": - { - "JavaScript": - { - "codeintel_max_recursive_dir_depth": 2, - "codeintel_scan_files_in_project": false, - "javascriptExtraPaths": - [ - ] - }, - "PHP": - { - "codeintel_max_recursive_dir_depth": 5, - "codeintel_scan_files_in_project": false, - "phpExtraPaths": - [ - ] - }, - "Python": - { - "env": - { - } - } - }, - "codeintel_enabled_languages": - [ - "JavaScript", - "Mason", - "XBL", - "XUL", - "RHTML", - "SCSS", - "Python", - "HTML", - "Ruby", - "Python3", - "XML", - "Sass", - "XSLT", - "Django", - "HTML5", - "Perl", - "CSS", - "Twig", - "Less", - "Smarty", - "Node.js", - "Tcl", - "TemplateToolkit", - "PHP" - ], - "codeintel_live": true, - "codeintel_live_enabled_languages": - [ - "JavaScript", - "Mason", - "XBL", - "XUL", - "RHTML", - "SCSS", - "Python", - "HTML", - "Ruby", - "Python3", - "XML", - "Sass", - "XSLT", - "Django", - "HTML5", - "Perl", - "CSS", - "Twig", - "Less", - "Smarty", - "Node.js", - "Tcl", - "TemplateToolkit", - "PHP" - ], - "codeintel_max_recursive_dir_depth": 10, - "codeintel_scan_exclude_dir": - { - "JavaScript": - [ - "/build/", - "/min/" - ] - }, - "codeintel_scan_files_in_project": true, - "codeintel_selected_catalogs": - [ - "PyWin32", - "jQuery", - "Rails" - ], - "codeintel_snippets": true, - "codeintel_syntax_map": - { - "Python Django": "Python" - }, - "sublime_auto_complete": true, - "syntax": "Packages/HTML/HTML.tmLanguage", - "translate_tabs_to_spaces": false - }, - "translation.x": 0.0, - "translation.y": 1424.0, - "zoom_level": 1.0 - }, - "type": "text" - }, - { - "buffer": 3, - "file": "src/core/World.js", - "settings": - { - "buffer_size": 5455, - "regions": - { - }, - "selection": - [ - [ - 0, - 0 - ] - ], - "settings": - { - "codeintel": true, - "codeintel_config": - { - "JavaScript": - { - "codeintel_max_recursive_dir_depth": 2, - "codeintel_scan_files_in_project": false, - "javascriptExtraPaths": - [ - ] - }, - "PHP": - { - "codeintel_max_recursive_dir_depth": 5, - "codeintel_scan_files_in_project": false, - "phpExtraPaths": - [ - ] - }, - "Python": - { - "env": - { - } - } - }, - "codeintel_enabled_languages": - [ - "JavaScript", - "Mason", - "XBL", - "XUL", - "RHTML", - "SCSS", - "Python", - "HTML", - "Ruby", - "Python3", - "XML", - "Sass", - "XSLT", - "Django", - "HTML5", - "Perl", - "CSS", - "Twig", - "Less", - "Smarty", - "Node.js", - "Tcl", - "TemplateToolkit", - "PHP" - ], - "codeintel_live": true, - "codeintel_live_enabled_languages": - [ - "JavaScript", - "Mason", - "XBL", - "XUL", - "RHTML", - "SCSS", - "Python", - "HTML", - "Ruby", - "Python3", - "XML", - "Sass", - "XSLT", - "Django", - "HTML5", - "Perl", - "CSS", - "Twig", - "Less", - "Smarty", - "Node.js", - "Tcl", - "TemplateToolkit", - "PHP" - ], - "codeintel_max_recursive_dir_depth": 10, - "codeintel_scan_exclude_dir": - { - "JavaScript": - [ - "/build/", - "/min/" - ] - }, - "codeintel_scan_files_in_project": true, - "codeintel_selected_catalogs": - [ - "PyWin32", - "jQuery", - "Rails" - ], - "codeintel_snippets": true, - "codeintel_syntax_map": - { - "Python Django": "Python" - }, - "sublime_auto_complete": true, - "syntax": "Packages/JavaScript/JavaScript.tmLanguage", - "translate_tabs_to_spaces": false - }, - "translation.x": 0.0, - "translation.y": 0.0, - "zoom_level": 1.0 - }, - "type": "text" - }, - { - "buffer": 4, - "file": "src/core/Group.js", - "settings": - { - "buffer_size": 19172, - "regions": - { - }, - "selection": - [ - [ - 0, - 0 - ] - ], - "settings": - { - "codeintel": true, - "codeintel_config": - { - "JavaScript": - { - "codeintel_max_recursive_dir_depth": 2, - "codeintel_scan_files_in_project": false, - "javascriptExtraPaths": - [ - ] - }, - "PHP": - { - "codeintel_max_recursive_dir_depth": 5, - "codeintel_scan_files_in_project": false, - "phpExtraPaths": - [ - ] - }, - "Python": - { - "env": - { - } - } - }, - "codeintel_enabled_languages": - [ - "JavaScript", - "Mason", - "XBL", - "XUL", - "RHTML", - "SCSS", - "Python", - "HTML", - "Ruby", - "Python3", - "XML", - "Sass", - "XSLT", - "Django", - "HTML5", - "Perl", - "CSS", - "Twig", - "Less", - "Smarty", - "Node.js", - "Tcl", - "TemplateToolkit", - "PHP" - ], - "codeintel_live": true, - "codeintel_live_enabled_languages": - [ - "JavaScript", - "Mason", - "XBL", - "XUL", - "RHTML", - "SCSS", - "Python", - "HTML", - "Ruby", - "Python3", - "XML", - "Sass", - "XSLT", - "Django", - "HTML5", - "Perl", - "CSS", - "Twig", - "Less", - "Smarty", - "Node.js", - "Tcl", - "TemplateToolkit", - "PHP" - ], - "codeintel_max_recursive_dir_depth": 10, - "codeintel_scan_exclude_dir": - { - "JavaScript": - [ - "/build/", - "/min/" - ] - }, - "codeintel_scan_files_in_project": true, - "codeintel_selected_catalogs": - [ - "PyWin32", - "jQuery", - "Rails" - ], - "codeintel_snippets": true, - "codeintel_syntax_map": - { - "Python Django": "Python" - }, - "sublime_auto_complete": true, - "syntax": "Packages/JavaScript/JavaScript.tmLanguage", - "translate_tabs_to_spaces": false - }, - "translation.x": 0.0, - "translation.y": 13739.0, - "zoom_level": 1.0 - }, - "type": "text" - } ] } ], diff --git a/Plugins/SamplePlugin.js b/Plugins/SamplePlugin.js new file mode 100644 index 00000000..a934c9a1 --- /dev/null +++ b/Plugins/SamplePlugin.js @@ -0,0 +1,37 @@ +/** +* A Sample Plugin demonstrating how to hook into the Phaser plugin system. +*/ +Phaser.Plugin.SamplePlugin = function (game, parent) { + + Phaser.Plugin.call(this, game, parent); + + this.sprite = null; + +}; + +// Extends the Phaser.Plugin template, setting up values we need +Phaser.Plugin.SamplePlugin.prototype = Object.create(Phaser.Plugin.prototype); +Phaser.Plugin.SamplePlugin.prototype.constructor = Phaser.Plugin.SamplePlugin; + +/** +* Add a Sprite reference to this Plugin. +* All this plugin does is move the Sprite across the screen slowly. +* @type {Phaser.Sprite} +*/ +Phaser.Plugin.SamplePlugin.prototype.addSprite = function (sprite) { + + this.sprite = sprite; + +}; + +/** +* This is run when the plugins update during the core game loop. +*/ +Phaser.Plugin.SamplePlugin.prototype.update = function () { + + if (this.sprite) + { + this.sprite.x += 0.5; + } + +}; diff --git a/examples/plugin1.php b/examples/plugin1.php new file mode 100644 index 00000000..3014b17d --- /dev/null +++ b/examples/plugin1.php @@ -0,0 +1,44 @@ + + + + phaser.js - a new beginning + + + + + + + + + \ No newline at end of file diff --git a/src/core/Game.js b/src/core/Game.js index 4e4aa453..65134796 100644 --- a/src/core/Game.js +++ b/src/core/Game.js @@ -394,6 +394,7 @@ Phaser.Game.prototype = { this.plugins.update(); this.renderer.render(this.stage._stage); + this.plugins.render(); this.state.render(); this.plugins.postRender(); diff --git a/src/core/Plugin.js b/src/core/Plugin.js index c83f89e8..ef1a967a 100644 --- a/src/core/Plugin.js +++ b/src/core/Plugin.js @@ -13,8 +13,6 @@ Phaser.Plugin = function (game, parent) { this.hasPreUpdate = false; this.hasUpdate = false; - this.hasPostUpdate = false; - this.hasPreRender = false; this.hasRender = false; this.hasPostRender = false; @@ -23,42 +21,28 @@ Phaser.Plugin = function (game, parent) { Phaser.Plugin.prototype = { /** - * Pre-update is called at the start of the update cycle, before any other updates have taken place. + * Pre-update is called at the start of the update cycle, before any other updates have taken place (including Physics). * It is only called if active is set to true. */ preUpdate: function () { }, /** - * Pre-update is called at the start of the update cycle, before any other updates have taken place. + * Update is called after all the core subsystems (Input, Tweens, Sound, etc) and the State have updated, but before the render. * It is only called if active is set to true. */ update: function () { }, /** - * Post-update is called at the end of the objects update cycle, after other update logic has taken place. - * It is only called if active is set to true. - */ - postUpdate: function () { - }, - - /** - * Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run. - * It is only called if visible is set to true. - */ - preRender: function () { - }, - - /** - * Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run. + * Render is called right after the Game Renderer completes, but before the State.render. * It is only called if visible is set to true. */ render: function () { }, /** - * Post-render is called after every camera and game object has been rendered, also after any custom postRender callbacks have been run. + * Post-render is called after the Game Renderer and State.render have run. * It is only called if visible is set to true. */ postRender: function () { diff --git a/src/core/PluginManager.js b/src/core/PluginManager.js index 2cf2cc9c..a4074f7a 100644 --- a/src/core/PluginManager.js +++ b/src/core/PluginManager.js @@ -36,52 +36,45 @@ Phaser.PluginManager.prototype = { } // Check for methods now to avoid having to do this every loop - if (typeof plugin['preUpdate'] === 'function') { + if (typeof plugin['preUpdate'] === 'function') + { plugin.hasPreUpdate = true; result = true; } - if (typeof plugin['update'] === 'function') { + if (typeof plugin['update'] === 'function') + { plugin.hasUpdate = true; result = true; } - if (typeof plugin['postUpdate'] === 'function') { - plugin.hasPostUpdate = true; - result = true; - } - - if (typeof plugin['preRender'] === 'function') { - plugin.hasPreRender = true; - result = true; - } - - if (typeof plugin['render'] === 'function') { + if (typeof plugin['render'] === 'function') + { plugin.hasRender = true; result = true; } - if (typeof plugin['postRender'] === 'function') { + if (typeof plugin['postRender'] === 'function') + { plugin.hasPostRender = true; result = true; } // The plugin must have at least one of the above functions to be added to the PluginManager. - if (result) { - - if (plugin.hasPreUpdate || plugin.hasUpdate || plugin.hasPostUpdate) + if (result) + { + if (plugin.hasPreUpdate || plugin.hasUpdate) { plugin.active = true; } - if (plugin.hasPreRender || plugin.hasRender || plugin.hasPostRender) + if (plugin.hasRender || plugin.hasPostRender) { plugin.visible = true; } this._pluginsLength = this.plugins.push(plugin); return plugin; - } else { @@ -103,8 +96,10 @@ Phaser.PluginManager.prototype = { return; } - for (this._p = 0; this._p < this._pluginsLength; this._p++) { - if (this.plugins[this._p].active && this.plugins[this._p].hasPreUpdate) { + for (this._p = 0; this._p < this._pluginsLength; this._p++) + { + if (this.plugins[this._p].active && this.plugins[this._p].hasPreUpdate) + { this.plugins[this._p].preUpdate(); } } @@ -118,44 +113,16 @@ Phaser.PluginManager.prototype = { return; } - for (this._p = 0; this._p < this._pluginsLength; this._p++) { - if (this.plugins[this._p].active && this.plugins[this._p].hasUpdate) { + for (this._p = 0; this._p < this._pluginsLength; this._p++) + { + if (this.plugins[this._p].active && this.plugins[this._p].hasUpdate) + { this.plugins[this._p].update(); } } }, - postUpdate: function () { - - if (this._pluginsLength == 0) - { - return; - } - - for (this._p = 0; this._p < this._pluginsLength; this._p++) { - if (this.plugins[this._p].active && this.plugins[this._p].hasPostUpdate) { - this.plugins[this._p].postUpdate(); - } - } - - }, - - preRender: function () { - - if (this._pluginsLength == 0) - { - return; - } - - for (this._p = 0; this._p < this._pluginsLength; this._p++) { - if (this.plugins[this._p].visible && this.plugins[this._p].hasPreRender) { - this.plugins[this._p].preRender(); - } - } - - }, - render: function () { if (this._pluginsLength == 0) @@ -163,8 +130,10 @@ Phaser.PluginManager.prototype = { return; } - for (this._p = 0; this._p < this._pluginsLength; this._p++) { - if (this.plugins[this._p].visible && this.plugins[this._p].hasRender) { + for (this._p = 0; this._p < this._pluginsLength; this._p++) + { + if (this.plugins[this._p].visible && this.plugins[this._p].hasRender) + { this.plugins[this._p].render(); } } @@ -178,9 +147,10 @@ Phaser.PluginManager.prototype = { return; } - for (this._p = 0; this._p < this._pluginsLength; this._p++) { - - if (this.plugins[this._p].visible && this.plugins[this._p].hasPostRender) { + for (this._p = 0; this._p < this._pluginsLength; this._p++) + { + if (this.plugins[this._p].visible && this.plugins[this._p].hasPostRender) + { this.plugins[this._p].postRender(); } } diff --git a/src/gameobjects/Bullet.js b/src/gameobjects/Bullet.js new file mode 100644 index 00000000..0d1d96be --- /dev/null +++ b/src/gameobjects/Bullet.js @@ -0,0 +1,364 @@ +Phaser.Bullet = function (game, x, y, key, frame) { + + x = x || 0; + y = y || 0; + key = key || null; + frame = frame || null; + + this.game = game; + + // If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all + this.exists = true; + + // This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering + this.alive = true; + + this.group = null; + + this.name = ''; + + this.renderOrderID = -1; + + // If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc. + // The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called. + this.lifespan = 0; + + this.key = key; + + if (key instanceof Phaser.RenderTexture) + { + PIXI.Sprite.call(this, key); + + this.currentFrame = this.game.cache.getTextureFrame(key.name); + } + else + { + if (key == null || this.game.cache.checkImageKey(key) == false) + { + key = '__default'; + } + + PIXI.Sprite.call(this, PIXI.TextureCache[key]); + + if (this.game.cache.isSpriteSheet(key)) + { + if (frame !== null) + { + if (typeof frame === 'string') + { + this.currentFrame = this.game.cache.getFrameByName(key, frame); + } + else + { + this.currentFrame = this.game.cache.getFrameByIndex(key, frame); + } + } + } + else + { + this.currentFrame = this.game.cache.getFrame(key); + } + } + + /** + * The anchor sets the origin point of the texture. + * The default is 0,0 this means the textures origin is the top left + * Setting than anchor to 0.5,0.5 means the textures origin is centered + * Setting the anchor to 1,1 would mean the textures origin points will be the bottom right + * + * @property anchor + * @type Point + */ + this.anchor = new Phaser.Point(); + + this.x = x; + this.y = y; + + this.position.x = x; + this.position.y = y; + + /** + * Should this Sprite be automatically culled if out of range of the camera? + * A culled sprite has its visible property set to 'false'. + * Note that this check doesn't look at this Sprites children, which may still be in camera range. + * So you should set autoCull to false if the Sprite will have children likely to still be in camera range. + * + * @property autoCull + * @type Boolean + */ + this.autoCull = false; + + // Replaces the PIXI.Point with a slightly more flexible one + this.scale = new Phaser.Point(1, 1); + + // Influence of camera movement upon the position + this.scrollFactor = new Phaser.Point(1, 1); + + // A mini cache for storing all of the calculated values + this._cache = { + + dirty: false, + + // Transform cache + a00: 1, a01: 0, a02: x, a10: 0, a11: 1, a12: y, id: 1, + + // Input specific transform cache + i01: 0, i10: 0, idi: 1, + + // Bounds check + left: null, right: null, top: null, bottom: null, + + // The previous calculated position inc. camera x/y and scrollFactor + x: -1, y: -1, + + // The actual scale values based on the worldTransform + scaleX: 1, scaleY: 1, + + // The width/height of the image, based on the un-modified frame size multiplied by the final calculated scale size + width: this.currentFrame.sourceSizeW, height: this.currentFrame.sourceSizeH, + + // The actual width/height of the image if from a trimmed atlas, multiplied by the final calculated scale size + halfWidth: Math.floor(this.currentFrame.sourceSizeW / 2), halfHeight: Math.floor(this.currentFrame.sourceSizeH / 2), + + // The current frame details + frameID: this.currentFrame.uuid, frameWidth: this.currentFrame.width, frameHeight: this.currentFrame.height, + + boundsX: 0, boundsY: 0, + + // If this sprite visible to the camera (regardless of being set to visible or not) + cameraVisible: true + + }; + + this.bounds = new Phaser.Rectangle(x, y, this.currentFrame.sourceSizeW, this.currentFrame.sourceSizeH); + + // Set-up the physics body + this.body = new Phaser.Physics.Arcade.Body(this); + + // World bounds check + this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds); + this.inWorldThreshold = 0; + this._outOfBoundsFired = false; + +}; + +// Needed to keep the PIXI.Sprite constructor in the prototype chain (as the core pixi renderer uses an instanceof check sadly) +Phaser.Bullet.prototype = Object.create(PIXI.Sprite.prototype); +Phaser.Bullet.prototype.constructor = Phaser.Bullet; + +/** + * Automatically called by World.update. You can create your own update in Objects that extend Phaser.Bullet. + */ +Phaser.Bullet.prototype.preUpdate = function() { + + if (!this.exists) + { + this.renderOrderID = -1; + return; + } + + if (this.lifespan > 0) + { + this.lifespan -= this.game.time.elapsed; + + if (this.lifespan <= 0) + { + this.kill(); + return; + } + } + + // this._cache.dirty = false; + + this._cache.x = this.x - (this.game.world.camera.x * this.scrollFactor.x); + this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y); + + // If this sprite or the camera have moved then let's update everything + if (this.position.x != this._cache.x || this.position.y != this._cache.y) + { + this.position.x = this._cache.x; + this.position.y = this._cache.y; + // this._cache.dirty = true; + } + + if (this.visible) + { + this.renderOrderID = this.game.world.currentRenderOrderID++; + + /* + + // Only update the values we need + if (this.worldTransform[0] != this._cache.a00 || this.worldTransform[1] != this._cache.a01) + { + this._cache.a00 = this.worldTransform[0]; // scaleX a + this._cache.a01 = this.worldTransform[1]; // skewY c + this._cache.i01 = this.worldTransform[1]; // skewY c + this._cache.scaleX = Math.sqrt((this._cache.a00 * this._cache.a00) + (this._cache.a01 * this._cache.a01)); // round this off a bit? + this._cache.a01 *= -1; + this._cache.dirty = true; + } + + // Need to test, but probably highly unlikely that a scaleX would happen without effecting the Y skew + if (this.worldTransform[3] != this._cache.a10 || this.worldTransform[4] != this._cache.a11) + { + this._cache.a10 = this.worldTransform[3]; // skewX b + this._cache.i10 = this.worldTransform[3]; // skewX b + this._cache.a11 = this.worldTransform[4]; // scaleY d + this._cache.scaleY = Math.sqrt((this._cache.a10 * this._cache.a10) + (this._cache.a11 * this._cache.a11)); // round this off a bit? + this._cache.a10 *= -1; + this._cache.dirty = true; + } + + if (this.worldTransform[2] != this._cache.a02 || this.worldTransform[5] != this._cache.a12) + { + this._cache.a02 = this.worldTransform[2]; // translateX tx + this._cache.a12 = this.worldTransform[5]; // translateY ty + this._cache.dirty = true; + } + + if (this._cache.dirty) + { + this._cache.width = Math.floor(this.currentFrame.sourceSizeW * this._cache.scaleX); + this._cache.height = Math.floor(this.currentFrame.sourceSizeH * this._cache.scaleY); + this._cache.halfWidth = Math.floor(this._cache.width / 2); + this._cache.halfHeight = Math.floor(this._cache.height / 2); + + this._cache.id = 1 / (this._cache.a00 * this._cache.a11 + this._cache.a01 * -this._cache.a10); + this._cache.idi = 1 / (this._cache.a00 * this._cache.a11 + this._cache.i01 * -this._cache.i10); + + this.updateBounds(); + } + */ + } + else + { + // We still need to work out the bounds in case the camera has moved + // but we can't use the local or worldTransform to do it, as Pixi resets that if a Sprite is invisible. + // So we'll compare against the cached state + new position. + if (this._cache.dirty && this.visible == false) + { + this.bounds.x -= this._cache.boundsX - this._cache.x; + this._cache.boundsX = this._cache.x; + + this.bounds.y -= this._cache.boundsy - this._cache.y; + this._cache.boundsY = this._cache.y; + } + } + + // Re-run the camera visibility check + // if (this._cache.dirty) + // { + this._cache.cameraVisible = Phaser.Rectangle.intersects(this.game.world.camera.screenView, this.bounds, 0); + + if (this.autoCull == true) + { + this.visible = this._cache.cameraVisible; + } + + // Update our physics bounds + this.body.updateBounds(this.center.x, this.center.y, this._cache.scaleX, this._cache.scaleY); + // } + + this.body.update(); + +} + +Phaser.Bullet.prototype.revive = function() { + + this.alive = true; + this.exists = true; + this.visible = true; + // this.events.onRevived.dispatch(this); + +} + +Phaser.Bullet.prototype.kill = function() { + + this.alive = false; + this.exists = false; + this.visible = false; + // this.events.onKilled.dispatch(this); + +} + +Phaser.Bullet.prototype.reset = function(x, y) { + + this.x = x; + this.y = y; + this.position.x = x; + this.position.y = y; + this.alive = true; + this.exists = true; + this.visible = true; + this._outOfBoundsFired = false; + this.body.reset(); + +} + +Phaser.Bullet.prototype.updateBounds = function() { + + // Update the edge points + + // this.bounds.setTo(this._cache.left, this._cache.top, this._cache.right - this._cache.left, this._cache.bottom - this._cache.top); + + if (this.inWorld == false) + { + // Sprite WAS out of the screen, is it still? + this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds, this.inWorldThreshold); + + if (this.inWorld) + { + // It's back again, reset the OOB check + this._outOfBoundsFired = false; + } + } + else + { + // Sprite WAS in the screen, has it now left? + this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds, this.inWorldThreshold); + + if (this.inWorld == false) + { + this.events.onOutOfBounds.dispatch(this); + this._outOfBoundsFired = true; + } + } + +} + +Phaser.Bullet.prototype.bringToTop = function() { + + if (this.group) + { + this.group.bringToTop(this); + } + else + { + this.game.world.bringToTop(this); + } + +} + +Object.defineProperty(Phaser.Bullet.prototype, 'angle', { + + get: function() { + return Phaser.Math.radToDeg(this.rotation); + }, + + set: function(value) { + this.rotation = Phaser.Math.degToRad(value); + } + +}); + +Object.defineProperty(Phaser.Bullet.prototype, "inCamera", { + + /** + * Is this sprite visible to the camera or not? + */ + get: function () { + return this._cache.cameraVisible; + } + +}); + diff --git a/src/loader/Cache.js b/src/loader/Cache.js index 89c1f70d..86627538 100644 --- a/src/loader/Cache.js +++ b/src/loader/Cache.js @@ -330,6 +330,36 @@ Phaser.Cache.prototype = { return null; }, + /** + * Get a single frame out of a frameData set by key. + * @param key Asset key of the frame data you want. + * @return {object} The frame data you want. + */ + getFrameByIndex: function (key, frame) { + + if (this._images[key] && this._images[key].frameData) + { + return this._images[key].frameData.getFrame(frame); + } + + return null; + }, + + /** + * Get a single frame out of a frameData set by key. + * @param key Asset key of the frame data you want. + * @return {object} The frame data you want. + */ + getFrameByName: function (key, frame) { + + if (this._images[key] && this._images[key].frameData) + { + return this._images[key].frameData.getFrameByName(frame); + } + + return null; + }, + /** * Get a single frame by key. You'd only do this to get the default Frame created for a non-atlas/spritesheet image. * @param key Asset key of the frame data you want.