├── .gitignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── lib ├── flixel-v2.55.swc ├── neoart-flectrum-v1.0.swc └── neoart-flod-v2.0.swc └── src └── org └── flixel └── plugin └── photonstorm ├── API └── FlxKongregate.as ├── BaseTypes ├── Bullet.as └── MouseSpring.as ├── FX ├── BaseFX.as ├── BlurFX.as ├── CenterSlideFX.as ├── FloodFillFX.as ├── GlitchFX.as ├── PlasmaFX.as ├── RainbowLineFX.as ├── RevealFX.as ├── SineWaveFX.as ├── StarfieldFX.as └── WowCopperFX.as ├── FlxBar.as ├── FlxBitmapFont.as ├── FlxButtonPlus.as ├── FlxCollision.as ├── FlxColor.as ├── FlxControl.as ├── FlxControlHandler.as ├── FlxCoreUtils.as ├── FlxDelay.as ├── FlxDisplay.as ├── FlxExplode.as ├── FlxExtendedSprite.as ├── FlxFlectrum.as ├── FlxFlod.as ├── FlxGradient.as ├── FlxGridOverlay.as ├── FlxLinkedGroup.as ├── FlxMath.as ├── FlxMouseControl.as ├── FlxPowerTools.as ├── FlxScreenGrab.as ├── FlxScrollZone.as ├── FlxScrollingText.as ├── FlxSpecialFX.as ├── FlxVelocity.as ├── FlxWeapon.as └── PNGEncoder.as /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | ### ACTIONSCRIPT ### 3 | 4 | # Build and Release Folders 5 | bin/ 6 | bin-debug/ 7 | bin-release/ 8 | 9 | # Project property files 10 | .actionScriptProperties 11 | .flexProperties 12 | .settings/ 13 | .project 14 | 15 | 16 | ### OS SPECIAL FILES ### 17 | 18 | # Windows 19 | Thumbs.db 20 | ehthumbs.db 21 | Desktop.ini 22 | $RECYCLE.BIN/ 23 | 24 | # OSX (MAC) 25 | .DS_Store 26 | .AppleDouble 27 | .LSOverride 28 | Icon 29 | ._* 30 | .Spotlight-V100 31 | .Trashes 32 | 33 | # Linux 34 | .* 35 | !.gitignore 36 | *~ 37 | 38 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## v1.9 Released ## 2 | 3 | #### 10th October 2011 4 | 5 | FlxBar - v1.6 Lots of bug fixes, more documentation, 2 new test cases, ability to set currentValue added 6 | 7 | #### 9th October 2011 8 | 9 | FlxCollision - v1.6 Fixed bug in pixelPerfectCheck that stopped non-square rotated objects from colliding properly (thanks to joon on the flixel forums for spotting) 10 | FlxWeapon - v1.3 Added bullet elasticity and bulletsFired counter 11 | 12 | #### 15th August 2011 13 | 14 | FlxWeapon - v1.2 Added useParentDirection boolean 15 | FlxControlHandler - v1.8 Added isPressedUp/Down/Left/Right handlers 16 | FlxVelocity - v1.6 New Method: velocityFromFacing 17 | 18 | #### 11th August 2011 19 | 20 | Created WeaponTest9 - destructable terrain 21 | 22 | #### 8th August 2011 23 | 24 | GlitchFX - v1.2 Fixed updateFromSource github issue #8 (thanks CoderBrandon) 25 | FlxControlHandler - v1.7 Modified update function so gravity is applied constantly 26 | Several new demos created 27 | 28 | #### 4th August 2011 29 | 30 | FlxCoreUtils - v1.1 Added get mouseIndex and gameContainer 31 | FlxColor - v1.5 Added RGBtoWebString 32 | 33 | #### 3rd August 2011 34 | 35 | FlxWeapon - v1.1 Added pre-fire, fire and post-fire callbacks and sound support, rnd factors, boolean returns and currentBullet 36 | Bullet - v1.1 Updated to support fire callbacks, sounds, random variances and lifespan 37 | FlxKongregate - v1.0 First release 38 | 39 | 40 | ## v1.8 Released ## 41 | 42 | #### 31st July 2011 43 | 44 | FlxDelay - v1.4 Modified abort so it no longer runs the stop callback (thanks to Cambrian-Man) 45 | 46 | #### 29th July 2011 47 | 48 | FlxFlod : Added full FlxFlectrum support 49 | FlxFlectrum - new class 50 | 51 | #### 28th July 2011 52 | 53 | FlxExtendedSprite : Added Gravity, Friction and Tolerance support 54 | FlxButtonPlus : Added scrollFactor to buttonNormal and buttonHighlight 55 | 56 | #### 27th July 2011 57 | 58 | Added createCameraWall to FlxCollision and created lots more tests 59 | FlxMouseControl: Added Mouse Zone, Mouse Speed and refactored addToStack process 60 | 61 | #### 21st July 2011 62 | 63 | FlxMouseControl and FlxExtendedSprite given a serious overhaul and now provide for totally draggable sprites! 64 | 65 | #### 21st June 2011 66 | 67 | Added support for fixed widths in FlxBitmapFont, and the ability to align the text left/right/center within that width. 68 | Updated BitmapFontTest3 to demonstrate this. 69 | 70 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Simplified BSD License 2 | ====================== 3 | 4 | Copyright © 2011, Richard Davey 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | The views and conclusions contained in the software and documentation are those 28 | of the authors and should not be interpreted as representing official policies, 29 | either expressed or implied, of the FreeBSD Project. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Flixel Power Tools 2 | ================== 3 | 4 | Version 1.9 (final release) 5 | 6 | November 28th 2013 7 | 8 | By Richard Davey, [Photon Storm](http://www.photonstorm.com) 9 | 10 | The [Flixel Power Tools](http://www.photonstorm.com/flixel-power-tools) are a package 11 | of classes designed to provide extra functionality to your Flixel 2.5+ games. 12 | 13 | 14 | Quick Install Guide 15 | ------------------- 16 | 17 | Copy the `src` and `lib` folders into your ActionScript project. All the classes for Flixel Power Tools should be contained in 18 | 19 | src/org/flixel/plugin/photonstorm 20 | 21 | Now read the "Getting Started Guide" in the `Docs` folder; it contains important information that will 22 | help you compile! 23 | 24 | 25 | Getting Started Guide 26 | --------------------- 27 | 28 | There is a comprehensive Getting Started Guide in both Word and PDF format in the `Docs` branch: 29 | 30 | https://github.com/FlixelCommunity/Flixel-Power-Tools/tree/docs 31 | 32 | Documentation is also provided built-in to the classes. AS3 IDEs such as FlashDevelop will 33 | provide context-sensitive help for all classes and functions in the Flixel Power Tools. 34 | 35 | Finally check out the home page at http://www.photonstorm.com/flixel-power-tools for updates. 36 | 37 | 38 | Test Suite 39 | ---------- 40 | 41 | Get the full Test Suite from here: 42 | 43 | https://github.com/FlixelCommunity/Flixel-Power-Tools/tree/test-suite 44 | 45 | The Flixel Power Tools come with a comprehensive Test Suite. Use it to visually see the 46 | tools in action, and then learn from the source code and comments within. 47 | 48 | To run the Test Suite launch the following SWF: 49 | 50 | Test Suite/bin/FlixelPowerTools.swf 51 | 52 | If you don't have Flash Player installed locally then open `index.html` in a browser. 53 | 54 | 55 | Classes 56 | ------- 57 | 58 | The following classes are currently in the Flixel Power Tools: 59 | 60 | * FlxBar 61 | * FlxBitmapFont 62 | * FlxButtonPlus 63 | * FlxCollision 64 | * FlxColor 65 | * FlxControl (includes FlxControlHandler) 66 | * FlxCoreUtils 67 | * FlxDelay 68 | * FlxDisplay 69 | * FlxExtendedSprite 70 | * FlxFlod (includes FlxFlectrum) 71 | * FlxGradient 72 | * FlxGridOverlay 73 | * FlxLinkedGroup 74 | * FlxMath 75 | * FlxMouseControl 76 | * FlxScreenGrab 77 | * FlxScrollingText 78 | * FlxScrollZone 79 | * FlxSpecialFX 80 | * FlxVelocity 81 | * FlxWeapon 82 | 83 | APIs Include 84 | 85 | * FlxKongregate 86 | 87 | Special FX Includes 88 | 89 | * BlurFX 90 | * CenterSlideFX 91 | * FloodFillFX 92 | * GlitchFX 93 | * PlasmaFX 94 | * RainbowLineFX 95 | * RevealFX 96 | * SineWaveFX 97 | * StarfieldFX 98 | 99 | Contributing 100 | ------------ 101 | 102 | I'm afraid that the Flixel Power Tools are no longer maintained by myself. I have moved on to [other things](http://phaser.io). 103 | 104 | I would strongly suggest you start using the [Flixel Commmunity](https://github.com/FlixelCommunity) version of Flixel which contains updated versions of these tools. 105 | 106 | License 107 | ------- 108 | 109 | Copyright 2011 Richard Davey. All rights reserved. 110 | 111 | Redistribution and use in source and binary forms, with or without modification, are 112 | permitted provided that the following conditions are met: 113 | 114 | 1. Redistributions of source code must retain the above copyright notice, this list of 115 | conditions and the following disclaimer. 116 | 117 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 118 | of conditions and the following disclaimer in the documentation and/or other materials 119 | provided with the distribution. 120 | 121 | THIS SOFTWARE IS PROVIDED BY RICHARD DAVEY ``AS IS'' AND ANY EXPRESS OR IMPLIED 122 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 123 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RICHARD DAVEY OR 124 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 125 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 126 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 127 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 128 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 129 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 130 | 131 | The views and conclusions contained in the software and documentation are those of the 132 | authors and should not be interpreted as representing official policies, either expressed 133 | or implied, of the FreeBSD Project. 134 | 135 | [1]: https://github.com/photonstorm/Flixel-Power-Tools/issues 136 | [fpt]: https://github.com/photonstorm/Flixel-Power-Tools 137 | [ff]: http://flixel.org/forums/ 138 | -------------------------------------------------------------------------------- /lib/flixel-v2.55.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/photonstorm/Flixel-Power-Tools/0a37c8e7a3c6133adef1ab090cac5e60e3939133/lib/flixel-v2.55.swc -------------------------------------------------------------------------------- /lib/neoart-flectrum-v1.0.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/photonstorm/Flixel-Power-Tools/0a37c8e7a3c6133adef1ab090cac5e60e3939133/lib/neoart-flectrum-v1.0.swc -------------------------------------------------------------------------------- /lib/neoart-flod-v2.0.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/photonstorm/Flixel-Power-Tools/0a37c8e7a3c6133adef1ab090cac5e60e3939133/lib/neoart-flod-v2.0.swc -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/API/FlxKongregate.as: -------------------------------------------------------------------------------- 1 | /** 2 | * FlxKongregate 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.0 First release 6 | * 7 | * @version 1.0 - August 1st 2011 8 | * @link http://www.photonstorm.com 9 | * @author Richard Davey / Photon Storm 10 | */ 11 | 12 | package org.flixel.plugin.photonstorm.API 13 | { 14 | import flash.display.DisplayObject; 15 | import flash.display.Loader; 16 | import flash.errors.IOError; 17 | import flash.events.Event; 18 | import flash.events.IOErrorEvent; 19 | import flash.net.URLRequest; 20 | import flash.system.Security; 21 | 22 | import org.flixel.*; 23 | 24 | /** 25 | * Allows for easy access to the Kongregate API 26 | * 27 | * Todo: Add in the functions for Chat Integration - you can still use them via the FlxKongregate.api object. 28 | */ 29 | public class FlxKongregate 30 | { 31 | /** 32 | * The Kongregate API object. You can make calls directly to this once the API has connected. 33 | */ 34 | public static var api:*; 35 | 36 | /** 37 | * true if the API has loaded otherwise false. Loaded is not the same thing as connected, it just means it's ready for the connection. 38 | */ 39 | public static var hasLoaded:Boolean = false; 40 | 41 | /** 42 | * Is the game running locally in Shadow API mode (true) or from Kongregates servers (false) 43 | */ 44 | public static var isLocal:Boolean = false; 45 | 46 | private static var shadowAPI:String = "http://www.kongregate.com/flash/API_AS3_Local.swf"; 47 | private static var apiLoader:Loader; 48 | private static var loadCallback:Function; 49 | 50 | public function FlxKongregate() 51 | { 52 | } 53 | 54 | /** 55 | * Loads the Kongregate API and if successful connects to the service. 56 | * Note that your game must have access to Stage by this point. 57 | * 58 | * @param callback This function is called if the API loads successfully. Do not call any API function until this has happened. 59 | */ 60 | public static function init(callback:Function):void 61 | { 62 | try 63 | { 64 | var parameters:Object = FlxG.stage.loaderInfo.parameters; 65 | } 66 | catch (e:Error) 67 | { 68 | throw new Error("FlxKongregate: No access to FlxG.stage - only call this once your game has access to the display list"); 69 | return; 70 | } 71 | 72 | var apiPath:String; 73 | 74 | if (parameters.kongregate_api_path) 75 | { 76 | Security.allowDomain(parameters.kongregate_api_path); 77 | apiPath = parameters.kongregate_api_path; 78 | } 79 | else 80 | { 81 | Security.allowDomain(shadowAPI); 82 | apiPath = shadowAPI; 83 | isLocal = true; 84 | } 85 | 86 | loadCallback = callback; 87 | 88 | apiLoader = new Loader(); 89 | apiLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, apiLoadComplete, false, 0, true); 90 | apiLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, apiLoadError, false, 0, true); 91 | apiLoader.load(new URLRequest(apiPath)); 92 | 93 | FlxG.stage.addChild(apiLoader); 94 | } 95 | 96 | /** 97 | * Remove the API from memory (when possible) and removes it from the display list also 98 | */ 99 | public static function disconnect():void 100 | { 101 | api = null; 102 | 103 | hasLoaded = false; 104 | 105 | FlxG.stage.removeChild(apiLoader); 106 | } 107 | 108 | private static function apiLoadComplete(event:Event):void 109 | { 110 | api = event.target.content; 111 | 112 | hasLoaded = true; 113 | 114 | Security.allowDomain(api.loaderInfo.url); 115 | 116 | if (loadCallback is Function) 117 | { 118 | loadCallback.call(); 119 | } 120 | 121 | } 122 | 123 | private static function apiLoadError(error:IOError):void 124 | { 125 | trace("Error loading Kongregate API", error); 126 | } 127 | 128 | /** 129 | * Use the addLoadListener function to register an event listener which will be triggered when content of the specified type is loaded by the user. 130 | * These MUST be set-up *before* you call FlxKongregate.connect() 131 | * See: http://www.kongregate.com/developer_center/docs/shared-content-api 132 | * 133 | * @param contentType Type of content to listen for 134 | * @param callback Function to call when content load request has been made 135 | */ 136 | public static function addLoadListener(contentType:String, callback:Function):void 137 | { 138 | api.sharedContent.addLoadListener(contentType, callback); 139 | } 140 | 141 | /** 142 | * Register an event listener with the API. Useful for capturing guest to user login requests for example. 143 | * See: http://www.kongregate.com/developer_center/docs/handling-guests 144 | * 145 | * @param contentType The event to listen for (i.e. "login") 146 | * @param callback Funcation to call when this event is received 147 | */ 148 | public static function addEventListener(contentType:String, callback:Function):void 149 | { 150 | api.services.addEventListener(contentType, callback); 151 | } 152 | 153 | /** 154 | * Connect to the Kongregate API. This should be called only after the init callback reports a succesful load of the API 155 | */ 156 | public static function connect():void 157 | { 158 | if (hasLoaded) 159 | { 160 | api.services.connect(); 161 | } 162 | } 163 | 164 | /** 165 | * The isGuest function can be called to determine if the player is currently signed into Kongregate or not 166 | */ 167 | public static function get isGuest():Boolean 168 | { 169 | return api.services.isGuest(); 170 | } 171 | 172 | /** 173 | * You can use the getUsername() function to retrieve the username of the current player. It will begin with Guest if the user is not signed in. 174 | */ 175 | public static function get getUserName():String 176 | { 177 | return api.services.getUsername(); 178 | } 179 | 180 | /** 181 | * You can use the getUserId() function to retrieve the unique user id of the current player. It will return 0 if the user is not signed in. 182 | */ 183 | public static function get getUserId():Number 184 | { 185 | try 186 | { 187 | return api.services.getUserId(); 188 | } 189 | catch (e:Error) 190 | { 191 | return 0; 192 | } 193 | 194 | return 0; 195 | } 196 | 197 | /** 198 | * If you are using the Authentication API you can use the getGameAuthToken function to get the player's game authentication token. 199 | */ 200 | public static function get getGameAuthToken():String 201 | { 202 | return api.services.getGameAuthToken(); 203 | } 204 | 205 | /** 206 | * If the player is a guest, and you want to display the sign-in/registration UI to them you can use the showSignInBox function. 207 | */ 208 | public static function showSignInBox():void 209 | { 210 | if (api.services.isGuest()) 211 | { 212 | api.services.showSignInBox(); 213 | } 214 | } 215 | 216 | /** 217 | * This call works the same way as showSigninBox, but it focuses the registration form rather than the sign-in form. 218 | */ 219 | public static function showRegistrationBox():void 220 | { 221 | if (api.services.isGuest()) 222 | { 223 | api.services.showRegistrationBox(); 224 | } 225 | } 226 | 227 | /** 228 | * If a player is logged-in and you want to allow them to post a shout on their profile page, you may bring up the shout box, optionally populated with some initial content. 229 | * 230 | * @param message The optional initial content 231 | */ 232 | public static function showShoutBox(message:String = ""):void 233 | { 234 | if (api.services.isGuest() == false) 235 | { 236 | api.services.showShoutBox(message); 237 | } 238 | } 239 | 240 | /** 241 | * If you need to resize your game's enclosing container, you may do so with resizeGame call. The enclosing iframe will resize around your game. 242 | * Games may not be resized smaller than their initial dimensions. This call requires special permission from Kongregate to use. 243 | * 244 | * @param width New width (in pixels) of the container 245 | * @param height New height (in pixels) of the container 246 | */ 247 | public static function resizeGame(width:int, height:int):void 248 | { 249 | api.services.resizeGame(width, height); 250 | } 251 | 252 | /** 253 | * Submit a statistic to the Kongregate server. Make sure you have defined the stat before calling this. 254 | * See the Kongregate API documentation for details. 255 | * 256 | * @param name The name of the statistic 257 | * @param value The value to submit (will be converted to an integer server-side) 258 | */ 259 | public static function submitStats(name:String, value:Number):void 260 | { 261 | api.stats.submit(name, value); 262 | } 263 | 264 | /** 265 | * Bring up the "purchase items" dialog box by using the purchaseItems method on the microtransaction services object. 266 | * Your game must be in the Kongregate Microtransactions beta to use this function. 267 | * See: http://www.kongregate.com/developer_center/docs/microtransaction-client-api 268 | * 269 | * @param items The array of item identifier strings or item/metadata objects. 270 | * @param callback The callback function 271 | */ 272 | public static function purchaseItem(items:Array, callback:Function):void 273 | { 274 | api.mtx.purchaseItems(items, callback); 275 | } 276 | 277 | /** 278 | * Request the inventory of any user. 279 | * Your game must be in the Kongregate Microtransactions beta to use this function. 280 | * See: http://www.kongregate.com/developer_center/docs/microtransaction-client-api 281 | * 282 | * @param username The username to request inventory for, or null for the current player 283 | * @param callback The callback function 284 | */ 285 | public static function requestUserItemList(username:String, callback:Function):void 286 | { 287 | api.mtx.requestUserItemList(username, callback); 288 | } 289 | 290 | /** 291 | * Display the Kred purchasing Dialog. 292 | * Your game must be in the Kongregate Microtransactions beta to use this function. 293 | * See: http://www.kongregate.com/developer_center/docs/microtransaction-client-api 294 | * 295 | * @param purchaseMethod The purchase method to display. Should be "offers" or "mobile" 296 | */ 297 | public static function showKredPurchaseDialog(purchaseMethod:String):void 298 | { 299 | api.mtx.showKredPurchaseDialog(purchaseMethod); 300 | } 301 | 302 | /** 303 | * The browse function causes a list of shared content to appear in the user's browser. 304 | * This will allow them to view, rate, or load shared content for your game. 305 | * See: http://www.kongregate.com/developer_center/docs/shared-content-api 306 | * 307 | * @param contentType Type of content to browse 308 | * @param sortOrder Optional constant specifying how to sort content (see API docs) 309 | * @param label Optional, only browse content saved with the specified label 310 | */ 311 | public static function browseSharedContent(contentType:String, sortOrder:String=null, label:String=null):void 312 | { 313 | api.sharedContent.browse(contentType, sortOrder, label); 314 | } 315 | 316 | /** 317 | * Use the save function to submit shared content on the Kongregate back-end. 318 | * See: http://www.kongregate.com/developer_center/docs/shared-content-api 319 | * 320 | * @param type Type of content the user wishes to save, 12 characters max. 321 | * @param content Value of content to be saved. We strongly recommend keeping these values under 100K. 322 | * @param callback Function to call when save has finished. 323 | * @param thumb Optional but highly recommended! Send us a DisplayObject that we will snapshotted and used as a thumbnail for the content. 324 | * @param label Optional, label for sub-classing the shared content. 325 | */ 326 | public static function saveSharedContent(type:String, content:String, callback:Function, thumb:DisplayObject = null, label:String = null):void 327 | { 328 | api.sharedContent.save(type, content, callback, thumb, label); 329 | } 330 | 331 | /** 332 | * Export a DisplayObject to be converted to a user avatar. It is highly recommended that avatars be at least 40 x 40px. 333 | * See: http://www.kongregate.com/developer_center/docs/avatar-api 334 | * 335 | * @param avatar Can be null, but highly recommended that you send yourself. If null, we will snapshot the stage. 336 | * @param callback Function to call when content load request has been made 337 | */ 338 | public static function submitAvatar(avatar:DisplayObject, callback:Function):void 339 | { 340 | api.images.submitAvatar(avatar, callback); 341 | } 342 | } 343 | 344 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/BaseTypes/Bullet.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Bullet 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.2 Removed "id" and used the FlxSprite ID value instead 6 | * v1.1 Updated to support fire callbacks, sounds, random variances and lifespan 7 | * v1.0 First release 8 | * 9 | * @version 1.2 - October 10th 2011 10 | * @link http://www.photonstorm.com 11 | * @author Richard Davey / Photon Storm 12 | */ 13 | 14 | package org.flixel.plugin.photonstorm.BaseTypes 15 | { 16 | import org.flixel.FlxPoint; 17 | import org.flixel.FlxSprite; 18 | import org.flixel.plugin.photonstorm.FlxMath; 19 | import org.flixel.plugin.photonstorm.FlxVelocity; 20 | import org.flixel.plugin.photonstorm.FlxWeapon; 21 | import flash.utils.getTimer; 22 | 23 | public class Bullet extends FlxSprite 24 | { 25 | protected var weapon:FlxWeapon; 26 | 27 | protected var bulletSpeed:int; 28 | 29 | // Acceleration or Velocity? 30 | public var accelerates:Boolean; 31 | public var xAcceleration:int; 32 | public var yAcceleration:int; 33 | 34 | public var rndFactorAngle:uint; 35 | public var rndFactorSpeed:uint; 36 | public var rndFactorLifeSpan:uint; 37 | public var lifespan:uint; 38 | public var launchTime:uint; 39 | public var expiresTime:uint; 40 | 41 | protected var animated:Boolean; 42 | 43 | public function Bullet(weapon:FlxWeapon, id:uint) 44 | { 45 | super(0, 0); 46 | 47 | this.weapon = weapon; 48 | this.ID = id; 49 | 50 | // Safe defaults 51 | accelerates = false; 52 | animated = false; 53 | bulletSpeed = 0; 54 | 55 | exists = false; 56 | } 57 | 58 | /** 59 | * Adds a new animation to the sprite. 60 | * 61 | * @param Name What this animation should be called (e.g. "run"). 62 | * @param Frames An array of numbers indicating what frames to play in what order (e.g. 1, 2, 3). 63 | * @param FrameRate The speed in frames per second that the animation should play at (e.g. 40 fps). 64 | * @param Looped Whether or not the animation is looped or just plays once. 65 | */ 66 | override public function addAnimation(Name:String, Frames:Array, FrameRate:Number = 0, Looped:Boolean = true):void 67 | { 68 | super.addAnimation(Name, Frames, FrameRate, Looped); 69 | 70 | animated = true; 71 | } 72 | 73 | public function fire(fromX:int, fromY:int, velX:int, velY:int):void 74 | { 75 | x = fromX + FlxMath.rand( -weapon.rndFactorPosition.x, weapon.rndFactorPosition.x); 76 | y = fromY + FlxMath.rand( -weapon.rndFactorPosition.y, weapon.rndFactorPosition.y); 77 | 78 | if (accelerates) 79 | { 80 | acceleration.x = xAcceleration + FlxMath.rand( -weapon.rndFactorSpeed, weapon.rndFactorSpeed); 81 | acceleration.y = yAcceleration + FlxMath.rand( -weapon.rndFactorSpeed, weapon.rndFactorSpeed); 82 | } 83 | else 84 | { 85 | velocity.x = velX + FlxMath.rand( -weapon.rndFactorSpeed, weapon.rndFactorSpeed); 86 | velocity.y = velY + FlxMath.rand( -weapon.rndFactorSpeed, weapon.rndFactorSpeed); 87 | } 88 | 89 | postFire(); 90 | } 91 | 92 | public function fireAtMouse(fromX:int, fromY:int, speed:int):void 93 | { 94 | x = fromX + FlxMath.rand( -weapon.rndFactorPosition.x, weapon.rndFactorPosition.x); 95 | y = fromY + FlxMath.rand( -weapon.rndFactorPosition.y, weapon.rndFactorPosition.y); 96 | 97 | if (accelerates) 98 | { 99 | FlxVelocity.accelerateTowardsMouse(this, speed + FlxMath.rand( -weapon.rndFactorSpeed, weapon.rndFactorSpeed), maxVelocity.x, maxVelocity.y); 100 | } 101 | else 102 | { 103 | FlxVelocity.moveTowardsMouse(this, speed + FlxMath.rand( -weapon.rndFactorSpeed, weapon.rndFactorSpeed)); 104 | } 105 | 106 | postFire(); 107 | } 108 | 109 | public function fireAtPosition(fromX:int, fromY:int, toX:int, toY:int, speed:int):void 110 | { 111 | x = fromX + FlxMath.rand( -weapon.rndFactorPosition.x, weapon.rndFactorPosition.x); 112 | y = fromY + FlxMath.rand( -weapon.rndFactorPosition.y, weapon.rndFactorPosition.y); 113 | 114 | if (accelerates) 115 | { 116 | FlxVelocity.accelerateTowardsPoint(this, new FlxPoint(toX, toY), speed + FlxMath.rand( -weapon.rndFactorSpeed, weapon.rndFactorSpeed), maxVelocity.x, maxVelocity.y); 117 | } 118 | else 119 | { 120 | FlxVelocity.moveTowardsPoint(this, new FlxPoint(toX, toY), speed + FlxMath.rand( -weapon.rndFactorSpeed, weapon.rndFactorSpeed)); 121 | } 122 | 123 | postFire(); 124 | } 125 | 126 | public function fireAtTarget(fromX:int, fromY:int, target:FlxSprite, speed:int):void 127 | { 128 | x = fromX + FlxMath.rand( -weapon.rndFactorPosition.x, weapon.rndFactorPosition.x); 129 | y = fromY + FlxMath.rand( -weapon.rndFactorPosition.y, weapon.rndFactorPosition.y); 130 | 131 | if (accelerates) 132 | { 133 | FlxVelocity.accelerateTowardsObject(this, target, speed + FlxMath.rand( -weapon.rndFactorSpeed, weapon.rndFactorSpeed), maxVelocity.x, maxVelocity.y); 134 | } 135 | else 136 | { 137 | FlxVelocity.moveTowardsObject(this, target, speed + FlxMath.rand( -weapon.rndFactorSpeed, weapon.rndFactorSpeed)); 138 | } 139 | 140 | postFire(); 141 | } 142 | 143 | public function fireFromAngle(fromX:int, fromY:int, fireAngle:int, speed:int):void 144 | { 145 | x = fromX + FlxMath.rand( -weapon.rndFactorPosition.x, weapon.rndFactorPosition.x); 146 | y = fromY + FlxMath.rand( -weapon.rndFactorPosition.y, weapon.rndFactorPosition.y); 147 | 148 | var newVelocity:FlxPoint = FlxVelocity.velocityFromAngle(fireAngle + FlxMath.rand( -weapon.rndFactorAngle, weapon.rndFactorAngle), speed + FlxMath.rand( -weapon.rndFactorSpeed, weapon.rndFactorSpeed)); 149 | 150 | if (accelerates) 151 | { 152 | acceleration.x = newVelocity.x; 153 | acceleration.y = newVelocity.y; 154 | } 155 | else 156 | { 157 | velocity.x = newVelocity.x; 158 | velocity.y = newVelocity.y; 159 | } 160 | 161 | postFire(); 162 | } 163 | 164 | private function postFire():void 165 | { 166 | if (animated) 167 | { 168 | play("fire"); 169 | } 170 | 171 | if (weapon.bulletElasticity > 0) 172 | { 173 | elasticity = weapon.bulletElasticity; 174 | } 175 | 176 | exists = true; 177 | 178 | launchTime = getTimer(); 179 | 180 | if (weapon.bulletLifeSpan > 0) 181 | { 182 | lifespan = weapon.bulletLifeSpan + FlxMath.rand( -weapon.rndFactorLifeSpan, weapon.rndFactorLifeSpan); 183 | expiresTime = getTimer() + lifespan; 184 | } 185 | 186 | if (weapon.onFireCallback is Function) 187 | { 188 | weapon.onFireCallback.apply(); 189 | } 190 | 191 | if (weapon.onFireSound) 192 | { 193 | weapon.onFireSound.play(); 194 | } 195 | } 196 | 197 | public function set xGravity(gx:int):void 198 | { 199 | acceleration.x = gx; 200 | } 201 | 202 | public function set yGravity(gy:int):void 203 | { 204 | acceleration.y = gy; 205 | } 206 | 207 | public function set maxVelocityX(mx:int):void 208 | { 209 | maxVelocity.x = mx; 210 | } 211 | 212 | public function set maxVelocityY(my:int):void 213 | { 214 | maxVelocity.y = my; 215 | } 216 | 217 | override public function update():void 218 | { 219 | if (lifespan > 0 && getTimer() > expiresTime) 220 | { 221 | kill(); 222 | } 223 | 224 | if (FlxMath.pointInFlxRect(x, y, weapon.bounds) == false) 225 | { 226 | kill(); 227 | } 228 | } 229 | 230 | } 231 | 232 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/BaseTypes/MouseSpring.as: -------------------------------------------------------------------------------- 1 | package org.flixel.plugin.photonstorm.BaseTypes 2 | { 3 | import org.flixel.*; 4 | import org.flixel.plugin.photonstorm.FlxExtendedSprite; 5 | 6 | public class MouseSpring 7 | { 8 | public var sprite:FlxExtendedSprite; 9 | 10 | /** 11 | * The tension of the spring, smaller numbers create springs closer to the mouse pointer 12 | * @default 0.1 13 | */ 14 | public var tension:Number = 0.1; 15 | 16 | /** 17 | * The friction applied to the spring as it moves 18 | * @default 0.95 19 | */ 20 | public var friction:Number = 0.95; 21 | 22 | /** 23 | * The gravity controls how far "down" the spring hangs (use a negative value for it to hang up!) 24 | * @default 0 25 | */ 26 | public var gravity:Number = 0; 27 | 28 | private var retainVelocity:Boolean = false; 29 | 30 | private var vx:Number = 0; 31 | private var vy:Number = 0; 32 | 33 | private var dx:Number = 0; 34 | private var dy:Number = 0; 35 | 36 | private var ax:Number = 0; 37 | private var ay:Number = 0; 38 | 39 | /** 40 | * Adds a spring between the mouse and a Sprite. 41 | * 42 | * @param sprite The FlxExtendedSprite to which this spring is attached 43 | * @param retainVelocity true to retain the velocity of the spring when the mouse is released, or false to clear it 44 | * @param tension The tension of the spring, smaller numbers create springs closer to the mouse pointer 45 | * @param friction The friction applied to the spring as it moves 46 | * @param gravity The gravity controls how far "down" the spring hangs (use a negative value for it to hang up!) 47 | */ 48 | public function MouseSpring(sprite:FlxExtendedSprite, retainVelocity:Boolean = false, tension:Number = 0.1, friction:Number = 0.95, gravity:Number = 0) 49 | { 50 | this.sprite = sprite; 51 | this.retainVelocity = retainVelocity; 52 | this.tension = tension; 53 | this.friction = friction; 54 | this.gravity = gravity; 55 | } 56 | 57 | /** 58 | * Updates the spring physics and repositions the sprite 59 | */ 60 | public function update():void 61 | { 62 | dx = FlxG.mouse.x - sprite.springX; 63 | dy = FlxG.mouse.y - sprite.springY; 64 | 65 | ax = dx * tension; 66 | ay = dy * tension; 67 | 68 | vx += ax; 69 | vy += ay; 70 | 71 | vy += gravity; 72 | vx *= friction; 73 | vy *= friction; 74 | 75 | sprite.x += vx; 76 | sprite.y += vy; 77 | } 78 | 79 | /** 80 | * Resets the internal spring physics 81 | */ 82 | public function reset():void 83 | { 84 | vx = 0; 85 | vy = 0; 86 | 87 | dx = 0; 88 | dy = 0; 89 | 90 | ax = 0; 91 | ay = 0; 92 | } 93 | 94 | } 95 | 96 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FX/BaseFX.as: -------------------------------------------------------------------------------- 1 | /** 2 | * BaseFX - Special FX Plugin 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.1 Fixed some documentation 6 | * v1.0 First release 7 | * 8 | * @version 1.1 - June 10th 2011 9 | * @link http://www.photonstorm.com 10 | * @author Richard Davey / Photon Storm 11 | */ 12 | 13 | package org.flixel.plugin.photonstorm.FX 14 | { 15 | import flash.geom.Point; 16 | import flash.geom.Rectangle; 17 | import org.flixel.FlxSprite; 18 | import flash.display.BitmapData; 19 | 20 | public class BaseFX 21 | { 22 | /** 23 | * Set to false to stop this effect being updated by the FlxSpecialFX Plugin. Set to true to enable. 24 | */ 25 | public var active:Boolean; 26 | 27 | /** 28 | * The FlxSprite into which the effect is drawn. Add this to your FlxState / FlxGroup to display the effect. 29 | */ 30 | public var sprite:FlxSprite; 31 | 32 | /** 33 | * A scratch bitmapData used to build-up the effect before passing to sprite.pixels 34 | */ 35 | internal var canvas:BitmapData; 36 | 37 | /** 38 | * TODO A snapshot of the sprite background before the effect is applied 39 | */ 40 | internal var back:BitmapData; 41 | 42 | internal var image:BitmapData; 43 | internal var sourceRef:FlxSprite; 44 | internal var updateFromSource:Boolean; 45 | internal var clsRect:Rectangle; 46 | internal var clsPoint:Point; 47 | internal var clsColor:uint; 48 | 49 | // For staggered drawing updates 50 | internal var updateLimit:uint = 0; 51 | internal var lastUpdate:uint = 0; 52 | internal var ready:Boolean = false; 53 | 54 | internal var copyRect:Rectangle; 55 | internal var copyPoint:Point; 56 | 57 | public function BaseFX() 58 | { 59 | active = false; 60 | } 61 | 62 | /** 63 | * Starts the effect runnning 64 | * 65 | * @param delay How many "game updates" should pass between each update? If your game runs at 30fps a value of 0 means it will do 30 updates per second. A value of 1 means it will do 15 updates per second, etc. 66 | */ 67 | public function start(delay:uint = 0):void 68 | { 69 | updateLimit = delay; 70 | lastUpdate = 0; 71 | ready = true; 72 | } 73 | 74 | /** 75 | * Pauses the effect from running. The draw function is still called each loop, but the pixel data is stopped from updating.
76 | * To disable the SpecialFX Plugin from calling the FX at all set the "active" parameter to false. 77 | */ 78 | public function stop():void 79 | { 80 | ready = false; 81 | } 82 | 83 | public function destroy():void 84 | { 85 | if (sprite) 86 | { 87 | sprite.kill(); 88 | } 89 | 90 | if (canvas) 91 | { 92 | canvas.dispose(); 93 | } 94 | 95 | if (back) 96 | { 97 | back.dispose(); 98 | } 99 | 100 | if (image) 101 | { 102 | image.dispose(); 103 | } 104 | 105 | sourceRef = null; 106 | 107 | active = false; 108 | } 109 | 110 | } 111 | 112 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FX/BlurFX.as: -------------------------------------------------------------------------------- 1 | /** 2 | * BlurFX - Special FX Plugin 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.0 First release 6 | * 7 | * @version 1.0 - June 10th 2011 8 | * @link http://www.photonstorm.com 9 | * @author Richard Davey / Photon Storm 10 | */ 11 | 12 | package org.flixel.plugin.photonstorm.FX 13 | { 14 | import flash.display.BitmapData; 15 | import flash.geom.Point; 16 | import flash.geom.Rectangle; 17 | import flash.utils.Dictionary; 18 | import flash.filters.BlurFilter; 19 | 20 | import org.flixel.*; 21 | import org.flixel.plugin.photonstorm.*; 22 | 23 | /** 24 | * Creates a blur effect 25 | */ 26 | public class BlurFX extends BaseFX 27 | { 28 | private var objects:Array; 29 | private var blurFilter:BlurFilter; 30 | 31 | public function BlurFX() 32 | { 33 | } 34 | 35 | /** 36 | * Creates a new BlurFX the given width/height in size.
37 | * The blur X / Y / Quality parameters all control the strength of the effect.
38 | * Add the resulting FlxSprite to your display to see the effect. 39 | * 40 | * @param width The width (in pixels) of the resulting FlxSprite containing the Blur effect 41 | * @param height The height (in pixels) of the resulting FlxSprite containing the Blur effect 42 | * @param blurX The amount of horizontal blur. 43 | * @param blurY The amount of vertical blur. 44 | * @param blurQuality The number of times to perform the blur. Default is 1 (fastest, single pass) up to a maxium of 15 (very VERY expensive!) 45 | * 46 | * @return An FlxSprite containing the updating blur effect 47 | */ 48 | public function create(width:int, height:int, blurX:Number, blurY:Number, blurQuality:int = 1):FlxSprite 49 | { 50 | sprite = new FlxSprite(0, 0).makeGraphic(width, height, 0x0, true); 51 | 52 | objects = new Array; 53 | 54 | blurFilter = new BlurFilter(blurX, blurY, blurQuality); 55 | 56 | copyPoint = new Point(0, 0); 57 | copyRect = new Rectangle(0, 0, width, height); 58 | 59 | return sprite; 60 | } 61 | 62 | /** 63 | * Adds an FlxSprite to the BlurFX. Every loop this sprite will be drawn to the FX and then blurred if the FlxSprite is both onScreen() and visible. 64 | * 65 | * @param source The FlxSprite to add to the blur effect 66 | * @param autoRemove If true and the FlxSprite.exists value ever equals false then BlurFX will automatically remove it 67 | */ 68 | public function addSprite(source:FlxSprite, autoRemove:Boolean = true):void 69 | { 70 | objects.push( { sprite: source, autoRemove: autoRemove } ); 71 | 72 | if (active == false) 73 | { 74 | active = true; 75 | } 76 | } 77 | 78 | /** 79 | * Removes the FlxSprite from the effect 80 | * 81 | * @param source The FlxSprite to remove from the blur effect 82 | */ 83 | public function removeSprite(source:FlxSprite):void 84 | { 85 | for (var i:int = 0; i < objects.length; i++) 86 | { 87 | if (objects[i].sprite == source) 88 | { 89 | objects.splice(i, 1); 90 | break; 91 | } 92 | } 93 | } 94 | 95 | public function draw():void 96 | { 97 | if (ready) 98 | { 99 | // Write every object to the canvas 100 | for each (var obj:Object in objects) 101 | { 102 | // Removal check 103 | if (obj.sprite.exists == false) 104 | { 105 | removeSprite(obj.sprite); 106 | } 107 | else 108 | { 109 | if (obj.sprite.visible && obj.sprite.onScreen()) 110 | { 111 | sprite.stamp(obj.sprite, obj.sprite.x, obj.sprite.y); 112 | } 113 | } 114 | } 115 | 116 | // We'll use the update timer to control how often the blur is run, not how often the objects are drawn 117 | if (lastUpdate != updateLimit) 118 | { 119 | lastUpdate++; 120 | 121 | return; 122 | } 123 | 124 | // Then blur it 125 | sprite.pixels.applyFilter(sprite.pixels, copyRect, copyPoint, blurFilter); 126 | 127 | lastUpdate = 0; 128 | 129 | sprite.dirty = true; 130 | } 131 | } 132 | 133 | } 134 | 135 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FX/CenterSlideFX.as: -------------------------------------------------------------------------------- 1 | /** 2 | * CenterSlideFX - Special FX Plugin 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.1 Refactored main loop a little and added reverse function 6 | * v1.0 First release 7 | * 8 | * @version 1.1 - June 13th 2011 9 | * @link http://www.photonstorm.com 10 | * @author Richard Davey / Photon Storm 11 | */ 12 | 13 | package org.flixel.plugin.photonstorm.FX 14 | { 15 | import flash.display.BitmapData; 16 | import flash.geom.Point; 17 | import flash.geom.Rectangle; 18 | 19 | import org.flixel.*; 20 | import org.flixel.plugin.photonstorm.*; 21 | 22 | /** 23 | * Makes an image expand or collapse from its center 24 | */ 25 | public class CenterSlideFX extends BaseFX 26 | { 27 | /** 28 | * True when the effect has completed. False while the effect is running. 29 | */ 30 | public var complete:Boolean; 31 | 32 | /** 33 | * A function that is called once the effect is has finished running and is complete 34 | */ 35 | public var completeCallback:Function; 36 | 37 | private var pixels:uint; 38 | private var direction:uint; 39 | 40 | private var sideA:Rectangle; 41 | private var sideB:Rectangle; 42 | private var pointA:Point; 43 | private var pointB:Point; 44 | 45 | public static const REVEAL_VERTICAL:uint = 0; 46 | public static const REVEAL_HORIZONTAL:uint = 1; 47 | public static const HIDE_VERTICAL:uint = 2; 48 | public static const HIDE_HORIZONTAL:uint = 3; 49 | 50 | public function CenterSlideFX() 51 | { 52 | } 53 | 54 | /** 55 | * Creates a new CenterSlide effect from the given FlxSprite. The original sprite remains unmodified.
56 | * The resulting FlxSprite will take on the same width / height and x/y coordinates of the source FlxSprite. 57 | * 58 | * @param source The FlxSprite providing the image data for this effect. The resulting FlxSprite takes on the source width, height and x/y position. 59 | * @param direction REVEAL_VERTICAL, REVEAL_HORIZONTAL, HIDE_VERTICAL or HIDE_HORIZONTAL 60 | * @param pixels How many pixels to slide update (default 1) 61 | * @param backgroundColor The background colour of the FlxSprite the effect is drawn in to (default 0x0 = transparent) 62 | * 63 | * @return An FlxSprite with the effect running through it, which should be started with a call to CenterSlideFX.start() 64 | */ 65 | public function createFromFlxSprite(source:FlxSprite, direction:uint = 0, pixels:uint = 1, backgroundColor:uint = 0x0):FlxSprite 66 | { 67 | return create(source.pixels, source.x, source.y, direction, pixels, backgroundColor); 68 | } 69 | 70 | /** 71 | * Creates a new CenterSlide effect from the given Class (which must contain a Bitmap) usually from an Embedded bitmap. 72 | * 73 | * @param source The Class providing the bitmapData for this effect, usually from an Embedded bitmap. 74 | * @param x The x coordinate (in game world pixels) that the resulting FlxSprite will be created at. 75 | * @param y The x coordinate (in game world pixels) that the resulting FlxSprite will be created at. 76 | * @param direction REVEAL_VERTICAL, REVEAL_HORIZONTAL, HIDE_VERTICAL or HIDE_HORIZONTAL 77 | * @param pixels How many pixels to slide update (default 1) 78 | * @param backgroundColor The background colour of the FlxSprite the effect is drawn in to (default 0x0 = transparent) 79 | * 80 | * @return An FlxSprite with the effect running through it, which should be started with a call to CenterSlideFX.start() 81 | */ 82 | public function createFromClass(source:Class, x:int, y:int, direction:uint = 0, pixels:uint = 1, backgroundColor:uint = 0x0):FlxSprite 83 | { 84 | return create((new source).bitmapData, x, y, direction, pixels, backgroundColor); 85 | } 86 | 87 | /** 88 | * Creates a new CenterSlide effect from the given bitmapData. 89 | * 90 | * @param source The bitmapData image to use for this effect. 91 | * @param x The x coordinate (in game world pixels) that the resulting FlxSprite will be created at. 92 | * @param y The x coordinate (in game world pixels) that the resulting FlxSprite will be created at. 93 | * @param direction REVEAL_VERTICAL, REVEAL_HORIZONTAL, HIDE_VERTICAL or HIDE_HORIZONTAL 94 | * @param pixels How many pixels to slide update (default 1) 95 | * @param backgroundColor The background colour of the FlxSprite the effect is drawn in to (default 0x0 = transparent) 96 | * 97 | * @return An FlxSprite with the effect running through it, which should be started with a call to CenterSlideFX.start() 98 | */ 99 | public function createFromBitmapData(source:BitmapData, x:int, y:int, direction:uint = 0, pixels:uint = 1, backgroundColor:uint = 0x0):FlxSprite 100 | { 101 | return create(source, x, y, direction, pixels, backgroundColor); 102 | } 103 | 104 | private function create(source:BitmapData, x:int, y:int, direction:uint = 0, pixels:uint = 1, backgroundColor:uint = 0x0):FlxSprite 105 | { 106 | sprite = new FlxSprite(x, y).makeGraphic(source.width, source.height, backgroundColor); 107 | 108 | canvas = new BitmapData(source.width, source.height, true, backgroundColor); 109 | 110 | image = source.clone(); 111 | 112 | clsRect = new Rectangle(0, 0, canvas.width, canvas.height); 113 | clsColor = backgroundColor; 114 | 115 | this.direction = direction; 116 | this.pixels = pixels; 117 | 118 | var midway:int = int(source.height / 2); 119 | 120 | switch (direction) 121 | { 122 | case REVEAL_VERTICAL: 123 | sideA = new Rectangle(0, 0, source.width, pixels); 124 | sideB = new Rectangle(0, source.height - pixels, source.width, pixels); 125 | pointA = new Point(0, midway); 126 | pointB = new Point(0, midway); 127 | break; 128 | 129 | case REVEAL_HORIZONTAL: 130 | midway = int(source.width / 2); 131 | sideA = new Rectangle(0, 0, pixels, source.height); 132 | sideB = new Rectangle(source.width - pixels, 0, pixels, source.height); 133 | pointA = new Point(midway, 0); 134 | pointB = new Point(midway, 0); 135 | break; 136 | 137 | case HIDE_VERTICAL: 138 | canvas = image.clone(); 139 | sprite.pixels = canvas; 140 | sprite.dirty = true; 141 | sideA = new Rectangle(0, 0, source.width, midway); 142 | sideB = new Rectangle(0, midway, source.width, source.height - midway); 143 | pointA = new Point(0, 0); 144 | pointB = new Point(0, midway); 145 | break; 146 | 147 | case HIDE_HORIZONTAL: 148 | canvas = image.clone(); 149 | sprite.pixels = canvas; 150 | sprite.dirty = true; 151 | midway = int(source.width / 2); 152 | sideA = new Rectangle(0, 0, midway, source.height); 153 | sideB = new Rectangle(midway, 0, source.width - midway, source.height); 154 | pointA = new Point(0, 0); 155 | pointB = new Point(midway, 0); 156 | break; 157 | } 158 | 159 | active = true; 160 | complete = false; 161 | 162 | return sprite; 163 | } 164 | 165 | public function reverse():void 166 | { 167 | if (direction == REVEAL_VERTICAL) 168 | { 169 | direction = HIDE_VERTICAL; 170 | complete = false; 171 | } 172 | else if (direction == REVEAL_HORIZONTAL) 173 | { 174 | direction = HIDE_HORIZONTAL; 175 | complete = false; 176 | } 177 | } 178 | 179 | public function draw():void 180 | { 181 | if (ready && complete == false) 182 | { 183 | if (lastUpdate != updateLimit) 184 | { 185 | lastUpdate++; 186 | 187 | return; 188 | } 189 | 190 | canvas.fillRect(clsRect, clsColor); 191 | canvas.copyPixels(image, sideA, pointA, null, null, true); 192 | canvas.copyPixels(image, sideB, pointB, null, null, true); 193 | 194 | switch (direction) 195 | { 196 | case REVEAL_VERTICAL: 197 | sideA.height += pixels; 198 | pointA.y -= pixels; 199 | sideB.height += pixels; 200 | sideB.y -= pixels; 201 | break; 202 | 203 | case REVEAL_HORIZONTAL: 204 | sideA.width += pixels; 205 | pointA.x -= pixels; 206 | sideB.width += pixels; 207 | sideB.x -= pixels; 208 | break; 209 | 210 | case HIDE_VERTICAL: 211 | sideA.height -= pixels; 212 | pointA.y += pixels; 213 | sideB.height -= pixels; 214 | sideB.y += pixels; 215 | break; 216 | 217 | case HIDE_HORIZONTAL: 218 | sideA.width -= pixels; 219 | pointA.x += pixels; 220 | sideB.width -= pixels; 221 | sideB.x += pixels; 222 | break; 223 | } 224 | 225 | // Are we finished? 226 | if ((direction == REVEAL_VERTICAL && pointA.y < 0) || (direction == REVEAL_HORIZONTAL && pointA.x < 0)) 227 | { 228 | canvas = image.clone(); 229 | complete = true; 230 | } 231 | else if ((direction == HIDE_VERTICAL && sideA.height <= 0) || (direction == HIDE_HORIZONTAL && sideA.width <= 0)) 232 | { 233 | canvas.fillRect(clsRect, clsColor); 234 | complete = true; 235 | } 236 | 237 | lastUpdate = 0; 238 | 239 | sprite.pixels = canvas; 240 | sprite.dirty = true; 241 | 242 | if (complete && completeCallback is Function) 243 | { 244 | completeCallback.call(); 245 | } 246 | } 247 | } 248 | 249 | } 250 | 251 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FX/FloodFillFX.as: -------------------------------------------------------------------------------- 1 | /** 2 | * FloodFillFX - Special FX Plugin 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.1 Renamed - was "DropDown", but now a more accurate "flood fill" 6 | * v1.0 First release 7 | * 8 | * @version 1.1 - May 31st 2011 9 | * @link http://www.photonstorm.com 10 | * @author Richard Davey / Photon Storm 11 | */ 12 | 13 | package org.flixel.plugin.photonstorm.FX 14 | { 15 | import flash.display.BitmapData; 16 | import flash.geom.Point; 17 | import flash.geom.Rectangle; 18 | 19 | import org.flixel.*; 20 | import org.flixel.plugin.photonstorm.*; 21 | 22 | /** 23 | * Creates a flood fill effect FlxSprite, useful for bringing in images in cool ways 24 | */ 25 | public class FloodFillFX extends BaseFX 26 | { 27 | private var complete:Boolean; 28 | private var chunk:uint; 29 | private var offset:uint; 30 | private var dropDirection:uint; 31 | private var dropRect:Rectangle; 32 | private var dropPoint:Point; 33 | private var dropY:uint; 34 | 35 | public function FloodFillFX() 36 | { 37 | } 38 | 39 | /** 40 | * Creates a new Flood Fill effect from the given image 41 | * 42 | * @param source The source image bitmapData to use for the drop 43 | * @param x The x coordinate to place the resulting effect sprite 44 | * @param y The y coordinate to place the resulting effect sprite 45 | * @param width The width of the resulting effet sprite. Doesn't have to match the source image 46 | * @param height The height of the resulting effet sprite. Doesn't have to match the source image 47 | * @param direction 0 = Top to bottom. 1 = Bottom to top. 2 = Left to Right. 3 = Right to Left. 48 | * @param pixels How many pixels to drop per update (default 1) 49 | * @param split Boolean (default false) - if split it will drop from opposite sides at the same time 50 | * @param backgroundColor The background colour of the FlxSprite the effect is drawn in to (default 0x0 = transparent) 51 | * 52 | * @return An FlxSprite with the effect ready to run in it 53 | */ 54 | public function create(source:FlxSprite, x:int, y:int, width:uint, height:uint, direction:uint = 0, pixels:uint = 1, split:Boolean = false, backgroundColor:uint = 0x0):FlxSprite 55 | { 56 | sprite = new FlxSprite(x, y).makeGraphic(width, height, backgroundColor); 57 | 58 | canvas = new BitmapData(width, height, true, backgroundColor); 59 | 60 | if (source.pixels.width != width || source.pixels.height != height) 61 | { 62 | image = new BitmapData(width, height, true, backgroundColor); 63 | image.copyPixels(source.pixels, new Rectangle(0, 0, source.pixels.width, source.pixels.height), new Point(0, height - source.pixels.height)); 64 | } 65 | else 66 | { 67 | image = source.pixels; 68 | } 69 | 70 | offset = pixels; 71 | 72 | dropDirection = direction; 73 | dropRect = new Rectangle(0, canvas.height - offset, canvas.width, offset); 74 | dropPoint = new Point(0, 0); 75 | dropY = canvas.height; 76 | 77 | active = true; 78 | 79 | return sprite; 80 | } 81 | 82 | public function draw():void 83 | { 84 | if (ready && complete == false) 85 | { 86 | if (lastUpdate != updateLimit) 87 | { 88 | lastUpdate++; 89 | 90 | return; 91 | } 92 | 93 | canvas.lock(); 94 | 95 | switch (dropDirection) 96 | { 97 | // Dropping Down 98 | case 0: 99 | 100 | // Get a pixel strip from the picture (starting at the bottom and working way up) 101 | for (var y:int = 0; y < dropY; y += offset) 102 | { 103 | dropPoint.y = y; 104 | canvas.copyPixels(image, dropRect, dropPoint); 105 | } 106 | 107 | dropY -= offset; 108 | 109 | dropRect.y -= offset; 110 | 111 | if (dropY <= 0) 112 | { 113 | complete = true; 114 | } 115 | 116 | break; 117 | } 118 | 119 | lastUpdate = 0; 120 | 121 | canvas.unlock(); 122 | 123 | sprite.pixels = canvas; 124 | sprite.dirty = true; 125 | } 126 | } 127 | 128 | } 129 | 130 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FX/GlitchFX.as: -------------------------------------------------------------------------------- 1 | /** 2 | * GlitchFX - Special FX Plugin 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.2 Fixed updateFromSource github issue #8 (thanks CoderBrandon) 6 | * v1.1 Added changeGlitchValues support 7 | * v1.0 First release 8 | * 9 | * @version 1.2 - August 8th 2011 10 | * @link http://www.photonstorm.com 11 | * @author Richard Davey / Photon Storm 12 | */ 13 | 14 | package org.flixel.plugin.photonstorm.FX 15 | { 16 | import flash.display.BitmapData; 17 | import flash.geom.Point; 18 | import flash.geom.Rectangle; 19 | 20 | import org.flixel.*; 21 | import org.flixel.plugin.photonstorm.*; 22 | 23 | /** 24 | * Creates a static / glitch / monitor-corruption style effect on an FlxSprite 25 | * 26 | * TODO: 27 | * 28 | * Add reduction from really high glitch value down to zero, will smooth the image into place and look cool :) 29 | * Add option to glitch vertically? 30 | * 31 | */ 32 | public class GlitchFX extends BaseFX 33 | { 34 | private var glitchSize:uint; 35 | private var glitchSkip:uint; 36 | 37 | public function GlitchFX() 38 | { 39 | } 40 | 41 | public function createFromFlxSprite(source:FlxSprite, maxGlitch:uint, maxSkip:uint, autoUpdate:Boolean = false, backgroundColor:uint = 0x0):FlxSprite 42 | { 43 | sprite = new FlxSprite(source.x, source.y).makeGraphic(source.width + maxGlitch, source.height, backgroundColor); 44 | 45 | canvas = new BitmapData(sprite.width, sprite.height, true, backgroundColor); 46 | 47 | image = source.pixels; 48 | 49 | updateFromSource = autoUpdate; 50 | 51 | if (updateFromSource) 52 | { 53 | sourceRef = source; 54 | } 55 | 56 | glitchSize = maxGlitch; 57 | glitchSkip = maxSkip; 58 | 59 | clsColor = backgroundColor; 60 | clsRect = new Rectangle(0, 0, canvas.width, canvas.height); 61 | 62 | copyPoint = new Point(0, 0); 63 | copyRect = new Rectangle(0, 0, image.width, 1); 64 | 65 | active = true; 66 | 67 | return sprite; 68 | } 69 | 70 | public function changeGlitchValues(maxGlitch:uint, maxSkip:uint):void 71 | { 72 | glitchSize = maxGlitch; 73 | glitchSkip = maxSkip; 74 | } 75 | 76 | public function draw():void 77 | { 78 | if (ready) 79 | { 80 | if (lastUpdate != updateLimit) 81 | { 82 | lastUpdate++; 83 | 84 | return; 85 | } 86 | 87 | if (updateFromSource && sourceRef.exists) 88 | { 89 | image = sourceRef.framePixels; 90 | } 91 | 92 | canvas.lock(); 93 | canvas.fillRect(clsRect, clsColor); 94 | 95 | var rndSkip:uint = 1 + int(Math.random() * glitchSkip); 96 | 97 | copyRect.y = 0; 98 | copyPoint.y = 0; 99 | copyRect.height = rndSkip; 100 | 101 | for (var y:int = 0; y < sprite.height; y += rndSkip) 102 | { 103 | copyPoint.x = int(Math.random() * glitchSize); 104 | canvas.copyPixels(image, copyRect, copyPoint); 105 | 106 | copyRect.y += rndSkip; 107 | copyPoint.y += rndSkip; 108 | } 109 | 110 | canvas.unlock(); 111 | 112 | lastUpdate = 0; 113 | 114 | sprite.pixels = canvas; 115 | sprite.dirty = true; 116 | } 117 | } 118 | 119 | } 120 | 121 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FX/PlasmaFX.as: -------------------------------------------------------------------------------- 1 | /** 2 | * PlasmaFX - Special FX Plugin 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.4 Moved to the new Special FX Plugins 6 | * v1.3 Colours updated to include alpha values 7 | * v1.2 Updated for the Flixel 2.5 Plugin system 8 | * 9 | * @version 1.4 - May 8th 2011 10 | * @link http://www.photonstorm.com 11 | * @author Richard Davey / Photon Storm 12 | */ 13 | 14 | package org.flixel.plugin.photonstorm.FX 15 | { 16 | import flash.display.BitmapData; 17 | import flash.geom.Rectangle; 18 | 19 | import org.flixel.*; 20 | import org.flixel.plugin.photonstorm.*; 21 | 22 | /** 23 | * Creates a plasma effect FlxSprite 24 | */ 25 | 26 | public class PlasmaFX extends BaseFX 27 | { 28 | //private var pos1:uint; 29 | //private var pos2:uint; 30 | //private var pos3:uint; 31 | //private var pos4:uint; 32 | 33 | public var pos1:uint; 34 | public var pos2:uint; 35 | public var pos3:uint; 36 | public var pos4:uint; 37 | public var depth:uint = 128; 38 | 39 | private var tpos1:uint; 40 | private var tpos2:uint; 41 | private var tpos3:uint; 42 | private var tpos4:uint; 43 | 44 | private var aSin:Array; 45 | //private var previousColour:uint; 46 | private var colours:Array; 47 | private var step:uint = 0; 48 | private var span:uint; 49 | 50 | public function PlasmaFX():void 51 | { 52 | } 53 | 54 | public function create(x:int, y:int, width:uint, height:uint, scaleX:uint = 1, scaleY:uint = 1):FlxSprite 55 | { 56 | sprite = new FlxSprite(x, y).makeGraphic(width, height, 0x0); 57 | 58 | if (scaleX != 1 || scaleY != 1) 59 | { 60 | sprite.scale = new FlxPoint(scaleX, scaleY); 61 | sprite.x += width / scaleX; 62 | sprite.y += height / scaleY; 63 | } 64 | 65 | canvas = new BitmapData(width, height, true, 0x0); 66 | 67 | colours = FlxColor.getHSVColorWheel(); 68 | 69 | //colours = FlxColor.getHSVColorWheel(140); // now supports alpha :) 70 | //colours = FlxGradient.createGradientArray(1, 360, [0xff000000, 0xff000000, 0xff000000, 0x00000000, 0xff000000], 2); // Lovely black reveal for over an image 71 | //colours = FlxGradient.createGradientArray(1, 360, [0xff0000FF, 0xff000000, 0xff8F107C, 0xff00FFFF, 0xff0000FF], 1); // lovely purple black blue thingy 72 | 73 | span = colours.length - 1; 74 | 75 | aSin = new Array(512); 76 | 77 | for (var i:int = 0; i < 512; i++) 78 | { 79 | //var rad:Number = (i * 0.703125) * 0.0174532; 80 | var rad:Number = (i * 0.703125) * 0.0174532; 81 | 82 | // Any power of 2! 83 | // http://www.vaughns-1-pagers.com/computer/powers-of-2.htm 84 | // 256, 512, 1024, 2048, 4096, 8192, 16384 85 | aSin[i] = Math.sin(rad) * 1024; 86 | 87 | //aSin[i] = Math.cos(rad) * 1024; 88 | } 89 | 90 | active = true; 91 | 92 | tpos1 = 293; 93 | tpos2 = 483; 94 | tpos3 = 120; 95 | tpos4 = 360; 96 | 97 | pos1 = 0; 98 | pos2 = 5; 99 | pos3 = 0; 100 | pos4 = 0; 101 | 102 | return sprite; 103 | } 104 | 105 | public function draw():void 106 | { 107 | if (step < 10) 108 | { 109 | //trace(step, tpos1, tpos2, tpos3, tpos4, pos1, pos2, pos3, pos4, index); 110 | step++; 111 | } 112 | 113 | tpos4 = pos4; 114 | tpos3 = pos3; 115 | 116 | canvas.lock(); 117 | 118 | for (var y:int = 0; y < canvas.height; y++) 119 | { 120 | tpos1 = pos1 + 5; 121 | tpos2 = pos2 + 3; 122 | 123 | //tpos1 = pos1; 124 | //tpos2 = pos2; 125 | 126 | tpos2 &= 511; 127 | tpos3 &= 511; 128 | 129 | for (var x:int = 0; x < canvas.width; x++) 130 | { 131 | tpos1 &= 511; 132 | tpos2 &= 511; 133 | 134 | var x2:int = aSin[tpos1] + aSin[tpos2] + aSin[tpos3] + aSin[tpos4]; 135 | 136 | //var index:int = depth + (x2 >> 4); 137 | var index:int = depth + (x2 >> 4); 138 | //p = (128 + (p >> 4)) & 255; 139 | 140 | 141 | if (index <= 0) 142 | { 143 | index += span; 144 | } 145 | 146 | if (index >= span) 147 | { 148 | index -= span; 149 | } 150 | 151 | canvas.setPixel32(x, y, colours[index]); 152 | 153 | tpos1 += 5; 154 | tpos2 += 3; 155 | } 156 | 157 | tpos3 += 1; 158 | tpos4 += 3; 159 | } 160 | 161 | canvas.unlock(); 162 | 163 | sprite.pixels = canvas; 164 | sprite.dirty = true; 165 | 166 | pos1 += 4; // horizontal shift 167 | pos3 += 2; // vertical shift 168 | } 169 | 170 | } 171 | 172 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FX/RainbowLineFX.as: -------------------------------------------------------------------------------- 1 | /** 2 | * RainbowLineFX - A Special FX Plugin 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.0 Built into the new FlxSpecialFX system 6 | * 7 | * @version 1.0 - May 9th 2011 8 | * @link http://www.photonstorm.com 9 | * @author Richard Davey / Photon Storm 10 | * @see Requires FlxGradient, FlxMath 11 | */ 12 | 13 | package org.flixel.plugin.photonstorm.FX 14 | { 15 | import flash.display.BitmapData; 16 | import flash.geom.Rectangle; 17 | 18 | import org.flixel.*; 19 | import org.flixel.plugin.photonstorm.*; 20 | 21 | /** 22 | * Creates a Rainbow Line Effect - typically a rainbow sequence of color values passing through a 1px high line 23 | */ 24 | public class RainbowLineFX extends BaseFX 25 | { 26 | private var lineColors:Array; 27 | private var maxColor:uint; 28 | private var currentColor:uint; 29 | private var fillRect:Rectangle; 30 | private var speed:uint; 31 | private var chunk:uint; 32 | private var direction:uint; 33 | private var setPixel:Boolean; 34 | 35 | public function RainbowLineFX() 36 | { 37 | } 38 | 39 | /** 40 | * Creates a Color Line FlxSprite. 41 | * 42 | * @param x The x coordinate of the FlxSprite in game world pixels 43 | * @param y The y coordinate of the FlxSprite in game world pixels 44 | * @param width The width of the FlxSprite in pixels 45 | * @param height The height of the FlxSprite in pixels 46 | * @param colors An Array of color values used to create the line. If null (default) the HSV Color Wheel is used, giving a full spectrum rainbow effect 47 | * @param colorWidth The width of the color range controls how much interpolation occurs between each color in the colors array (default 360) 48 | * @param colorSpeed The speed at which the Rainbow Line cycles through its colors (default 1) 49 | * @param stepSize The size of each "chunk" of the Rainbow Line - use a higher value for a more retro look (default 1) 50 | * @param fadeWidth If you want the Line to fade from fadeColor to the first color in the colors array, and then out again, set this value to the amount of transition you want (128 looks good) 51 | * @param fadeColor The default fade color is black, but if you need to alpha it, or change for a different color, set it here 52 | * 53 | * @return An FlxSprite which automatically updates each draw() to cycle the colors through it 54 | */ 55 | public function create(x:int, y:int, width:uint, height:uint = 1, colors:Array = null, colorWidth:uint = 360, colorSpeed:uint = 1, stepSize:uint = 1, fadeWidth:uint = 128, fadeColor:uint = 0xff000000):FlxSprite 56 | { 57 | sprite = new FlxSprite(x, y).makeGraphic(width, height, 0x0); 58 | 59 | canvas = new BitmapData(width, height, true, 0x0); 60 | 61 | if (colors is Array) 62 | { 63 | lineColors = FlxGradient.createGradientArray(1, colorWidth, colors); 64 | } 65 | else 66 | { 67 | lineColors = FlxColor.getHSVColorWheel(); 68 | } 69 | 70 | currentColor = 0; 71 | maxColor = lineColors.length - 1; 72 | 73 | if (fadeWidth != 0) 74 | { 75 | var blackToFirst:Array = FlxGradient.createGradientArray(1, fadeWidth, [ fadeColor, fadeColor, fadeColor, lineColors[0] ]); 76 | var lastToBlack:Array = FlxGradient.createGradientArray(1, fadeWidth, [ lineColors[maxColor], fadeColor, fadeColor, fadeColor, fadeColor ]); 77 | 78 | var fadingColours:Array = blackToFirst.concat(lineColors); 79 | fadingColours = fadingColours.concat(lastToBlack); 80 | 81 | lineColors = fadingColours; 82 | 83 | maxColor = lineColors.length - 1; 84 | } 85 | 86 | direction = 0; 87 | setPixel = false; 88 | speed = colorSpeed; 89 | chunk = stepSize; 90 | fillRect = new Rectangle(0, 0, chunk, height); 91 | 92 | if (height == 1 && chunk == 1) 93 | { 94 | setPixel = true; 95 | } 96 | 97 | active = true; 98 | 99 | return sprite; 100 | } 101 | 102 | /** 103 | * Change the colors cycling through the line by passing in a new array of color values 104 | * 105 | * @param colors An Array of color values used to create the line. If null (default) the HSV Color Wheel is used, giving a full spectrum rainbow effect 106 | * @param colorWidth The width of the color range controls how much interpolation occurs between each color in the colors array (default 360) 107 | * @param resetCurrentColor If true the color pointer is returned to the start of the new color array, otherwise remains where it is 108 | * @param fadeWidth If you want the Rainbow Line to fade from black to the first color in the colors array, and then out again, set this value to the amount of transition you want (128 looks good) 109 | * @param fadeColor The default fade color is black, but if you need to alpha it, or change for a different color, set it here 110 | */ 111 | public function updateColors(colors:Array, colorWidth:uint = 360, resetCurrentColor:Boolean = false, fadeWidth:uint = 128, fadeColor:uint = 0xff000000):void 112 | { 113 | if (colors is Array) 114 | { 115 | lineColors = FlxGradient.createGradientArray(1, colorWidth, colors); 116 | } 117 | else 118 | { 119 | lineColors = FlxColor.getHSVColorWheel(); 120 | } 121 | 122 | maxColor = lineColors.length - 1; 123 | 124 | if (fadeWidth != 0) 125 | { 126 | var blackToFirst:Array = FlxGradient.createGradientArray(1, fadeWidth, [ 0xff000000, 0xff000000, 0xff000000, lineColors[0] ]); 127 | var lastToBlack:Array = FlxGradient.createGradientArray(1, fadeWidth, [ lineColors[maxColor], 0xff000000, 0xff000000, 0xff000000, 0xff000000 ]); 128 | 129 | var fadingColours:Array = blackToFirst.concat(lineColors); 130 | fadingColours = fadingColours.concat(lastToBlack); 131 | 132 | lineColors = fadingColours; 133 | 134 | maxColor = lineColors.length - 1; 135 | } 136 | 137 | if (currentColor > maxColor || resetCurrentColor) 138 | { 139 | currentColor = 0; 140 | } 141 | } 142 | 143 | /** 144 | * Doesn't need to be called directly as it's called by the FlxSpecialFX Plugin.
145 | * Set active to false if you wish to disable the effect.
146 | * Pass the effect to FlxSpecialFX.erase() if you wish to destroy this effect. 147 | */ 148 | public function draw():void 149 | { 150 | canvas.lock(); 151 | 152 | fillRect.x = 0; 153 | 154 | for (var x:int = 0; x < canvas.width; x = x + chunk) 155 | { 156 | var c:int = FlxMath.wrapValue(currentColor + x, 1, maxColor); 157 | 158 | if (setPixel) 159 | { 160 | canvas.setPixel32(x, 0, lineColors[c]); 161 | } 162 | else 163 | { 164 | canvas.fillRect(fillRect, lineColors[c]); 165 | fillRect.x += chunk; 166 | } 167 | } 168 | 169 | canvas.unlock(); 170 | 171 | if (direction == 0) 172 | { 173 | currentColor += speed; 174 | 175 | if (currentColor >= maxColor) 176 | { 177 | currentColor = 0; 178 | } 179 | } 180 | else 181 | { 182 | currentColor -= speed; 183 | 184 | if (currentColor < 0) 185 | { 186 | currentColor = maxColor; 187 | } 188 | } 189 | 190 | sprite.pixels = canvas; 191 | sprite.dirty = true; 192 | } 193 | 194 | /** 195 | * Set the speed at which the Line cycles through its colors 196 | */ 197 | public function set colorSpeed(value:uint):void 198 | { 199 | if (value < maxColor) 200 | { 201 | speed = value; 202 | } 203 | } 204 | 205 | /** 206 | * The speed at which the Line cycles through its colors 207 | */ 208 | public function get colorSpeed():uint 209 | { 210 | return speed; 211 | } 212 | 213 | /** 214 | * Set the size of each "chunk" of the Line. Use a higher value for a more retro look 215 | */ 216 | public function set stepSize(value:uint):void 217 | { 218 | if (value < canvas.width && value > 0) 219 | { 220 | canvas.fillRect(new Rectangle(0, 0, canvas.width, canvas.height), 0x0); 221 | chunk = value; 222 | 223 | fillRect.x = 0; 224 | fillRect.width = chunk; 225 | 226 | if (value > 1) 227 | { 228 | setPixel = false; 229 | } 230 | else 231 | { 232 | setPixel = true; 233 | } 234 | } 235 | } 236 | 237 | /** 238 | * The size of each "chunk" of the Line 239 | */ 240 | public function get stepSize():uint 241 | { 242 | return chunk; 243 | } 244 | 245 | /** 246 | * Changes the color cycle direction. 247 | * 248 | * @param newDirection 0 = Colors cycle incrementally (line looks like it is moving to the left), 1 = Colors decrement (line moves to the right) 249 | */ 250 | public function setDirection(newDirection:uint):void 251 | { 252 | if (newDirection == 0 || newDirection == 1) 253 | { 254 | direction = newDirection; 255 | } 256 | } 257 | 258 | } 259 | 260 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FX/RevealFX.as: -------------------------------------------------------------------------------- 1 | /** 2 | * RevealFX - Special FX Plugin 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.1 Added changeGlitchValues support 6 | * v1.0 First release 7 | * 8 | * @version 1.1 - June 13th 2011 9 | * @link http://www.photonstorm.com 10 | * @author Richard Davey / Photon Storm 11 | */ 12 | 13 | package org.flixel.plugin.photonstorm.FX 14 | { 15 | import flash.display.BitmapData; 16 | import flash.geom.Point; 17 | import flash.geom.Rectangle; 18 | 19 | import org.flixel.*; 20 | import org.flixel.plugin.photonstorm.*; 21 | 22 | /** 23 | * Creates a static / glitch / monitor-corruption style effect on an FlxSprite 24 | * 25 | * TODO: 26 | * 27 | * Add reduction from really high glitch value down to zero, will smooth the image into place and look cool :) 28 | * Add option to glitch vertically? 29 | * 30 | */ 31 | public class RevealFX extends BaseFX 32 | { 33 | private var glitchSize:uint; 34 | private var glitchSkip:uint; 35 | 36 | public function RevealFX() 37 | { 38 | } 39 | 40 | public function createFromFlxSprite(source:FlxSprite, maxGlitch:uint, maxSkip:uint, autoUpdate:Boolean = false, backgroundColor:uint = 0x0):FlxSprite 41 | { 42 | sprite = new FlxSprite(source.x, source.y).makeGraphic(source.width + maxGlitch, source.height, backgroundColor); 43 | 44 | canvas = new BitmapData(sprite.width, sprite.height, true, backgroundColor); 45 | 46 | image = source.pixels; 47 | 48 | updateFromSource = autoUpdate; 49 | 50 | glitchSize = maxGlitch; 51 | glitchSkip = maxSkip; 52 | 53 | clsColor = backgroundColor; 54 | clsRect = new Rectangle(0, 0, canvas.width, canvas.height); 55 | 56 | copyPoint = new Point(0, 0); 57 | copyRect = new Rectangle(0, 0, image.width, 1); 58 | 59 | active = true; 60 | 61 | return sprite; 62 | } 63 | 64 | public function changeGlitchValues(maxGlitch:uint, maxSkip:uint):void 65 | { 66 | glitchSize = maxGlitch; 67 | glitchSkip = maxSkip; 68 | } 69 | 70 | public function draw():void 71 | { 72 | if (ready) 73 | { 74 | if (lastUpdate != updateLimit) 75 | { 76 | lastUpdate++; 77 | 78 | return; 79 | } 80 | 81 | if (updateFromSource && sourceRef.exists) 82 | { 83 | image = sourceRef.framePixels; 84 | } 85 | 86 | canvas.lock(); 87 | canvas.fillRect(clsRect, clsColor); 88 | 89 | var rndSkip:uint = 1 + int(Math.random() * glitchSkip); 90 | 91 | copyRect.y = 0; 92 | copyPoint.y = 0; 93 | copyRect.height = rndSkip; 94 | 95 | for (var y:int = 0; y < sprite.height; y += rndSkip) 96 | { 97 | copyPoint.x = int(Math.random() * glitchSize); 98 | canvas.copyPixels(image, copyRect, copyPoint); 99 | 100 | copyRect.y += rndSkip; 101 | copyPoint.y += rndSkip; 102 | } 103 | 104 | canvas.unlock(); 105 | 106 | lastUpdate = 0; 107 | 108 | sprite.pixels = canvas; 109 | sprite.dirty = true; 110 | } 111 | } 112 | 113 | } 114 | 115 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FX/SineWaveFX.as: -------------------------------------------------------------------------------- 1 | /** 2 | * SineWaveFX - Special FX Plugin 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.0 First release 6 | * 7 | * @version 1.0 - May 21st 2011 8 | * @link http://www.photonstorm.com 9 | * @author Richard Davey / Photon Storm 10 | */ 11 | 12 | package org.flixel.plugin.photonstorm.FX 13 | { 14 | import flash.display.BitmapData; 15 | import flash.geom.Point; 16 | import flash.geom.Rectangle; 17 | 18 | import org.flixel.*; 19 | import org.flixel.plugin.photonstorm.*; 20 | 21 | /** 22 | * Creates a sine-wave effect through an FlxSprite which can be applied vertically or horizontally 23 | */ 24 | public class SineWaveFX extends BaseFX 25 | { 26 | private var waveType:uint; 27 | private var waveVertical:Boolean; 28 | private var waveLength:uint; 29 | private var waveSize:uint; 30 | private var waveFrequency:Number; 31 | private var wavePixelChunk:uint; 32 | private var waveData:Array; 33 | private var waveDataCounter:uint = 0; 34 | private var waveLoopCallback:Function; 35 | 36 | public static const WAVETYPE_VERTICAL_SINE:uint = 0; 37 | public static const WAVETYPE_VERTICAL_COSINE:uint = 1; 38 | public static const WAVETYPE_HORIZONTAL_SINE:uint = 2; 39 | public static const WAVETYPE_HORIZONTAL_COSINE:uint = 3; 40 | 41 | public function SineWaveFX() 42 | { 43 | } 44 | 45 | /** 46 | * Creates a new SineWaveFX Effect from the given FlxSprite. The original sprite remains unmodified.
47 | * The resulting FlxSprite will take on the same width / height and x/y coordinates of the source FlxSprite.
48 | * For really cool effects you can SineWave an FlxSprite that is constantly updating (either through animation or an FX chain). 49 | * 50 | * @param source The FlxSprite providing the image data for this effect. The resulting FlxSprite takes on the source width, height, x/y positions and scrollfactor. 51 | * @param type WAVETYPE_VERTICAL_SINE, WAVETYPE_VERTICAL_COSINE, WAVETYPE_HORIZONTAL_SINE or WAVETYPE_HORIZONTAL_COSINE 52 | * @param size The size in pixels of the sine wave. Either the height of the wave or the width (for vertical or horizontal waves) 53 | * @param length The length of the wave in pixels. You should usually set this to the width or height of the source image, or a multiple of it. 54 | * @param frequency The frequency of the peaks in the wave. MUST BE AN EVEN NUMBER! 2, 4, 6, 8, etc. 55 | * @param pixelsPerChunk How many pixels to use per step. Higher numbers make a more chunky but faster effect. Make sure source.width/height divides by this value evenly. 56 | * @param updateFrame When this effect is created it takes a copy of the source image data and stores it. Set this to true to grab a new copy of the image data every frame. 57 | * @param backgroundColor The background color (0xAARRGGBB format) to draw behind the effect (default 0x0 = transparent) 58 | * @return An FlxSprite with the effect running through it, which should be started with a call to SineWaveFX.start() 59 | */ 60 | public function createFromFlxSprite(source:FlxSprite, type:uint, size:uint, length:uint, frequency:uint = 2, pixelsPerChunk:uint = 1, updateFrame:Boolean = false, backgroundColor:uint = 0x0):FlxSprite 61 | { 62 | var result:FlxSprite = create(source.pixels, source.x, source.y, type, size, length, frequency, pixelsPerChunk, backgroundColor); 63 | 64 | updateFromSource = updateFrame; 65 | 66 | if (updateFromSource) 67 | { 68 | sourceRef = source; 69 | } 70 | 71 | return result; 72 | } 73 | 74 | /** 75 | * Creates a new SineWaveFX Effect from the given Class (which must contain a Bitmap).
76 | * If you need to update the source data at run-time then use createFromFlxSprite 77 | * 78 | * @param source The Class providing the bitmapData for this effect, usually from an Embedded bitmap. 79 | * @param x The x coordinate (in game world pixels) that the resulting FlxSprite will be created at. 80 | * @param y The x coordinate (in game world pixels) that the resulting FlxSprite will be created at. 81 | * @param type WAVETYPE_VERTICAL_SINE, WAVETYPE_VERTICAL_COSINE, WAVETYPE_HORIZONTAL_SINE or WAVETYPE_HORIZONTAL_COSINE 82 | * @param size The size in pixels of the sine wave. Either the height of the wave or the width (for vertical or horizontal waves) 83 | * @param length The length of the wave in pixels. You should usually set this to the width or height of the source image, or a multiple of it. 84 | * @param frequency The frequency of the peaks in the wave. MUST BE AN EVEN NUMBER! 2, 4, 6, 8, etc. 85 | * @param pixelsPerChunk How many pixels to use per step. Higher numbers make a more chunky but faster effect. Make sure source.width/height divides by this value evenly. 86 | * @param backgroundColor The background color in 0xAARRGGBB format to draw behind the effect (default 0x0 = transparent) 87 | * @return An FlxSprite with the effect running through it, which should be started with a call to SineWaveFX.start() 88 | */ 89 | public function createFromClass(source:Class, x:int, y:int, type:uint, size:uint, length:uint, frequency:uint = 2, pixelsPerChunk:uint = 1, backgroundColor:uint = 0x0):FlxSprite 90 | { 91 | var result:FlxSprite = create((new source).bitmapData, x, y, type, size, length, frequency, pixelsPerChunk, backgroundColor); 92 | 93 | updateFromSource = false; 94 | 95 | return result; 96 | } 97 | 98 | /** 99 | * Creates a new SineWaveFX Effect from the given bitmapData.
100 | * If you need to update the source data at run-time then use createFromFlxSprite 101 | * 102 | * @param source The bitmapData image to use for this effect. 103 | * @param x The x coordinate (in game world pixels) that the resulting FlxSprite will be created at. 104 | * @param y The x coordinate (in game world pixels) that the resulting FlxSprite will be created at. 105 | * @param type WAVETYPE_VERTICAL_SINE, WAVETYPE_VERTICAL_COSINE, WAVETYPE_HORIZONTAL_SINE or WAVETYPE_HORIZONTAL_COSINE 106 | * @param size The size in pixels of the sine wave. Either the height of the wave or the width (for vertical or horizontal waves) 107 | * @param length The length of the wave in pixels. You should usually set this to the width or height of the source image, or a multiple of it. 108 | * @param frequency The frequency of the peaks in the wave. MUST BE AN EVEN NUMBER! 2, 4, 6, 8, etc. 109 | * @param pixelsPerChunk How many pixels to use per step. Higher numbers make a more chunky but faster effect. Make sure source.width/height divides by this value evenly. 110 | * @param backgroundColor The background color in 0xAARRGGBB format to draw behind the effect (default 0x0 = transparent) 111 | * @return An FlxSprite with the effect running through it, which should be started with a call to SineWaveFX.start() 112 | */ 113 | public function createFromBitmapData(source:BitmapData, x:int, y:int, type:uint, size:uint, length:uint, frequency:uint = 2, pixelsPerChunk:uint = 1, backgroundColor:uint = 0x0):FlxSprite 114 | { 115 | var result:FlxSprite = create(source, x, y, type, size, length, frequency, pixelsPerChunk, backgroundColor); 116 | 117 | updateFromSource = false; 118 | 119 | return result; 120 | } 121 | 122 | /** 123 | * Internal function fed from createFromFlxSprite / createFromClass / createFromBitmapData 124 | * 125 | * @param source The bitmapData image to use for this effect. 126 | * @param x The x coordinate (in game world pixels) that the resulting FlxSprite will be created at. 127 | * @param y The x coordinate (in game world pixels) that the resulting FlxSprite will be created at. 128 | * @param type WAVETYPE_VERTICAL_SINE, WAVETYPE_VERTICAL_COSINE, WAVETYPE_HORIZONTAL_SINE or WAVETYPE_HORIZONTAL_COSINE 129 | * @param size The size in pixels of the sine wave. Either the height of the wave or the width (for vertical or horizontal waves) 130 | * @param length The length of the wave in pixels. You should usually set this to the width or height of the source image, or a multiple of it. 131 | * @param frequency The frequency of the peaks in the wave. MUST BE AN EVEN NUMBER! 2, 4, 6, 8, etc. 132 | * @param pixelsPerChunk How many pixels to use per step. Higher numbers make a more chunky but faster effect. Make sure source.width/height divides by this value evenly. 133 | * @param backgroundColor The background color in 0xAARRGGBB format to draw behind the effect (default 0x0 = transparent) 134 | * @return An FlxSprite with the effect running through it, which should be started with a call to SineWaveFX.start() 135 | */ 136 | private function create(source:BitmapData, x:int, y:int, type:uint, size:uint, length:uint, frequency:uint = 2, pixelsPerChunk:uint = 1, backgroundColor:uint = 0x0):FlxSprite 137 | { 138 | if (type == WAVETYPE_VERTICAL_SINE || type == WAVETYPE_VERTICAL_COSINE) 139 | { 140 | waveVertical = true; 141 | 142 | if (pixelsPerChunk >= source.width) 143 | { 144 | throw new Error("SineWaveFX: pixelsPerChunk cannot be >= source.width with WAVETYPE_VERTICAL"); 145 | } 146 | } 147 | else if (type == WAVETYPE_HORIZONTAL_SINE || type == WAVETYPE_HORIZONTAL_COSINE) 148 | { 149 | waveVertical = false; 150 | 151 | if (pixelsPerChunk >= source.height) 152 | { 153 | throw new Error("SineWaveFX: pixelsPerChunk cannot be >= source.height with WAVETYPE_HORIZONTAL"); 154 | } 155 | } 156 | 157 | updateWaveData(type, size, length, frequency, pixelsPerChunk); 158 | 159 | // The FlxSprite into which the sine-wave effect is drawn 160 | 161 | if (waveVertical) 162 | { 163 | sprite = new FlxSprite(x, y).makeGraphic(source.width, source.height + (waveSize * 3), backgroundColor); 164 | } 165 | else 166 | { 167 | sprite = new FlxSprite(x, y).makeGraphic(source.width + (waveSize * 3), source.height, backgroundColor); 168 | } 169 | 170 | // The scratch bitmapData where we prepare the final sine-waved image 171 | canvas = new BitmapData(sprite.width, sprite.height, true, backgroundColor); 172 | 173 | // Our local copy of the sprite image data 174 | image = source.clone(); 175 | 176 | clsColor = backgroundColor; 177 | clsRect = new Rectangle(0, 0, canvas.width, canvas.height); 178 | 179 | copyPoint = new Point(0, 0); 180 | 181 | if (waveVertical) 182 | { 183 | copyRect = new Rectangle(0, 0, wavePixelChunk, image.height); 184 | } 185 | else 186 | { 187 | copyRect = new Rectangle(0, 0, image.width, wavePixelChunk); 188 | } 189 | 190 | active = true; 191 | 192 | return sprite; 193 | } 194 | 195 | /** 196 | * Update the SineWave data without modifying the source image being used.
197 | * This call is fast enough that you can modify it in real-time. 198 | * 199 | * @param type WAVETYPE_VERTICAL_SINE, WAVETYPE_VERTICAL_COSINE, WAVETYPE_HORIZONTAL_SINE or WAVETYPE_HORIZONTAL_COSINE 200 | * @param size The size in pixels of the sine wave. Either the height of the wave or the width (for vertical or horizontal waves) 201 | * @param length The length of the wave in pixels. You should usually set this to the width or height of the source image, or a multiple of it. 202 | * @param frequency The frequency of the peaks in the wave. MUST BE AN EVEN NUMBER! 2, 4, 6, 8, etc. 203 | * @param pixelsPerChunk How many pixels to use per step. Higher numbers make a more chunky but faster effect. Make sure source.width/height divides by this value evenly. 204 | */ 205 | public function updateWaveData(type:uint, size:uint, length:uint, frequency:uint = 2, pixelsPerChunk:uint = 1):void 206 | { 207 | if (type > WAVETYPE_HORIZONTAL_COSINE) 208 | { 209 | throw new Error("SineWaveFX: Invalid WAVETYPE"); 210 | } 211 | 212 | if (FlxMath.isOdd(frequency)) 213 | { 214 | throw new Error("SineWaveFX: frequency must be an even number"); 215 | } 216 | 217 | waveType = type; 218 | waveSize = uint(size * 0.5); 219 | waveLength = uint(length / pixelsPerChunk); 220 | waveFrequency = frequency; 221 | wavePixelChunk = pixelsPerChunk; 222 | waveData = FlxMath.sinCosGenerator(waveLength, waveSize, waveSize, waveFrequency); 223 | 224 | if (waveType == WAVETYPE_VERTICAL_COSINE || waveType == WAVETYPE_HORIZONTAL_COSINE) 225 | { 226 | waveData = FlxMath.getCosTable(); 227 | } 228 | } 229 | 230 | /** 231 | * Use this to set a function to be called every time the wave has completed one full cycle.
232 | * Set to null to remove any previous callback. 233 | * 234 | * @param callback The function to call every time the wave completes a full cycle (duration will vary based on waveLength) 235 | */ 236 | public function setLoopCompleteCallback(callback:Function):void 237 | { 238 | waveLoopCallback = callback; 239 | } 240 | 241 | /** 242 | * Called by the FlxSpecialFX plugin. Should not be called directly. 243 | */ 244 | public function draw():void 245 | { 246 | if (ready) 247 | { 248 | if (lastUpdate != updateLimit) 249 | { 250 | lastUpdate++; 251 | 252 | return; 253 | } 254 | 255 | if (updateFromSource && sourceRef.exists) 256 | { 257 | image = sourceRef.framePixels; 258 | } 259 | 260 | canvas.lock(); 261 | canvas.fillRect(clsRect, clsColor); 262 | 263 | var s:uint = 0; 264 | 265 | copyRect.x = 0; 266 | copyRect.y = 0; 267 | 268 | if (waveVertical) 269 | { 270 | for (var x:int = 0; x < image.width; x += wavePixelChunk) 271 | { 272 | copyPoint.x = x; 273 | copyPoint.y = waveSize + (waveSize / 2) + waveData[s]; 274 | 275 | canvas.copyPixels(image, copyRect, copyPoint); 276 | 277 | copyRect.x += wavePixelChunk; 278 | 279 | s++; 280 | } 281 | } 282 | else 283 | { 284 | for (var y:int = 0; y < image.height; y += wavePixelChunk) 285 | { 286 | copyPoint.x = waveSize + (waveSize / 2) + waveData[s]; 287 | copyPoint.y = y; 288 | 289 | canvas.copyPixels(image, copyRect, copyPoint); 290 | 291 | copyRect.y += wavePixelChunk; 292 | 293 | s++; 294 | } 295 | } 296 | 297 | // Cycle through the wave data - this is what causes the image to "undulate" 298 | var t:Number = waveData.shift(); 299 | waveData.push(t); 300 | 301 | waveDataCounter++; 302 | 303 | if (waveDataCounter == waveData.length) 304 | { 305 | waveDataCounter = 0; 306 | 307 | if (waveLoopCallback is Function) 308 | { 309 | waveLoopCallback.call(); 310 | } 311 | } 312 | 313 | canvas.unlock(); 314 | 315 | lastUpdate = 0; 316 | 317 | sprite.pixels = canvas; 318 | sprite.dirty = true; 319 | } 320 | } 321 | 322 | public function toString():String 323 | { 324 | var output:Array = [ "Type: " + waveType, "Size: " + waveSize, "Length: " + waveLength, "Frequency: " + waveFrequency, "Chunks: " + wavePixelChunk, "clsRect: " + clsRect ]; 325 | 326 | return output.join(","); 327 | } 328 | 329 | } 330 | 331 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FX/StarfieldFX.as: -------------------------------------------------------------------------------- 1 | /** 2 | * StarfieldFX - Special FX Plugin 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.1 StarField moved to the FX Plugin system 6 | * v1.0 First release 7 | * 8 | * @version 1.1 - May 21st 2011 9 | * @link http://www.photonstorm.com 10 | * @author Richard Davey / Photon Storm 11 | */ 12 | 13 | package org.flixel.plugin.photonstorm.FX 14 | { 15 | import flash.display.BitmapData; 16 | import flash.geom.Point; 17 | import flash.geom.Rectangle; 18 | import flash.utils.getTimer; 19 | 20 | import org.flixel.*; 21 | import org.flixel.plugin.photonstorm.*; 22 | 23 | /** 24 | * Creates a 2D or 3D Star Field effect on an FlxSprite for use in your game. 25 | */ 26 | public class StarfieldFX extends BaseFX 27 | { 28 | /** 29 | * In a 3D starfield this controls the X coordinate the stars emit from, can be updated in real-time! 30 | */ 31 | public var centerX:int; 32 | 33 | /** 34 | * In a 3D starfield this controls the Y coordinate the stars emit from, can be updated in real-time! 35 | */ 36 | public var centerY:int; 37 | 38 | /** 39 | * How much to shift on the X axis every update. Negative values move towards the left, positiive to the right. 2D Starfield only. Can also be set via setStarSpeed() 40 | */ 41 | public var starXOffset:Number = -1; 42 | 43 | /** 44 | * How much to shift on the Y axis every update. Negative values move up, positiive values move down. 2D Starfield only. Can also be set via setStarSpeed() 45 | */ 46 | public var starYOffset:Number = 0; 47 | 48 | private var stars:Array; 49 | private var starfieldType:int; 50 | 51 | private var backgroundColor:uint = 0xff000000; 52 | 53 | private var updateSpeed:int; 54 | private var tick:int; 55 | 56 | private var depthColours:Array; 57 | 58 | public static const STARFIELD_TYPE_2D:int = 1; 59 | public static const STARFIELD_TYPE_3D:int = 2; 60 | 61 | public function StarfieldFX() 62 | { 63 | } 64 | 65 | /** 66 | * Create a new StarField 67 | * 68 | * @param x X coordinate of the starfield sprite 69 | * @param y Y coordinate of the starfield sprite 70 | * @param width The width of the starfield 71 | * @param height The height of the starfield 72 | * @param quantity The number of stars in the starfield (default 200) 73 | * @param type Type of starfield. Either STARFIELD_TYPE_2D (default, stars move horizontally) or STARFIELD_TYPE_3D (stars flow out from the center) 74 | * @param updateInterval How many ms should pass before the next starfield update (default 20) 75 | */ 76 | public function create(x:int, y:int, width:uint, height:uint, quantity:uint = 200, type:int = 1, updateInterval:int = 20):FlxSprite 77 | { 78 | sprite = new FlxSprite(x, y).makeGraphic(width, height, backgroundColor); 79 | 80 | canvas = new BitmapData(sprite.width, sprite.height, true, backgroundColor); 81 | 82 | starfieldType = type; 83 | 84 | updateSpeed = speed; 85 | 86 | // Stars come from the middle of the starfield in 3D mode 87 | centerX = width >> 1; 88 | centerY = height >> 1; 89 | 90 | clsRect = new Rectangle(0, 0, width, height); 91 | clsPoint = new Point; 92 | clsColor = backgroundColor; 93 | 94 | stars = new Array(); 95 | 96 | for (var i:uint = 0; i < quantity; i++) 97 | { 98 | var star:Object = new Object; 99 | 100 | star.index = i; 101 | star.x = int(Math.random() * width); 102 | star.y = int(Math.random() * height); 103 | star.d = 1; 104 | 105 | if (type == STARFIELD_TYPE_2D) 106 | { 107 | star.speed = 1 + int(Math.random() * 5); 108 | } 109 | else 110 | { 111 | star.speed = Math.random(); 112 | } 113 | 114 | star.r = Math.random() * Math.PI * 2; 115 | star.alpha = 0; 116 | 117 | stars.push(star); 118 | } 119 | 120 | // Colours array 121 | if (type == STARFIELD_TYPE_2D) 122 | { 123 | depthColours = FlxGradient.createGradientArray(1, 5, [0xff585858, 0xffF4F4F4]); 124 | } 125 | else 126 | { 127 | depthColours = FlxGradient.createGradientArray(1, 300, [0xff292929, 0xffffffff]); 128 | } 129 | 130 | active = true; 131 | 132 | return sprite; 133 | } 134 | 135 | /** 136 | * Change the background color in the format 0xAARRGGBB of the starfield.
137 | * Supports alpha, so if you want a transparent background just pass 0x00 as the color. 138 | * 139 | * @param backgroundColor 140 | */ 141 | public function setBackgroundColor(backgroundColor:uint):void 142 | { 143 | clsColor = backgroundColor; 144 | } 145 | 146 | /** 147 | * Change the number of layers (depth) and colors used for each layer of the starfield. Change happens immediately. 148 | * 149 | * @param depth Number of depths (for a 2D starfield the default is 5) 150 | * @param lowestColor The color given to the stars furthest away from the camera (i.e. the slowest stars), typically the darker colour 151 | * @param highestColor The color given to the stars cloest to the camera (i.e. the fastest stars), typically the brighter colour 152 | */ 153 | public function setStarDepthColors(depth:int, lowestColor:uint = 0xff585858, highestColor:uint = 0xffF4F4F4):void 154 | { 155 | // Depth is the same, we just need to update the gradient then 156 | depthColours = FlxGradient.createGradientArray(1, depth, [lowestColor, highestColor]); 157 | 158 | // Run through the stars array, making sure the depths are all within range 159 | for each (var star:Object in stars) 160 | { 161 | star.speed = 1 + int(Math.random() * depth); 162 | } 163 | } 164 | 165 | /** 166 | * Sets the direction and speed of the 2D starfield (doesn't apply to 3D)
167 | * You can combine both X and Y together to make the stars move on a diagnol 168 | * 169 | * @param xShift How much to shift on the X axis every update. Negative values move towards the left, positiive to the right 170 | * @param yShift How much to shift on the Y axis every update. Negative values move up, positiive values move down 171 | */ 172 | public function setStarSpeed(xShift:Number, yShift:Number):void 173 | { 174 | starXOffset = xShift; 175 | starYOffset = yShift; 176 | } 177 | 178 | /** 179 | * The current update speed 180 | */ 181 | public function get speed():int 182 | { 183 | return updateSpeed; 184 | } 185 | 186 | /** 187 | * Change the tick interval on which the update runs. By default the starfield updates once every 20ms. Set to zero to disable totally. 188 | */ 189 | public function set speed(newSpeed:int):void 190 | { 191 | updateSpeed = newSpeed; 192 | } 193 | 194 | private function update2DStarfield():void 195 | { 196 | for each (var star:Object in stars) 197 | { 198 | star.x += (starXOffset * star.speed); 199 | star.y += (starYOffset * star.speed); 200 | 201 | canvas.setPixel32(star.x, star.y, depthColours[star.speed - 1]); 202 | 203 | if (star.x > sprite.width) 204 | { 205 | star.x = 0; 206 | } 207 | else if (star.x < 0) 208 | { 209 | star.x = sprite.width; 210 | } 211 | 212 | if (star.y > sprite.height) 213 | { 214 | star.y = 0; 215 | } 216 | else if (star.y < 0) 217 | { 218 | star.y = sprite.height; 219 | } 220 | } 221 | } 222 | 223 | private function update3DStarfield():void 224 | { 225 | for each (var star:Object in stars) 226 | { 227 | star.d *= 1.1; 228 | star.x = centerX + ((Math.cos(star.r) * star.d) * star.speed); 229 | star.y = centerY + ((Math.sin(star.r) * star.d) * star.speed); 230 | 231 | star.alpha = star.d * 2; 232 | 233 | if (star.alpha > 255) 234 | { 235 | star.alpha = 255; 236 | } 237 | 238 | canvas.setPixel32(star.x, star.y, 0xffffffff); 239 | //canvas.setPixel32(star.x, star.y, FlxColor.getColor32(255, star.alpha, star.alpha, star.alpha)); 240 | 241 | if (star.x < 0 || star.x > sprite.width || star.y < 0 || star.y > sprite.height) 242 | { 243 | star.d = 1; 244 | star.r = Math.random() * Math.PI * 2; 245 | star.x = 0; 246 | star.y = 0; 247 | star.speed = Math.random(); 248 | star.alpha = 0; 249 | 250 | stars[star.index] = star; 251 | } 252 | } 253 | } 254 | 255 | public function draw():void 256 | { 257 | if (getTimer() > tick) 258 | { 259 | canvas.lock(); 260 | canvas.fillRect(clsRect, clsColor); 261 | 262 | if (starfieldType == STARFIELD_TYPE_2D) 263 | { 264 | update2DStarfield(); 265 | } 266 | else 267 | { 268 | update3DStarfield(); 269 | } 270 | 271 | canvas.unlock(); 272 | 273 | sprite.pixels = canvas; 274 | 275 | if (updateSpeed > 0) 276 | { 277 | tick = getTimer() + updateSpeed; 278 | } 279 | } 280 | } 281 | 282 | } 283 | 284 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FX/WowCopperFX.as: -------------------------------------------------------------------------------- 1 | /** 2 | * WowCopperFX - Special FX Plugin 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.0 First release 6 | * 7 | * @version 1.4 - May 8th 2011 8 | * @link http://www.photonstorm.com 9 | * @author Original by Mathew Nolan / Flashtro.com 10 | * @author Ported with permission by Richard Davey / Photon Storm 11 | */ 12 | 13 | package org.flixel.plugin.photonstorm.FX 14 | { 15 | import flash.display.Bitmap; 16 | import flash.display.BitmapData; 17 | import flash.display.Sprite; 18 | import flash.geom.Matrix; 19 | import flash.geom.Rectangle; 20 | 21 | import org.flixel.*; 22 | import org.flixel.plugin.photonstorm.*; 23 | 24 | /** 25 | * Creates a WOW Copper effect FlxSprite 26 | */ 27 | 28 | public class WowCopperFX extends BaseFX 29 | { 30 | private var colors:Array; 31 | private var step:uint = 0; 32 | private var span:uint; 33 | 34 | 35 | private var bmp_databg : BitmapData = new BitmapData( 1 , 64 , false , 0x00000100); 36 | //private var bmp_objbg : Bitmap = new Bitmap( bmp_databg , PixelSnapping.AUTO , false); 37 | private var bg2:Sprite = new Sprite; 38 | 39 | private var amount:int = 8; 40 | private var tab:int = 0; 41 | private var del:int = 0; 42 | private var max:int = 136; 43 | 44 | public function WowCopperFX():void 45 | { 46 | } 47 | 48 | public function create(x:int, y:int, width:uint, height:uint):FlxSprite 49 | { 50 | sprite = new FlxSprite(x, y).makeGraphic(width, height, 0x0); 51 | 52 | colors = [0x110011, 53 | 0x220022, 54 | 0x330033, 55 | 0x440044, 56 | 0x550055, 57 | 0x660066, 58 | 0x770077, 59 | 0x880088, 60 | 0x990099, 61 | 0xaa00aa, 62 | 0xbb00bb, 63 | 0xcc00cc, 64 | 0xdd00dd, 65 | 0xee00ee, 66 | 0xff00ff, 67 | 0xff00ff, 68 | 0xee00ee, 69 | 0xdd00dd, 70 | 0xcc00cc, 71 | 0xbb00bb, 72 | 0xaa00aa, 73 | 0x990099, 74 | 0x880088, 75 | 0x770077, 76 | 0x660066, 77 | 0x550055, 78 | 0x440044, 79 | 0x330033, 80 | 0x220022, 81 | 0x110011, 82 | 0x000001, 83 | 0x000001, 84 | 0x000001, 85 | 0x000001, 86 | 0x000001, 87 | 0x000001, 88 | 0x000001, 89 | 0x000001, 90 | 0x000001, 91 | 0x000001, 92 | 0x111100, 93 | 0x222200, 94 | 0x333300, 95 | 0x444400, 96 | 0x555500, 97 | 0x666600, 98 | 0x777700, 99 | 0x888800, 100 | 0x999900, 101 | 0xaaaa00, 102 | 0xbbbb00, 103 | 0xcccc00, 104 | 0xdddd00, 105 | 0xeeee00, 106 | 0xffff00, 107 | 0xffff00, 108 | 0xeeee00, 109 | 0xdddd00, 110 | 0xcccc00, 111 | 0xbbbb00, 112 | 0xaaaa00, 113 | 0x999900, 114 | 0x888800, 115 | 0x777700, 116 | 0x666600, 117 | 0x555500, 118 | 0x444400, 119 | 0x333300, 120 | 0x222200, 121 | 0x111100, 122 | 0x000001, 123 | 0x000001, 124 | 0x000001, 125 | 0x000001, 126 | 0x000001, 127 | 0x000001, 128 | 0x000001, 129 | 0x000001, 130 | 0x000001, 131 | 0x000001, 132 | 0x001111, 133 | 0x002222, 134 | 0x003333, 135 | 0x004444, 136 | 0x005555, 137 | 0x006666, 138 | 0x007777, 139 | 0x008888, 140 | 0x009999, 141 | 0x00aaaa, 142 | 0x00bbbb, 143 | 0x00cccc, 144 | 0x00dddd, 145 | 0x00eeee, 146 | 0x00ffff, 147 | 0x00ffff, 148 | 0x00eeee, 149 | 0x00dddd, 150 | 0x00cccc, 151 | 0x00bbbb, 152 | 0x00aaaa, 153 | 0x009999, 154 | 0x008888, 155 | 0x007777, 156 | 0x006666, 157 | 0x005555, 158 | 0x004444, 159 | 0x003333, 160 | 0x002222, 161 | 0x001111, 162 | 0x000001, 163 | 0x000001, 164 | 0x000001, 165 | 0x000001, 166 | 0x000001, 167 | 0x000001, 168 | 0x000001, 169 | 0x000001, 170 | 0x000001, 171 | 0x000001, 172 | 0x111111, 173 | 0x222222, 174 | 0x333333, 175 | 0x444444, 176 | 0x555555, 177 | 0x666666, 178 | 0x777777, 179 | 0x888888, 180 | 0x999999, 181 | 0xaaaaaa, 182 | 0xbbbbbb, 183 | 0xcccccc, 184 | 0xdddddd, 185 | 0xeeeeee, 186 | 0xffffff, 187 | 0xffffff, 188 | 0xeeeeee, 189 | 0xdddddd, 190 | 0xcccccc, 191 | 0xbbbbbb, 192 | 0xaaaaaa, 193 | 0x999999, 194 | 0x888888, 195 | 0x777777, 196 | 0x666666, 197 | 0x555555, 198 | 0x444444, 199 | 0x333333, 200 | 0x222222, 201 | 0x111111, 202 | 0x000001, 203 | 0x000001, 204 | 0x000001, 205 | 0x000001, 206 | 0x000001, 207 | 0x000001, 208 | 0x000001, 209 | 0x000001, 210 | 0x000001, 211 | 0x000001]; 212 | 213 | //canvas = new BitmapData(1, 64 , false , 0x00000100); 214 | canvas = new BitmapData(width, height, true, 0x0); 215 | 216 | active = true; 217 | 218 | return sprite; 219 | } 220 | 221 | public function draw():void 222 | { 223 | if (step < 10) 224 | { 225 | //trace(step, tpos1, tpos2, tpos3, tpos4, pos1, pos2, pos3, pos4, index); 226 | step++; 227 | } 228 | 229 | //canvas.setPixel(0, 31, colors[tab]); 230 | bmp_databg.setPixel(0, 31, colors[tab]); 231 | 232 | del++; 233 | 234 | if (del >= 2) 235 | { 236 | bmp_databg.scroll(0, -1); 237 | tab++; 238 | del = 0; 239 | } 240 | 241 | if (tab >= colors.length) 242 | { 243 | tab = 0; 244 | } 245 | 246 | bg2.graphics.clear(); 247 | 248 | var bbcb:Matrix = new Matrix; 249 | 250 | for (var i:uint = 0; i < max; i += amount) 251 | { 252 | bg2.graphics.beginBitmapFill(bmp_databg, bbcb, true, false); 253 | bg2.graphics.moveTo(0, i); 254 | bg2.graphics.lineTo(0, i + amount); 255 | bg2.graphics.lineTo(320, i + amount ); 256 | bg2.graphics.lineTo(320, i); 257 | bg2.graphics.endFill(); 258 | bbcb.translate(0, 7); 259 | } 260 | 261 | canvas.draw(bg2); 262 | 263 | sprite.pixels = canvas; 264 | sprite.dirty = true; 265 | 266 | /* 267 | bmp_databg.setPixel(0,31,cols[tab]) 268 | del++ 269 | if(del>=2){ 270 | bmp_databg.scroll(0,-1) 271 | tab++ 272 | del=0 273 | } 274 | if(tab>=cols.length){ 275 | tab=0 276 | } 277 | bg2.graphics.clear() 278 | var bbcb = new flash.geom.Matrix(); 279 | for (var i:uint=0; iFlxButton object with a gray background 108 | * and a callback function on the UI thread. 109 | * 110 | * @param X The X position of the button. 111 | * @param Y The Y position of the button. 112 | * @param Callback The function to call whenever the button is clicked. 113 | * @param Params An optional array of parameters that will be passed to the Callback function 114 | * @param Label Text to display on the button 115 | * @param Width The width of the button. 116 | * @param Height The height of the button. 117 | */ 118 | public function FlxButtonPlus(X:int, Y:int, Callback:Function, Params:Array = null, Label:String = null, Width:int = 100, Height:int = 20):void 119 | { 120 | super(4); 121 | 122 | _x = X; 123 | _y = Y; 124 | width = Width; 125 | height = Height; 126 | _onClick = Callback; 127 | 128 | buttonNormal = new FlxExtendedSprite(X, Y); 129 | buttonNormal.makeGraphic(Width, Height, borderColor); 130 | buttonNormal.stamp(FlxGradient.createGradientFlxSprite(Width - 2, Height - 2, offColor), 1, 1); 131 | buttonNormal.solid = false; 132 | buttonNormal.scrollFactor.x = 0; 133 | buttonNormal.scrollFactor.y = 0; 134 | 135 | buttonHighlight = new FlxExtendedSprite(X, Y); 136 | buttonHighlight.makeGraphic(Width, Height, borderColor); 137 | buttonHighlight.stamp(FlxGradient.createGradientFlxSprite(Width - 2, Height - 2, onColor), 1, 1); 138 | buttonHighlight.solid = false; 139 | buttonHighlight.visible = false; 140 | buttonHighlight.scrollFactor.x = 0; 141 | buttonHighlight.scrollFactor.y = 0; 142 | 143 | 144 | add(buttonNormal); 145 | add(buttonHighlight); 146 | 147 | if (Label != null) 148 | { 149 | textNormal = new FlxText(X, Y + 3, Width, Label); 150 | textNormal.setFormat(null, 8, 0xffffffff, "center", 0xff000000); 151 | 152 | textHighlight = new FlxText(X, Y + 3, Width, Label); 153 | textHighlight.setFormat(null, 8, 0xffffffff, "center", 0xff000000); 154 | 155 | add(textNormal); 156 | add(textHighlight); 157 | } 158 | 159 | _status = NORMAL; 160 | _pressed = false; 161 | _initialized = false; 162 | pauseProof = false; 163 | 164 | if (Params) 165 | { 166 | onClickParams = Params; 167 | } 168 | } 169 | 170 | public function set x(newX:int):void 171 | { 172 | _x = newX; 173 | 174 | buttonNormal.x = _x; 175 | buttonHighlight.x = _x; 176 | 177 | if (textNormal) 178 | { 179 | textNormal.x = _x; 180 | textHighlight.x = _x; 181 | } 182 | } 183 | 184 | public function get x():int 185 | { 186 | return _x; 187 | } 188 | 189 | public function set y(newY:int):void 190 | { 191 | _y = newY; 192 | 193 | buttonNormal.y = _y; 194 | buttonHighlight.y = _y; 195 | 196 | if (textNormal) 197 | { 198 | textNormal.y = _y; 199 | textHighlight.y = _y; 200 | } 201 | } 202 | 203 | public function get y():int 204 | { 205 | return _y; 206 | } 207 | 208 | //public function set scrollFactor(value:Number):void 209 | //{ 210 | //buttonNormal; 211 | //buttonHighlight; 212 | //textNormal; 213 | //textHighlight; 214 | //} 215 | 216 | override public function preUpdate():void 217 | { 218 | super.preUpdate(); 219 | 220 | if (!_initialized) 221 | { 222 | if(FlxG.stage != null) 223 | { 224 | FlxG.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); 225 | _initialized = true; 226 | } 227 | } 228 | } 229 | 230 | /** 231 | * If you wish to replace the two buttons (normal and hovered-over) with FlxSprites, then pass them here.
232 | * Note: The pixel data is extract from the passed FlxSprites and assigned locally, it doesn't actually use the sprites
233 | * or keep a reference to them. 234 | * 235 | * @param normal The FlxSprite to use when the button is in-active (not hovered over) 236 | * @param highlight The FlxSprite to use when the button is hovered-over by the mouse 237 | */ 238 | public function loadGraphic(normal:FlxSprite, highlight:FlxSprite):void 239 | { 240 | buttonNormal.pixels = normal.framePixels; 241 | buttonHighlight.pixels = highlight.framePixels; 242 | 243 | width = buttonNormal.width; 244 | height = buttonNormal.height; 245 | 246 | if (_pressed) 247 | { 248 | buttonNormal.visible = false; 249 | } 250 | else 251 | { 252 | buttonHighlight.visible = false; 253 | } 254 | } 255 | 256 | /** 257 | * Called by the game loop automatically, handles mouseover and click detection. 258 | */ 259 | override public function update():void 260 | { 261 | updateButton(); //Basic button logic 262 | } 263 | 264 | /** 265 | * Basic button update logic 266 | */ 267 | protected function updateButton():void 268 | { 269 | var prevStatus:uint = _status; 270 | 271 | if (FlxG.mouse.visible) 272 | { 273 | if (buttonNormal.cameras == null) 274 | { 275 | buttonNormal.cameras = FlxG.cameras; 276 | } 277 | 278 | var c:FlxCamera; 279 | var i:uint = 0; 280 | var l:uint = buttonNormal.cameras.length; 281 | var offAll:Boolean = true; 282 | 283 | while(i < l) 284 | { 285 | c = buttonNormal.cameras[i++] as FlxCamera; 286 | 287 | if (FlxMath.mouseInFlxRect(false, buttonNormal.rect)) 288 | { 289 | offAll = false; 290 | 291 | if (FlxG.mouse.justPressed()) 292 | { 293 | _status = PRESSED; 294 | } 295 | 296 | if (_status == NORMAL) 297 | { 298 | _status = HIGHLIGHT; 299 | } 300 | } 301 | } 302 | 303 | if (offAll) 304 | { 305 | _status = NORMAL; 306 | } 307 | } 308 | 309 | if (_status != prevStatus) 310 | { 311 | if (_status == NORMAL) 312 | { 313 | buttonNormal.visible = true; 314 | buttonHighlight.visible = false; 315 | 316 | if (textNormal) 317 | { 318 | textNormal.visible = true; 319 | textHighlight.visible = false; 320 | } 321 | 322 | if (leaveCallback is Function) 323 | { 324 | leaveCallback.apply(null, leaveCallbackParams); 325 | } 326 | } 327 | else if (_status == HIGHLIGHT) 328 | { 329 | buttonNormal.visible = false; 330 | buttonHighlight.visible = true; 331 | 332 | if (textNormal) 333 | { 334 | textNormal.visible = false; 335 | textHighlight.visible = true; 336 | } 337 | 338 | if (enterCallback is Function) 339 | { 340 | enterCallback.apply(null, enterCallbackParams); 341 | } 342 | } 343 | } 344 | } 345 | 346 | override public function draw():void 347 | { 348 | super.draw(); 349 | } 350 | 351 | /** 352 | * Called by the game state when state is changed (if this object belongs to the state) 353 | */ 354 | override public function destroy():void 355 | { 356 | if (FlxG.stage != null) 357 | { 358 | FlxG.stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp); 359 | } 360 | 361 | if (buttonNormal != null) 362 | { 363 | buttonNormal.destroy(); 364 | buttonNormal = null; 365 | } 366 | 367 | if (buttonHighlight != null) 368 | { 369 | buttonHighlight.destroy(); 370 | buttonHighlight = null; 371 | } 372 | 373 | if (textNormal != null) 374 | { 375 | textNormal.destroy(); 376 | textNormal = null; 377 | } 378 | 379 | if (textHighlight != null) 380 | { 381 | textHighlight.destroy(); 382 | textHighlight = null; 383 | } 384 | 385 | _onClick = null; 386 | enterCallback = null; 387 | leaveCallback = null; 388 | 389 | super.destroy(); 390 | } 391 | 392 | /** 393 | * Internal function for handling the actual callback call (for UI thread dependent calls like FlxU.openURL()). 394 | */ 395 | protected function onMouseUp(event:MouseEvent):void 396 | { 397 | if (exists && visible && active && (_status == PRESSED) && (_onClick != null) && (pauseProof || !FlxG.paused)) 398 | { 399 | _onClick.apply(null, onClickParams); 400 | } 401 | } 402 | 403 | /** 404 | * If you want to change the color of this button in its in-active (not hovered over) state, then pass a new array of color values 405 | * 406 | * @param colors 407 | */ 408 | public function updateInactiveButtonColors(colors:Array):void 409 | { 410 | offColor = colors; 411 | 412 | buttonNormal.stamp(FlxGradient.createGradientFlxSprite(width - 2, height - 2, offColor), 1, 1); 413 | } 414 | 415 | /** 416 | * If you want to change the color of this button in its active (hovered over) state, then pass a new array of color values 417 | * 418 | * @param colors 419 | */ 420 | public function updateActiveButtonColors(colors:Array):void 421 | { 422 | onColor = colors; 423 | 424 | buttonHighlight.stamp(FlxGradient.createGradientFlxSprite(width - 2, height - 2, onColor), 1, 1); 425 | } 426 | 427 | /** 428 | * If this button has text, set this to change the value 429 | */ 430 | public function set text(value:String):void 431 | { 432 | if (textNormal && textNormal.text != value) 433 | { 434 | textNormal.text = value; 435 | textHighlight.text = value; 436 | } 437 | } 438 | 439 | /** 440 | * Center this button (on the X axis) Uses FlxG.width / 2 - button width / 2 to achieve this.
441 | * Doesn't take into consideration scrolling 442 | */ 443 | public function screenCenter():void 444 | { 445 | buttonNormal.x = (FlxG.width / 2) - (width / 2); 446 | buttonHighlight.x = (FlxG.width / 2) - (width / 2); 447 | 448 | if (textNormal) 449 | { 450 | textNormal.x = buttonNormal.x; 451 | textHighlight.x = buttonHighlight.x; 452 | } 453 | } 454 | 455 | /** 456 | * Sets a callback function for when this button is rolled-over with the mouse 457 | * 458 | * @param callback The function to call, will be called once when the mouse enters 459 | * @param params An optional array of parameters to pass to the function 460 | */ 461 | public function setMouseOverCallback(callback:Function, params:Array = null):void 462 | { 463 | enterCallback = callback; 464 | 465 | enterCallbackParams = params; 466 | } 467 | 468 | /** 469 | * Sets a callback function for when the mouse rolls-out of this button 470 | * 471 | * @param callback The function to call, will be called once when the mouse leaves the button 472 | * @param params An optional array of parameters to pass to the function 473 | */ 474 | public function setMouseOutCallback(callback:Function, params:Array = null):void 475 | { 476 | leaveCallback = callback; 477 | 478 | leaveCallbackParams = params; 479 | } 480 | 481 | /** 482 | * Sets a callback function for when the mouse clicks on this button 483 | * 484 | * @param callback The function to call whenever the button is clicked. 485 | * @param params An optional array of parameters that will be passed to the Callback function 486 | */ 487 | public function setOnClickCallback(callback:Function, params:Array = null):void 488 | { 489 | _onClick = callback; 490 | 491 | if (params) 492 | { 493 | onClickParams = params; 494 | } 495 | } 496 | 497 | } 498 | } 499 | -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FlxCollision.as: -------------------------------------------------------------------------------- 1 | /** 2 | * FlxCollision 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.6 Fixed bug in pixelPerfectCheck that stopped non-square rotated objects from colliding properly (thanks to joon on the flixel forums for spotting) 6 | * v1.5 Added createCameraWall 7 | * v1.4 Added pixelPerfectPointCheck() 8 | * v1.3 Update fixes bug where it wouldn't accurately perform collision on AutoBuffered rotated sprites, or sprites with offsets 9 | * v1.2 Updated for the Flixel 2.5 Plugin system 10 | * 11 | * @version 1.6 - October 8th 2011 12 | * @link http://www.photonstorm.com 13 | * @author Richard Davey / Photon Storm 14 | */ 15 | 16 | package org.flixel.plugin.photonstorm 17 | { 18 | import flash.display.BitmapData; 19 | import flash.display.Sprite; 20 | import flash.geom.ColorTransform; 21 | import flash.geom.Matrix; 22 | import flash.geom.Point; 23 | import flash.geom.Rectangle; 24 | import flash.display.BlendMode; 25 | 26 | import org.flixel.*; 27 | 28 | public class FlxCollision 29 | { 30 | public static var debug:BitmapData = new BitmapData(1, 1, false); 31 | 32 | public static var CAMERA_WALL_OUTSIDE:uint = 0; 33 | public static var CAMERA_WALL_INSIDE:uint = 1; 34 | 35 | public function FlxCollision() 36 | { 37 | } 38 | 39 | /** 40 | * A Pixel Perfect Collision check between two FlxSprites. 41 | * It will do a bounds check first, and if that passes it will run a pixel perfect match on the intersecting area. 42 | * Works with rotated, scaled and animated sprites. 43 | * 44 | * @param contact The first FlxSprite to test against 45 | * @param target The second FlxSprite to test again, sprite order is irrelevant 46 | * @param alphaTolerance The tolerance value above which alpha pixels are included. Default to 255 (must be fully opaque for collision). 47 | * @param camera If the collision is taking place in a camera other than FlxG.camera (the default/current) then pass it here 48 | * 49 | * @return Boolean True if the sprites collide, false if not 50 | */ 51 | public static function pixelPerfectCheck(contact:FlxSprite, target:FlxSprite, alphaTolerance:int = 255, camera:FlxCamera = null):Boolean 52 | { 53 | var pointA:Point = new Point; 54 | var pointB:Point = new Point; 55 | 56 | if (camera) 57 | { 58 | pointA.x = contact.x - int(camera.scroll.x * contact.scrollFactor.x) - contact.offset.x; 59 | pointA.y = contact.y - int(camera.scroll.y * contact.scrollFactor.y) - contact.offset.y; 60 | 61 | pointB.x = target.x - int(camera.scroll.x * target.scrollFactor.x) - target.offset.x; 62 | pointB.y = target.y - int(camera.scroll.y * target.scrollFactor.y) - target.offset.y; 63 | } 64 | else 65 | { 66 | pointA.x = contact.x - int(FlxG.camera.scroll.x * contact.scrollFactor.x) - contact.offset.x; 67 | pointA.y = contact.y - int(FlxG.camera.scroll.y * contact.scrollFactor.y) - contact.offset.y; 68 | 69 | pointB.x = target.x - int(FlxG.camera.scroll.x * target.scrollFactor.x) - target.offset.x; 70 | pointB.y = target.y - int(FlxG.camera.scroll.y * target.scrollFactor.y) - target.offset.y; 71 | } 72 | 73 | var boundsA:Rectangle = new Rectangle(pointA.x, pointA.y, contact.framePixels.width, contact.framePixels.height); 74 | var boundsB:Rectangle = new Rectangle(pointB.x, pointB.y, target.framePixels.width, target.framePixels.height); 75 | 76 | var intersect:Rectangle = boundsA.intersection(boundsB); 77 | 78 | if (intersect.isEmpty() || intersect.width == 0 || intersect.height == 0) 79 | { 80 | return false; 81 | } 82 | 83 | // Normalise the values or it'll break the BitmapData creation below 84 | intersect.x = Math.floor(intersect.x); 85 | intersect.y = Math.floor(intersect.y); 86 | intersect.width = Math.ceil(intersect.width); 87 | intersect.height = Math.ceil(intersect.height); 88 | 89 | if (intersect.isEmpty()) 90 | { 91 | return false; 92 | } 93 | 94 | // Thanks to Chris Underwood for helping with the translate logic :) 95 | 96 | var matrixA:Matrix = new Matrix; 97 | matrixA.translate(-(intersect.x - boundsA.x), -(intersect.y - boundsA.y)); 98 | 99 | var matrixB:Matrix = new Matrix; 100 | matrixB.translate(-(intersect.x - boundsB.x), -(intersect.y - boundsB.y)); 101 | 102 | var testA:BitmapData = contact.framePixels; 103 | var testB:BitmapData = target.framePixels; 104 | var overlapArea:BitmapData = new BitmapData(intersect.width, intersect.height, false); 105 | 106 | overlapArea.draw(testA, matrixA, new ColorTransform(1, 1, 1, 1, 255, -255, -255, alphaTolerance), BlendMode.NORMAL); 107 | overlapArea.draw(testB, matrixB, new ColorTransform(1, 1, 1, 1, 255, 255, 255, alphaTolerance), BlendMode.DIFFERENCE); 108 | 109 | // Developers: If you'd like to see how this works, display it in your game somewhere. Or you can comment it out to save a tiny bit of performance 110 | debug = overlapArea; 111 | 112 | var overlap:Rectangle = overlapArea.getColorBoundsRect(0xffffffff, 0xff00ffff); 113 | overlap.offset(intersect.x, intersect.y); 114 | 115 | if (overlap.isEmpty()) 116 | { 117 | return false; 118 | } 119 | else 120 | { 121 | return true; 122 | } 123 | } 124 | 125 | /** 126 | * A Pixel Perfect Collision check between a given x/y coordinate and an FlxSprite
127 | * 128 | * @param pointX The x coordinate of the point given in local space (relative to the FlxSprite, not game world coordinates) 129 | * @param pointY The y coordinate of the point given in local space (relative to the FlxSprite, not game world coordinates) 130 | * @param target The FlxSprite to check the point against 131 | * @param alphaTolerance The alpha tolerance level above which pixels are counted as colliding. Default to 255 (must be fully transparent for collision) 132 | * 133 | * @return Boolean True if the x/y point collides with the FlxSprite, false if not 134 | */ 135 | public static function pixelPerfectPointCheck(pointX:uint, pointY:uint, target:FlxSprite, alphaTolerance:int = 255):Boolean 136 | { 137 | // Intersect check 138 | if (FlxMath.pointInCoordinates(pointX, pointY, target.x, target.y, target.framePixels.width, target.framePixels.height) == false) 139 | { 140 | return false; 141 | } 142 | 143 | // How deep is pointX/Y within the rect? 144 | var test:BitmapData = target.framePixels; 145 | 146 | if (FlxColor.getAlpha(test.getPixel32(pointX - target.x, pointY - target.y)) >= alphaTolerance) 147 | { 148 | return true; 149 | } 150 | else 151 | { 152 | return false; 153 | } 154 | } 155 | 156 | /** 157 | * Creates a "wall" around the given camera which can be used for FlxSprite collision 158 | * 159 | * @param camera The FlxCamera to use for the wall bounds (can be FlxG.camera for the current one) 160 | * @param placement CAMERA_WALL_OUTSIDE or CAMERA_WALL_INSIDE 161 | * @param thickness The thickness of the wall in pixels 162 | * @param adjustWorldBounds Adjust the FlxG.worldBounds based on the wall (true) or leave alone (false) 163 | * 164 | * @return FlxGroup The 4 FlxTileblocks that are created are placed into this FlxGroup which should be added to your State 165 | */ 166 | public static function createCameraWall(camera:FlxCamera, placement:uint, thickness:uint, adjustWorldBounds:Boolean = false):FlxGroup 167 | { 168 | var left:FlxTileblock; 169 | var right:FlxTileblock; 170 | var top:FlxTileblock; 171 | var bottom:FlxTileblock; 172 | 173 | switch (placement) 174 | { 175 | case CAMERA_WALL_OUTSIDE: 176 | left = new FlxTileblock(camera.x - thickness, camera.y + thickness, thickness, camera.height - (thickness * 2)); 177 | right = new FlxTileblock(camera.x + camera.width, camera.y + thickness, thickness, camera.height - (thickness * 2)); 178 | top = new FlxTileblock(camera.x - thickness, camera.y - thickness, camera.width + thickness * 2, thickness); 179 | bottom = new FlxTileblock(camera.x - thickness, camera.height, camera.width + thickness * 2, thickness); 180 | 181 | if (adjustWorldBounds) 182 | { 183 | FlxG.worldBounds = new FlxRect(camera.x - thickness, camera.y - thickness, camera.width + thickness * 2, camera.height + thickness * 2); 184 | } 185 | break; 186 | 187 | case CAMERA_WALL_INSIDE: 188 | left = new FlxTileblock(camera.x, camera.y + thickness, thickness, camera.height - (thickness * 2)); 189 | right = new FlxTileblock(camera.x + camera.width - thickness, camera.y + thickness, thickness, camera.height - (thickness * 2)); 190 | top = new FlxTileblock(camera.x, camera.y, camera.width, thickness); 191 | bottom = new FlxTileblock(camera.x, camera.height - thickness, camera.width, thickness); 192 | 193 | if (adjustWorldBounds) 194 | { 195 | FlxG.worldBounds = new FlxRect(camera.x, camera.y, camera.width, camera.height); 196 | } 197 | break; 198 | } 199 | 200 | var result:FlxGroup = new FlxGroup(4); 201 | 202 | result.add(left); 203 | result.add(right); 204 | result.add(top); 205 | result.add(bottom); 206 | 207 | return result; 208 | } 209 | 210 | } 211 | 212 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FlxControl.as: -------------------------------------------------------------------------------- 1 | /** 2 | * FlxControl 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.1 Fixed and added documentation 6 | * v1.0 First release 7 | * 8 | * @version 1.1 - July 21st 2011 9 | * @link http://www.photonstorm.com 10 | * @author Richard Davey / Photon Storm 11 | */ 12 | 13 | package org.flixel.plugin.photonstorm 14 | { 15 | import flash.utils.Dictionary; 16 | import org.flixel.*; 17 | 18 | public class FlxControl extends FlxBasic 19 | { 20 | // Quick references 21 | public static var player1:FlxControlHandler; 22 | public static var player2:FlxControlHandler; 23 | public static var player3:FlxControlHandler; 24 | public static var player4:FlxControlHandler; 25 | 26 | // Additional control handlers 27 | private static var members:Dictionary = new Dictionary(true); 28 | 29 | public function FlxControl() 30 | { 31 | } 32 | 33 | /** 34 | * Creates a new FlxControlHandler. You can have as many FlxControlHandlers as you like, but you usually only have one per player. The first handler you make 35 | * will be assigned to the FlxControl.player1 var. The 2nd to FlxControl.player2 and so on for player3 and player4. Beyond this you need to keep a reference to the 36 | * handler yourself. 37 | * 38 | * @param source The FlxSprite you want this class to control. It can only control one FlxSprite at once. 39 | * @param movementType Set to either MOVEMENT_INSTANT or MOVEMENT_ACCELERATES 40 | * @param stoppingType Set to STOPPING_INSTANT, STOPPING_DECELERATES or STOPPING_NEVER 41 | * @param updateFacing If true it sets the FlxSprite.facing value to the direction pressed (default false) 42 | * @param enableArrowKeys If true it will enable all arrow keys (default) - see setCursorControl for more fine-grained control 43 | * 44 | * @return The new FlxControlHandler 45 | */ 46 | public static function create(source:FlxSprite, movementType:int, stoppingType:int, player:int = 1, updateFacing:Boolean = false, enableArrowKeys:Boolean = true):FlxControlHandler 47 | { 48 | var result:FlxControlHandler; 49 | 50 | if (player == 1) 51 | { 52 | player1 = new FlxControlHandler(source, movementType, stoppingType, updateFacing, enableArrowKeys); 53 | members[player1] = player1; 54 | result = player1; 55 | } 56 | else if (player == 2) 57 | { 58 | player2 = new FlxControlHandler(source, movementType, stoppingType, updateFacing, enableArrowKeys); 59 | members[player2] = player2; 60 | result = player2; 61 | } 62 | else if (player == 3) 63 | { 64 | player3 = new FlxControlHandler(source, movementType, stoppingType, updateFacing, enableArrowKeys); 65 | members[player3] = player3; 66 | result = player3; 67 | } 68 | else if (player == 4) 69 | { 70 | player4 = new FlxControlHandler(source, movementType, stoppingType, updateFacing, enableArrowKeys); 71 | members[player4] = player4; 72 | result = player4; 73 | } 74 | else 75 | { 76 | var newControlHandler:FlxControlHandler = new FlxControlHandler(source, movementType, stoppingType, updateFacing, enableArrowKeys); 77 | members[newControlHandler] = newControlHandler; 78 | result = newControlHandler; 79 | } 80 | 81 | return result; 82 | } 83 | 84 | /** 85 | * Removes an FlxControlHandler 86 | * 87 | * @param source The FlxControlHandler to delete 88 | * @return Boolean true if the FlxControlHandler was removed, otherwise false. 89 | */ 90 | public static function remove(source:FlxControlHandler):Boolean 91 | { 92 | if (members[source]) 93 | { 94 | delete members[source]; 95 | 96 | return true; 97 | } 98 | 99 | return false; 100 | } 101 | 102 | /** 103 | * Removes all FlxControlHandlers.
104 | * This is called automatically if this plugin is ever destroyed. 105 | */ 106 | public static function clear():void 107 | { 108 | for each (var handler:FlxControlHandler in members) 109 | { 110 | delete members[handler]; 111 | } 112 | } 113 | 114 | /** 115 | * Starts updating the given FlxControlHandler, enabling keyboard actions for it. If no FlxControlHandler is given it starts updating all FlxControlHandlers currently added.
116 | * Updating is enabled by default, but this can be used to re-start it if you have stopped it via stop().
117 | * 118 | * @param source The FlxControlHandler to start updating on. If left as null it will start updating all handlers. 119 | */ 120 | public static function start(source:FlxControlHandler = null):void 121 | { 122 | if (source) 123 | { 124 | members[source].enabled = true; 125 | } 126 | else 127 | { 128 | for each (var handler:FlxControlHandler in members) 129 | { 130 | handler.enabled = true; 131 | } 132 | } 133 | } 134 | 135 | /** 136 | * Stops updating the given FlxControlHandler. If no FlxControlHandler is given it stops updating all FlxControlHandlers currently added.
137 | * Updating is enabled by default, but this can be used to stop it, for example if you paused your game (see start() to restart it again).
138 | * 139 | * @param source The FlxControlHandler to stop updating. If left as null it will stop updating all handlers. 140 | */ 141 | public static function stop(source:FlxControlHandler = null):void 142 | { 143 | if (source) 144 | { 145 | members[source].enabled = false; 146 | } 147 | else 148 | { 149 | for each (var handler:FlxControlHandler in members) 150 | { 151 | handler.enabled = false; 152 | } 153 | } 154 | } 155 | 156 | /** 157 | * Runs update on all currently active FlxControlHandlers 158 | */ 159 | override public function update():void 160 | { 161 | for each (var handler:FlxControlHandler in members) 162 | { 163 | if (handler.enabled == true) 164 | { 165 | handler.update(); 166 | } 167 | } 168 | } 169 | 170 | /** 171 | * Runs when this plugin is destroyed 172 | */ 173 | override public function destroy():void 174 | { 175 | clear(); 176 | } 177 | 178 | } 179 | 180 | } 181 | -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FlxCoreUtils.as: -------------------------------------------------------------------------------- 1 | /** 2 | * FlxCoreUtils 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.1 Added get mouseIndex and gameContainer 6 | * v1.0 First release with copyObject 7 | * 8 | * @version 1.1 - August 4th 2011 9 | * @link http://www.photonstorm.com 10 | * @author Richard Davey / Photon Storm 11 | */ 12 | 13 | package org.flixel.plugin.photonstorm 14 | { 15 | import flash.display.Sprite; 16 | import flash.utils.ByteArray; 17 | import org.flixel.*; 18 | 19 | public class FlxCoreUtils 20 | { 21 | 22 | public function FlxCoreUtils() 23 | { 24 | } 25 | 26 | /** 27 | * Performs a complete object deep-copy and returns a duplicate (not a reference) 28 | * 29 | * @param value The object you want copied 30 | * @return A copy of this object 31 | */ 32 | public static function copyObject(value:Object):Object 33 | { 34 | var buffer:ByteArray = new ByteArray(); 35 | buffer.writeObject(value); 36 | buffer.position = 0; 37 | var result:Object = buffer.readObject(); 38 | return result; 39 | } 40 | 41 | /** 42 | * Returns the Display List index of the mouse pointer 43 | */ 44 | public static function get mouseIndex():int 45 | { 46 | var mouseIndex:int = -1; 47 | 48 | try 49 | { 50 | mouseIndex = FlxG.camera.getContainerSprite().parent.numChildren - 4; 51 | } 52 | catch (e:Error) 53 | { 54 | //trace 55 | } 56 | 57 | return mouseIndex; 58 | } 59 | 60 | /** 61 | * Returns the Sprite that FlxGame extends (which contains the cameras, mouse, etc) 62 | */ 63 | public static function get gameContainer():Sprite 64 | { 65 | return Sprite(FlxG.camera.getContainerSprite().parent); 66 | } 67 | 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FlxDelay.as: -------------------------------------------------------------------------------- 1 | /** 2 | * FlxDelay 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.4 Modified abort so it no longer runs the stop callback (thanks to Cambrian-Man) 6 | * v1.3 Added secondsElapsed and secondsRemaining and some more documentation 7 | * v1.2 Added callback support 8 | * v1.1 Updated for the Flixel 2.5 Plugin system 9 | * 10 | * @version 1.4 - July 31st 2011 11 | * @link http://www.photonstorm.com 12 | * @author Richard Davey / Photon Storm 13 | */ 14 | 15 | package org.flixel.plugin.photonstorm 16 | { 17 | import flash.display.Sprite; 18 | import flash.events.Event; 19 | import flash.events.EventDispatcher; 20 | import flash.utils.getTimer; 21 | 22 | import org.flixel.*; 23 | 24 | /** 25 | * A useful timer that can be used to trigger events after certain amounts of time are up. 26 | * Uses getTimer so is low on resources and avoids using Flash events. 27 | * Also takes into consideration the Pause state of your game. 28 | * If your game pauses, when it starts again the timer notices and adjusts the expires time accordingly. 29 | */ 30 | 31 | public class FlxDelay extends Sprite 32 | { 33 | /** 34 | * true if the timer is currently running, otherwise false 35 | */ 36 | public var isRunning:Boolean; 37 | 38 | /** 39 | * If you wish to call a function once the timer completes, set it here 40 | */ 41 | public var callback:Function; 42 | 43 | /** 44 | * The duration of the Delay in milliseconds 45 | */ 46 | public var duration:int; 47 | 48 | private var started:int; 49 | private var expires:int; 50 | private var pauseStarted:int; 51 | private var pausedTimerRunning:Boolean; 52 | private var complete:Boolean; 53 | 54 | /** 55 | * Create a new timer which will run for the given amount of ms (1000 = 1 second real time) 56 | * 57 | * @param runFor The duration of this timer in ms. Call start() to set it going. 58 | */ 59 | public function FlxDelay(runFor:int) 60 | { 61 | duration = runFor; 62 | } 63 | 64 | /** 65 | * Starts the timer running 66 | */ 67 | public function start():void 68 | { 69 | started = getTimer(); 70 | expires = started + duration; 71 | isRunning = true; 72 | complete = false; 73 | 74 | pauseStarted = 0; 75 | pausedTimerRunning = false; 76 | 77 | addEventListener(Event.ENTER_FRAME, update, false, 0, true); 78 | } 79 | 80 | /** 81 | * Has the timer finished? 82 | */ 83 | public function get hasExpired():Boolean 84 | { 85 | return complete; 86 | } 87 | 88 | /** 89 | * Restart the timer using the new duration 90 | * 91 | * @param newDuration The duration of this timer in ms. 92 | */ 93 | public function reset(newDuration:int):void 94 | { 95 | duration = newDuration; 96 | 97 | start(); 98 | } 99 | 100 | /** 101 | * The amount of seconds that have elapsed since the timer was started 102 | */ 103 | public function get secondsElapsed():int 104 | { 105 | return int((getTimer() - started) / 1000); 106 | } 107 | 108 | /** 109 | * The amount of seconds that are remaining until the timer completes 110 | */ 111 | public function get secondsRemaining():int 112 | { 113 | return int((expires - getTimer()) / 1000); 114 | } 115 | 116 | private function update(event:Event):void 117 | { 118 | // Has the game been paused? 119 | if (pausedTimerRunning == true && FlxG.paused == false) 120 | { 121 | pausedTimerRunning = false; 122 | 123 | // Add the time the game was paused for onto the expires timer 124 | expires += (getTimer() - pauseStarted); 125 | } 126 | else if (FlxG.paused == true && pausedTimerRunning == false) 127 | { 128 | pauseStarted = getTimer(); 129 | pausedTimerRunning = true; 130 | } 131 | 132 | if (isRunning && pausedTimerRunning == false && getTimer() > expires) 133 | { 134 | stop(); 135 | } 136 | } 137 | 138 | /** 139 | * Abors a currently active timer without firing any callbacks (if set) 140 | */ 141 | public function abort():void 142 | { 143 | stop(false); 144 | } 145 | 146 | private function stop(runCallback:Boolean = true):void 147 | { 148 | removeEventListener(Event.ENTER_FRAME, update); 149 | 150 | isRunning = false; 151 | complete = true; 152 | 153 | if (callback is Function && runCallback == true) 154 | { 155 | callback.call(); 156 | } 157 | 158 | } 159 | 160 | } 161 | 162 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FlxDisplay.as: -------------------------------------------------------------------------------- 1 | /** 2 | * FlxDisplay 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.3 Added "screenWrap", "alphaMask" and "alphaMaskFlxSprite" methods 6 | * v1.2 Added "space" method 7 | * v1.1 Updated for the Flixel 2.5 Plugin system 8 | * 9 | * @version 1.3 - June 15th 2011 10 | * @link http://www.photonstorm.com 11 | * @author Richard Davey / Photon Storm 12 | */ 13 | 14 | package org.flixel.plugin.photonstorm 15 | { 16 | import flash.display.BitmapData; 17 | import flash.display.BitmapDataChannel; 18 | import flash.geom.Point; 19 | import flash.geom.Rectangle; 20 | import org.flixel.*; 21 | 22 | public class FlxDisplay 23 | { 24 | 25 | public function FlxDisplay() 26 | { 27 | } 28 | 29 | public function pad():void 30 | { 31 | // Pad the sprite out with empty pixels left/right/above/below it 32 | } 33 | 34 | public function flip():void 35 | { 36 | // mirror / reverse? 37 | // Flip image data horizontally / vertically without changing the angle 38 | } 39 | 40 | /** 41 | * Takes two source images (typically from Embedded bitmaps) and puts the resulting image into the output FlxSprite.
42 | * Note: It assumes the source and mask are the same size. Different sizes may result in undesired results.
43 | * It works by copying the source image (your picture) into the output sprite. Then it removes all areas of it that do not
44 | * have an alpha color value in the mask image. So if you draw a big black circle in your mask with a transparent edge, you'll
45 | * get a circular image appear. Look at the mask PNG files in the assets/pics folder for examples. 46 | * 47 | * @param source The source image. Typically the one with the image / picture / texture in it. 48 | * @param mask The mask to apply. Remember the non-alpha zero areas are the parts that will display. 49 | * @param output The FlxSprite you wish the resulting image to be placed in (will adjust width/height of image) 50 | * 51 | * @return The output FlxSprite for those that like chaining 52 | */ 53 | public static function alphaMask(source:Class, mask:Class, output:FlxSprite):FlxSprite 54 | { 55 | var data:BitmapData = (new source).bitmapData; 56 | 57 | data.copyChannel((new mask).bitmapData, new Rectangle(0, 0, data.width, data.height), new Point, BitmapDataChannel.ALPHA, BitmapDataChannel.ALPHA); 58 | 59 | output.pixels = data; 60 | 61 | return output; 62 | } 63 | 64 | /** 65 | * Takes the image data from two FlxSprites and puts the resulting image into the output FlxSprite.
66 | * Note: It assumes the source and mask are the same size. Different sizes may result in undesired results.
67 | * It works by copying the source image (your picture) into the output sprite. Then it removes all areas of it that do not
68 | * have an alpha color value in the mask image. So if you draw a big black circle in your mask with a transparent edge, you'll
69 | * get a circular image appear. Look at the mask PNG files in the assets/pics folder for examples. 70 | * 71 | * @param source The source FlxSprite. Typically the one with the image / picture / texture in it. 72 | * @param mask The FlxSprite containing the mask to apply. Remember the non-alpha zero areas are the parts that will display. 73 | * @param output The FlxSprite you wish the resulting image to be placed in (will adjust width/height of image) 74 | * 75 | * @return The output FlxSprite for those that like chaining 76 | */ 77 | public static function alphaMaskFlxSprite(source:FlxSprite, mask:FlxSprite, output:FlxSprite):FlxSprite 78 | { 79 | var data:BitmapData = source.pixels; 80 | 81 | data.copyChannel(mask.pixels, new Rectangle(0, 0, source.width, source.height), new Point, BitmapDataChannel.ALPHA, BitmapDataChannel.ALPHA); 82 | 83 | output.pixels = data; 84 | 85 | return output; 86 | } 87 | 88 | /** 89 | * Checks the x/y coordinates of the source FlxSprite and keeps them within the area of 0, 0, FlxG.width, FlxG.height (i.e. wraps it around the screen) 90 | * 91 | * @param source The FlxSprite to keep within the screen 92 | */ 93 | public static function screenWrap(source:FlxSprite):void 94 | { 95 | if (source.x < 0) 96 | { 97 | source.x = FlxG.width; 98 | } 99 | else if (source.x > FlxG.width) 100 | { 101 | source.x = 0; 102 | } 103 | 104 | if (source.y < 0) 105 | { 106 | source.y = FlxG.height; 107 | } 108 | else if (source.y > FlxG.height) 109 | { 110 | source.y = 0; 111 | } 112 | } 113 | 114 | /** 115 | * Takes the bitmapData from the given source FlxSprite and rotates it 90 degrees clockwise.
116 | * Can be useful if you need to control a sprite under rotation but it isn't drawn facing right.
117 | * This change overwrites FlxSprite.pixels, but will not work with animated sprites. 118 | * 119 | * @param source The FlxSprite who's image data you wish to rotate clockwise 120 | */ 121 | public static function rotateClockwise(source:FlxSprite):void 122 | { 123 | } 124 | 125 | /** 126 | * Aligns a set of FlxSprites so there is equal spacing between them 127 | * 128 | * @param sprites An Array of FlxSprites 129 | * @param startX The base X coordinate to start the spacing from 130 | * @param startY The base Y coordinate to start the spacing from 131 | * @param horizontalSpacing The amount of pixels between each sprite horizontally (default 0) 132 | * @param verticalSpacing The amount of pixels between each sprite vertically (default 0) 133 | * @param spaceFromBounds If set to true the h/v spacing values will be added to the width/height of the sprite, if false it will ignore this 134 | */ 135 | public static function space(sprites:Array, startX:int, startY:int, horizontalSpacing:int = 0, verticalSpacing:int = 0, spaceFromBounds:Boolean = false):void 136 | { 137 | var prevWidth:int = 0; 138 | var prevHeight:int = 0; 139 | 140 | for (var i:int = 0; i < sprites.length; i++) 141 | { 142 | var sprite:FlxSprite = sprites[i]; 143 | 144 | if (spaceFromBounds) 145 | { 146 | sprite.x = startX + prevWidth + (i * horizontalSpacing); 147 | sprite.y = startY + prevHeight + (i * verticalSpacing); 148 | } 149 | else 150 | { 151 | sprite.x = startX + (i * horizontalSpacing); 152 | sprite.y = startY + (i * verticalSpacing); 153 | } 154 | } 155 | } 156 | 157 | /** 158 | * Centers the given FlxSprite on the screen, either by the X axis, Y axis, or both 159 | * 160 | * @param source The FlxSprite to center 161 | * @param xAxis Boolean true if you want it centered on X (i.e. in the middle of the screen) 162 | * @param yAxis Boolean true if you want it centered on Y 163 | * 164 | * @return The FlxSprite for chaining 165 | */ 166 | public static function screenCenter(source:FlxSprite, xAxis:Boolean = true, yAxis:Boolean = false):FlxSprite 167 | { 168 | if (xAxis) 169 | { 170 | source.x = (FlxG.width / 2) - (source.width / 2); 171 | } 172 | 173 | if (yAxis) 174 | { 175 | source.y = (FlxG.height / 2) - (source.height / 2); 176 | } 177 | 178 | return source; 179 | } 180 | 181 | } 182 | 183 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FlxExplode.as: -------------------------------------------------------------------------------- 1 | package org.flixel.plugin.photonstorm 2 | { 3 | /** 4 | * ... 5 | * @author Richard Davey 6 | */ 7 | public class FlxExplode 8 | { 9 | 10 | public function FlxExplode() 11 | { 12 | 13 | } 14 | 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FlxFlod.as: -------------------------------------------------------------------------------- 1 | /** 2 | * FlxFlod 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.3 Added full FlxFlectrum support 6 | * v1.2 Updated for the Flixel 2.5 Plugin system 7 | * 8 | * @version 1.3 - July 29th 2011 9 | * @link http://www.photonstorm.com 10 | * @author Richard Davey / Photon Storm 11 | */ 12 | 13 | package org.flixel.plugin.photonstorm 14 | { 15 | import neoart.flectrum.Flectrum; 16 | import neoart.flectrum.SoundEx; 17 | import org.flixel.*; 18 | import neoart.flod.*; 19 | 20 | import flash.utils.ByteArray; 21 | import flash.media.SoundTransform; 22 | 23 | /** 24 | * FlxFlod adds support for the Flod AS3 Replay library by Christian Corti.
25 | * Flod is an incredibly powerful library allowing you to play tracker music from the Amiga / ST / PC (SoundTracker, ProTracker, etc)
26 | * More information about Flod can be found here: http://www.photonstorm.com/flod

27 | * 28 | * This class works without modifying flixel, however the mute/volume/pause/resume commands won't be hooked into flixel.
29 | * You can either use a patched version of Flixel which is provided in this repository:
30 | * flash-game-dev-tips\Flixel Versions\Flixel v2.43 Patch 1.0 31 | *
32 | * Or you can patch FlxG manually by doing the following:

33 | * 34 | * 1) Add import com.photonstorm.flixel.FlxFlod; at the top of FlxG.as:
35 | * 2) Find the function static public function set mute(Mute:Boolean):void and add this line at the end of it: FlxFlod.mute = Mute;
36 | * 3) Find the function static public function set volume(Volume:Number):void and add this line at the end of it: FlxFlod.volume = Volume;
37 | * 4) Find the function static protected function pauseSounds():void and add this line at the end of it: FlxFlod.pause();
38 | * 5) Find the function static protected function playSounds():void and add this line at the end of it: FlxFlod.resume();

39 | * 40 | * Flixel will now be patched so that any music playing via FlxFlod responds to the global flixel mute, volume and pause controls 41 | */ 42 | 43 | public class FlxFlod 44 | { 45 | private static var processor:ModProcessor; 46 | private static var modStream:ByteArray; 47 | private static var soundform:SoundTransform = new SoundTransform(); 48 | 49 | private static var fadeTimer:FlxDelay; 50 | 51 | private static var callbackHooksCreated:Boolean = false; 52 | 53 | private static var sound:SoundEx = new SoundEx; 54 | public static var flectrum:FlxFlectrum; 55 | 56 | /** 57 | * Starts playback of a tracker module 58 | * 59 | * @param toon The music to play 60 | * 61 | * @return Boolean true if playback started successfully, false if not 62 | */ 63 | public static function playMod(toon:Class):Boolean 64 | { 65 | stopMod(); 66 | 67 | modStream = new toon() as ByteArray; 68 | 69 | processor = new ModProcessor(); 70 | 71 | if (processor.load(modStream)) 72 | { 73 | processor.loopSong = true; 74 | processor.stereo = 0; 75 | processor.play(sound); 76 | 77 | if (processor.soundChannel) 78 | { 79 | soundform.volume = FlxG.volume; 80 | processor.soundChannel.soundTransform = soundform; 81 | } 82 | 83 | if (callbackHooksCreated == false) 84 | { 85 | FlxG.volumeHandler = updateVolume; 86 | callbackHooksCreated = true; 87 | } 88 | 89 | return true; 90 | 91 | } 92 | else 93 | { 94 | return false; 95 | } 96 | } 97 | 98 | /** 99 | * Creates a Flectrum (VU Meter / Spectrum Analyser) 100 | * 101 | * @param x The x position of the flectrum in game world coordinates 102 | * @param y The y position of the flectrum in game world coordinates 103 | * @param meter A graphic to use for the meter (bar) of the flectrum. Default null uses a solid fill rectangle. 104 | * @param showBackground Display an alpha background behind the meters 105 | * @param backgroundBeat Makes the alpha background pulsate in time to the music 106 | * @param columns The number of columns in the flectrum 107 | * @param columnSize The width of each column in pixels - if you use your own meter graphic this value is ignored 108 | * @param columnSpacing The spacing in pixels between each column (meter) of the flectrum 109 | * @param rows The number of rows in the flectrum 110 | * @param rowSize The height of each row. Overall flectrum height is rowSize + rowSpacing * rows - if you use your own meter graphic this value is ignored 111 | * @param rowSpacing The spacing in pixels between each row of the flectrum - if you use your own meter graphic this value is ignored 112 | * 113 | * @return The FlxFlectrum instance for further modification. Also available via FlxFlod.flectrum 114 | */ 115 | public static function createFlectrum(x:int, y:int, meter:Class = null, showBackground:Boolean = false, backgroundBeat:Boolean = false, columns:int = 15, columnSize:int = 10, columnSpacing:int = 0, rows:int = 32, rowSize:int = 3, rowSpacing:int = 0):FlxFlectrum 116 | { 117 | flectrum = new FlxFlectrum(); 118 | 119 | flectrum.init(x, y, sound, columns, columnSize, columnSpacing, rows, rowSize, rowSpacing); 120 | 121 | if (meter) 122 | { 123 | flectrum.useBitmap(meter); 124 | } 125 | 126 | flectrum.showBackground = showBackground; 127 | flectrum.backgroundBeat = backgroundBeat; 128 | 129 | return flectrum; 130 | } 131 | 132 | /** 133 | * Pauses playback of this module, if started 134 | */ 135 | public static function pause():void 136 | { 137 | if (processor) 138 | { 139 | processor.pause(); 140 | } 141 | } 142 | 143 | /** 144 | * Resumes playback of this module if paused 145 | */ 146 | public static function resume():void 147 | { 148 | if (processor) 149 | { 150 | processor.resume(); 151 | } 152 | } 153 | 154 | /** 155 | * Stops playback of this module, if started 156 | */ 157 | public static function stopMod():void 158 | { 159 | if (processor) 160 | { 161 | processor.stop(); 162 | } 163 | } 164 | 165 | /** 166 | * Toggles playback mute 167 | */ 168 | public static function set mute(Mute:Boolean):void 169 | { 170 | if (processor) 171 | { 172 | if (Mute) 173 | { 174 | if (processor.soundChannel) 175 | { 176 | soundform.volume = 0; 177 | processor.soundChannel.soundTransform = soundform; 178 | } 179 | } 180 | else 181 | { 182 | if (processor.soundChannel) 183 | { 184 | soundform.volume = FlxG.volume; 185 | processor.soundChannel.soundTransform = soundform; 186 | } 187 | } 188 | } 189 | } 190 | 191 | /** 192 | * Called by FlxG when the volume is adjusted in-game 193 | * 194 | * @param Volume 195 | */ 196 | public static function updateVolume(Volume:Number):void 197 | { 198 | volume = Volume; 199 | } 200 | 201 | /** 202 | * Sets the playback volume directly (usually controlled by FlxG.volume) 203 | */ 204 | public static function set volume(Volume:Number):void 205 | { 206 | if (processor) 207 | { 208 | if (processor.soundChannel) 209 | { 210 | soundform.volume = Volume; 211 | processor.soundChannel.soundTransform = soundform; 212 | } 213 | } 214 | } 215 | 216 | /** 217 | * Is a tune already playing? 218 | */ 219 | public static function get isPlaying():Boolean 220 | { 221 | if (processor) 222 | { 223 | return processor.isPlaying; 224 | } 225 | else 226 | { 227 | return false; 228 | } 229 | } 230 | 231 | /** 232 | * Is a tune paused? 233 | */ 234 | public static function get isPaused():Boolean 235 | { 236 | if (processor) 237 | { 238 | return processor.isPaused; 239 | } 240 | else 241 | { 242 | return false; 243 | } 244 | } 245 | 246 | } 247 | 248 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FlxGradient.as: -------------------------------------------------------------------------------- 1 | /** 2 | * FlxGradient 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.6 Fixed bug where gradients with chunk sizes > 1 would ignore alpha values 6 | * v1.5 Alpha values used in the gradient map 7 | * v1.4 Updated for the Flixel 2.5 Plugin system 8 | * 9 | * @version 1.6 - May 9th 2011 10 | * @link http://www.photonstorm.com 11 | * @author Richard Davey / Photon Storm 12 | * @see Requires FlxMath 13 | */ 14 | 15 | package org.flixel.plugin.photonstorm 16 | { 17 | import flash.geom.Point; 18 | import flash.geom.Rectangle; 19 | import org.flixel.*; 20 | 21 | import flash.display.Bitmap; 22 | import flash.geom.Matrix; 23 | import flash.display.BitmapData; 24 | import flash.display.Shape; 25 | import flash.display.GradientType; 26 | import flash.display.SpreadMethod; 27 | import flash.display.InterpolationMethod; 28 | 29 | /** 30 | * Adds a set of color gradient creation / rendering functions 31 | */ 32 | public class FlxGradient 33 | { 34 | 35 | public function FlxGradient() 36 | { 37 | } 38 | 39 | public static function createGradientMatrix(width:int, height:int, colors:Array, chunkSize:int = 1, rotation:int = 90):Object 40 | { 41 | var gradientMatrix:Matrix = new Matrix(); 42 | 43 | // Rotation (in radians) that the gradient is rotated 44 | var rot:Number = FlxMath.asRadians(rotation); 45 | 46 | // Last 2 values = horizontal and vertical shift (in pixels) 47 | if (chunkSize == 1) 48 | { 49 | gradientMatrix.createGradientBox(width, height, rot, 0, 0); 50 | } 51 | else 52 | { 53 | gradientMatrix.createGradientBox(width, height / chunkSize, rot, 0, 0); 54 | } 55 | 56 | // Create the alpha and ratio arrays 57 | 58 | var alpha:Array = new Array(); 59 | 60 | for (var ai:int = 0; ai < colors.length; ai++) 61 | { 62 | alpha.push(FlxColor.getAlphaFloat(colors[ai])); 63 | } 64 | 65 | var ratio:Array = new Array(); 66 | 67 | if (colors.length == 2) 68 | { 69 | ratio[0] = 0; 70 | ratio[1] = 255; 71 | } 72 | else 73 | { 74 | // Spread value 75 | var spread:int = 255 / (colors.length - 1); 76 | 77 | ratio.push(0); 78 | 79 | for (var ri:int = 1; ri < colors.length - 1; ri++) 80 | { 81 | ratio.push(ri * spread); 82 | } 83 | 84 | ratio.push(255); 85 | } 86 | 87 | return { matrix: gradientMatrix, alpha: alpha, ratio: ratio }; 88 | } 89 | 90 | public static function createGradientArray(width:int, height:int, colors:Array, chunkSize:int = 1, rotation:int = 90, interpolate:Boolean = true):Array 91 | { 92 | var data:BitmapData = createGradientBitmapData(width, height, colors, chunkSize, rotation, interpolate); 93 | 94 | var result:Array = new Array(); 95 | 96 | for (var y:int = 0; y < data.height; y++) 97 | { 98 | result.push(data.getPixel32(0, y)); 99 | } 100 | 101 | return result; 102 | } 103 | 104 | /** 105 | * Creates an FlxSprite of the given width/height with a colour gradient flowing through it. 106 | * 107 | * @param width The width of the FlxSprite (and therefore gradient) 108 | * @param height The height of the FlxSprite (and therefore gradient) 109 | * @param colors An array of colour values for the gradient to cycle through 110 | * @param chunkSize If you want a more old-skool looking chunky gradient, increase this value! 111 | * @param rotation Angle of the gradient in degrees. 90 = top to bottom, 180 = left to right. Any angle is valid 112 | * @param interpolate Interpolate the colours? True uses RGB interpolation, false uses linear RGB 113 | * 114 | * @return An FlxSprite containing your gradient (if valid parameters given!) 115 | */ 116 | public static function createGradientFlxSprite(width:int, height:int, colors:Array, chunkSize:int = 1, rotation:int = 90, interpolate:Boolean = true):FlxSprite 117 | { 118 | var data:BitmapData = createGradientBitmapData(width, height, colors, chunkSize, rotation, interpolate); 119 | 120 | var dest:FlxSprite = new FlxSprite().makeGraphic(width, height); 121 | 122 | dest.pixels = data; 123 | 124 | return dest; 125 | } 126 | 127 | public static function createGradientBitmapData(width:int, height:int, colors:Array, chunkSize:int = 1, rotation:int = 90, interpolate:Boolean = true):BitmapData 128 | { 129 | // Sanity checks 130 | if (width < 1) 131 | { 132 | width = 1; 133 | } 134 | 135 | if (height < 1) 136 | { 137 | height = 1; 138 | } 139 | 140 | var gradient:Object = createGradientMatrix(width, height, colors, chunkSize, rotation); 141 | 142 | var s:Shape = new Shape(); 143 | 144 | if (interpolate) 145 | { 146 | s.graphics.beginGradientFill(GradientType.LINEAR, colors, gradient.alpha, gradient.ratio, gradient.matrix, SpreadMethod.PAD, InterpolationMethod.RGB, 0); 147 | } 148 | else 149 | { 150 | s.graphics.beginGradientFill(GradientType.LINEAR, colors, gradient.alpha, gradient.ratio, gradient.matrix, SpreadMethod.PAD, InterpolationMethod.LINEAR_RGB, 0); 151 | } 152 | 153 | if (chunkSize == 1) 154 | { 155 | s.graphics.drawRect(0, 0, width, height); 156 | } 157 | else 158 | { 159 | s.graphics.drawRect(0, 0, width, height / chunkSize); 160 | } 161 | 162 | var data:BitmapData = new BitmapData(width, height, true, 0x0); 163 | 164 | if (chunkSize == 1) 165 | { 166 | data.draw(s); 167 | } 168 | else 169 | { 170 | var tempBitmap:Bitmap = new Bitmap(new BitmapData(width, height / chunkSize, true, 0x0)); 171 | tempBitmap.bitmapData.draw(s); 172 | tempBitmap.scaleY = chunkSize; 173 | 174 | var sM:Matrix = new Matrix(); 175 | sM.scale(tempBitmap.scaleX, tempBitmap.scaleY); 176 | 177 | data.draw(tempBitmap, sM); 178 | } 179 | 180 | return data; 181 | } 182 | 183 | /** 184 | * Creates a new gradient and overlays that on-top of the given FlxSprite at the destX/destY coordinates (default 0,0)
185 | * Use low alpha values in the colours to have the gradient overlay and not destroy the image below 186 | * 187 | * @param dest The FlxSprite to overlay the gradient onto 188 | * @param width The width of the FlxSprite (and therefore gradient) 189 | * @param height The height of the FlxSprite (and therefore gradient) 190 | * @param colors An array of colour values for the gradient to cycle through 191 | * @param destX The X offset the gradient is drawn at (default 0) 192 | * @param destY The Y offset the gradient is drawn at (default 0) 193 | * @param chunkSize If you want a more old-skool looking chunky gradient, increase this value! 194 | * @param rotation Angle of the gradient in degrees. 90 = top to bottom, 180 = left to right. Any angle is valid 195 | * @param interpolate Interpolate the colours? True uses RGB interpolation, false uses linear RGB 196 | * @return The composited FlxSprite (for chaining, if you need) 197 | */ 198 | public static function overlayGradientOnFlxSprite(dest:FlxSprite, width:int, height:int, colors:Array, destX:int = 0, destY:int = 0, chunkSize:int = 1, rotation:int = 90, interpolate:Boolean = true):FlxSprite 199 | { 200 | if (width > dest.width) 201 | { 202 | width = dest.width; 203 | } 204 | 205 | if (height > dest.height) 206 | { 207 | height = dest.height; 208 | } 209 | 210 | var source:FlxSprite = createGradientFlxSprite(width, height, colors, chunkSize, rotation, interpolate); 211 | 212 | dest.stamp(source, destX, destY); 213 | 214 | return dest; 215 | } 216 | 217 | /** 218 | * Creates a new gradient and overlays that on-top of the given BitmapData at the destX/destY coordinates (default 0,0)
219 | * Use low alpha values in the colours to have the gradient overlay and not destroy the image below 220 | * 221 | * @param dest The BitmapData to overlay the gradient onto 222 | * @param width The width of the FlxSprite (and therefore gradient) 223 | * @param height The height of the FlxSprite (and therefore gradient) 224 | * @param colors An array of colour values for the gradient to cycle through 225 | * @param destX The X offset the gradient is drawn at (default 0) 226 | * @param destY The Y offset the gradient is drawn at (default 0) 227 | * @param chunkSize If you want a more old-skool looking chunky gradient, increase this value! 228 | * @param rotation Angle of the gradient in degrees. 90 = top to bottom, 180 = left to right. Any angle is valid 229 | * @param interpolate Interpolate the colours? True uses RGB interpolation, false uses linear RGB 230 | * @return The composited BitmapData 231 | */ 232 | public static function overlayGradientOnBitmapData(dest:BitmapData, width:int, height:int, colors:Array, destX:int = 0, destY:int = 0, chunkSize:int = 1, rotation:int = 90, interpolate:Boolean = true):BitmapData 233 | { 234 | if (width > dest.width) 235 | { 236 | width = dest.width; 237 | } 238 | 239 | if (height > dest.height) 240 | { 241 | height = dest.height; 242 | } 243 | 244 | var source:BitmapData = createGradientBitmapData(width, height, colors, chunkSize, rotation, interpolate); 245 | 246 | dest.copyPixels(source, new Rectangle(0, 0, source.width, source.height), new Point(destX, destY), null, null, true); 247 | 248 | return dest; 249 | } 250 | 251 | } 252 | 253 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FlxGridOverlay.as: -------------------------------------------------------------------------------- 1 | /** 2 | * FlxGridOverlay 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.1 Updated for the Flixel 2.5 Plugin system 6 | * 7 | * @version 1.1 - April 23rd 2011 8 | * @link http://www.photonstorm.com 9 | * @author Richard Davey / Photon Storm 10 | */ 11 | 12 | package org.flixel.plugin.photonstorm 13 | { 14 | import flash.display.BitmapData; 15 | import flash.geom.Point; 16 | import flash.geom.Rectangle; 17 | import org.flixel.*; 18 | 19 | public class FlxGridOverlay 20 | { 21 | public function FlxGridOverlay() 22 | { 23 | } 24 | 25 | /** 26 | * Creates an FlxSprite of the given width and height filled with a checkerboard pattern.
27 | * Each grid cell is the specified width and height, and alternates between two colors.
28 | * If alternate is true each row of the pattern will be offset, for a proper checkerboard style. If false each row will be the same colour, creating a striped-pattern effect.
29 | * So to create an 8x8 grid you'd call create(8,8) 30 | * 31 | * @param cellWidth The grid cell width 32 | * @param cellHeight The grid cell height 33 | * @param width The width of the FlxSprite. If -1 it will be the size of the game (FlxG.width) 34 | * @param height The height of the FlxSprite. If -1 it will be the size of the game (FlxG.height) 35 | * @param addLegend TODO 36 | * @param alternate Should the pattern alternate on each new row? Default true = checkerboard effect. False = vertical stripes 37 | * @param color1 The first fill colour in 0xAARRGGBB format 38 | * @param color2 The second fill colour in 0xAARRGGBB format 39 | * 40 | * @return FlxSprite of given width/height 41 | */ 42 | public static function create(cellWidth:int, cellHeight:int, width:int = -1, height:int = -1, addLegend:Boolean = false, alternate:Boolean = true, color1:uint = 0xffe7e6e6, color2:uint = 0xffd9d5d5):FlxSprite 43 | { 44 | if (width == -1) 45 | { 46 | width = FlxG.width; 47 | } 48 | 49 | if (height == -1) 50 | { 51 | height = FlxG.height; 52 | } 53 | 54 | if (width < cellWidth || height < cellHeight) 55 | { 56 | return null; 57 | } 58 | 59 | var grid:BitmapData = createGrid(cellWidth, cellHeight, width, height, alternate, color1, color2); 60 | 61 | var output:FlxSprite = new FlxSprite().makeGraphic(width, height); 62 | 63 | output.pixels = grid; 64 | output.dirty = true; 65 | 66 | return output; 67 | } 68 | 69 | /** 70 | * Creates a checkerboard pattern of the given width/height and overlays it onto the given FlxSprite.
71 | * Each grid cell is the specified width and height, and alternates between two colors.
72 | * If alternate is true each row of the pattern will be offset, for a proper checkerboard style. If false each row will be the same colour, creating a striped-pattern effect.
73 | * So to create an 8x8 grid you'd call create(8,8, 74 | * 75 | * @param source The FlxSprite you wish to draw the grid on-top of. This updates its pixels value, not just the current frame (don't use animated sprites!) 76 | * @param cellWidth The grid cell width 77 | * @param cellHeight The grid cell height 78 | * @param width The width of the FlxSprite. If -1 it will be the size of the game (FlxG.width) 79 | * @param height The height of the FlxSprite. If -1 it will be the size of the game (FlxG.height) 80 | * @param addLegend TODO 81 | * @param alternate Should the pattern alternate on each new row? Default true = checkerboard effect. False = vertical stripes 82 | * @param color1 The first fill colour in 0xAARRGGBB format 83 | * @param color2 The second fill colour in 0xAARRGGBB format 84 | * 85 | * @return The modified source FlxSprite 86 | */ 87 | public static function overlay(source:FlxSprite, cellWidth:int, cellHeight:int, width:int = -1, height:int = -1, addLegend:Boolean = false, alternate:Boolean = true, color1:uint = 0x88e7e6e6, color2:uint = 0x88d9d5d5):FlxSprite 88 | { 89 | if (width == -1) 90 | { 91 | width = FlxG.width; 92 | } 93 | 94 | if (height == -1) 95 | { 96 | height = FlxG.height; 97 | } 98 | 99 | if (width < cellWidth || height < cellHeight) 100 | { 101 | return null; 102 | } 103 | 104 | var grid:BitmapData = createGrid(cellWidth, cellHeight, width, height, alternate, color1, color2); 105 | 106 | var pixels:BitmapData = source.pixels; 107 | 108 | pixels.copyPixels(grid, new Rectangle(0, 0, width, height), new Point(0, 0), null, null, true); 109 | 110 | source.pixels = pixels; 111 | 112 | return source; 113 | } 114 | 115 | public static function addLegend(source:FlxSprite, cellWidth:int, cellHeight:int, xAxis:Boolean = true, yAxis:Boolean = true):FlxSprite 116 | { 117 | if (cellWidth > source.width) 118 | { 119 | throw Error("cellWidth larger than FlxSprites width"); 120 | return source; 121 | } 122 | 123 | if (cellHeight > source.height) 124 | { 125 | throw Error("cellHeight larger than FlxSprites height"); 126 | return source; 127 | } 128 | 129 | if (source.width < cellWidth || source.height < cellHeight) 130 | { 131 | throw Error("source FlxSprite width or height smaller than requested cell width or height"); 132 | return source; 133 | } 134 | 135 | // Valid cell width/height and source to work on 136 | 137 | return source; 138 | 139 | } 140 | 141 | public static function createGrid(cellWidth:int, cellHeight:int, width:int, height:int, alternate:Boolean, color1:uint, color2:uint):BitmapData 142 | { 143 | // How many cells can we fit into the width/height? (round it UP if not even, then trim back) 144 | 145 | var rowColor:uint = color1; 146 | var lastColor:uint = color1; 147 | var grid:BitmapData = new BitmapData(width, height, true); 148 | 149 | // If there aren't an even number of cells in a row then we need to swap the lastColor value 150 | 151 | for (var y:int = 0; y <= height; y += cellHeight) 152 | { 153 | if (y > 0 && lastColor == rowColor && alternate) 154 | { 155 | (lastColor == color1) ? lastColor = color2 : lastColor = color1; 156 | } 157 | else if (y > 0 && lastColor != rowColor && alternate == false) 158 | { 159 | (lastColor == color2) ? lastColor = color1 : lastColor = color2; 160 | } 161 | 162 | for (var x:int = 0; x <= width; x += cellWidth) 163 | { 164 | if (x == 0) 165 | { 166 | rowColor = lastColor; 167 | } 168 | 169 | grid.fillRect(new Rectangle(x, y, cellWidth, cellHeight), lastColor); 170 | 171 | if (lastColor == color1) 172 | { 173 | lastColor = color2; 174 | } 175 | else 176 | { 177 | lastColor = color1; 178 | } 179 | } 180 | } 181 | 182 | return grid; 183 | } 184 | 185 | 186 | } 187 | 188 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FlxLinkedGroup.as: -------------------------------------------------------------------------------- 1 | package org.flixel.plugin.photonstorm 2 | { 3 | import org.flixel.FlxGroup; 4 | import org.flixel.FlxSprite; 5 | import flash.utils.getTimer; 6 | 7 | public class FlxLinkedGroup extends FlxGroup 8 | { 9 | //private var queue 10 | 11 | 12 | public function FlxLinkedGroup(MaxSize:uint = 0) 13 | { 14 | super(MaxSize); 15 | } 16 | 17 | public function addX(newX:int):void 18 | { 19 | for each (var s:FlxSprite in members) 20 | { 21 | s.x += newX; 22 | } 23 | } 24 | 25 | public function angle(newX:int):void 26 | { 27 | for each (var s:FlxSprite in members) 28 | { 29 | s.angle += newX; 30 | } 31 | } 32 | 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FlxMouseControl.as: -------------------------------------------------------------------------------- 1 | /** 2 | * FlxMouseControl 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.2 Added Mouse Zone, Mouse Speed and refactored addToStack process 6 | * v1.1 Moved to a native plugin 7 | * v1.0 First release 8 | * 9 | * @version 1.2 - July 28th 2011 10 | * @link http://www.photonstorm.com 11 | * @author Richard Davey / Photon Storm 12 | */ 13 | 14 | package org.flixel.plugin.photonstorm 15 | { 16 | import org.flixel.*; 17 | 18 | public class FlxMouseControl extends FlxBasic 19 | { 20 | /** 21 | * Use with sort() to sort in ascending order. 22 | */ 23 | public static const ASCENDING:int = -1; 24 | 25 | /** 26 | * Use with sort() to sort in descending order. 27 | */ 28 | public static const DESCENDING:int = 1; 29 | 30 | /** 31 | * The value that the FlxExtendedSprites are sorted by before deciding which is "on-top" for click select 32 | */ 33 | public static var sortIndex:String = "y"; 34 | 35 | /** 36 | * The sorting order. If the sortIndex is "y" and the order is ASCENDING then a sprite with a Y value of 200 would be "on-top" of one with a Y value of 100. 37 | */ 38 | public static var sortOrder:int = ASCENDING; 39 | 40 | /** 41 | * Is the mouse currently dragging a sprite? If you have just clicked but NOT yet moved the mouse then this might return false. 42 | */ 43 | public static var isDragging:Boolean = false; 44 | 45 | /** 46 | * The FlxExtendedSprite that is currently being dragged, if any. 47 | */ 48 | public static var dragTarget:FlxExtendedSprite; 49 | 50 | /** 51 | * The FlxExtendedSprite that currently has the mouse button pressed on it 52 | */ 53 | public static var clickTarget:FlxExtendedSprite; 54 | private static var clickStack:Array = new Array; 55 | private static var clickCoords:FlxPoint; 56 | private static var hasClickTarget:Boolean = false; 57 | 58 | private static var oldX:int; 59 | private static var oldY:int; 60 | 61 | /** 62 | * The speed the mouse is moving on the X axis in pixels per frame 63 | */ 64 | public static var speedX:int; 65 | 66 | /** 67 | * The speed the mouse is moving on the Y axis in pixels per frame 68 | */ 69 | public static var speedY:int; 70 | 71 | /** 72 | * The mouse can be set to only be active within a specific FlxRect region of the game world. 73 | * If outside this FlxRect no clicks, drags or throws will be processed. 74 | * If the mouse leaves this region while still dragging then the sprite is automatically dropped and its release handler is called. 75 | * Set the FlxRect to null to disable the zone. 76 | */ 77 | public static var mouseZone:FlxRect; 78 | 79 | /** 80 | * Instead of using a mouseZone (which is calculated in world coordinates) you can limit the mouse to the FlxG.camera.deadzone area instead. 81 | * If set to true the mouse will use the camera deadzone. If false (or the deadzone is null) no check will take place. 82 | * Note that this takes priority over the mouseZone above. If the mouseZone and deadzone are set, the deadzone is used. 83 | */ 84 | public static var linkToDeadZone:Boolean = false; 85 | 86 | public function FlxMouseControl() 87 | { 88 | } 89 | 90 | /** 91 | * Adds the given FlxExtendedSprite to the stack of potential sprites that were clicked, the stack is then sorted and the final sprite is selected from that 92 | * 93 | * @param item The FlxExtendedSprite that was clicked by the mouse 94 | */ 95 | public static function addToStack(item:FlxExtendedSprite):void 96 | { 97 | if (mouseZone is FlxRect) 98 | { 99 | if (FlxMath.pointInFlxRect(FlxG.mouse.x, FlxG.mouse.y, mouseZone) == true) 100 | { 101 | clickStack.push(item); 102 | } 103 | } 104 | else 105 | { 106 | clickStack.push(item); 107 | } 108 | } 109 | 110 | /** 111 | * Main Update Loop - checks mouse status and updates FlxExtendedSprites accordingly 112 | */ 113 | override public function update():void 114 | { 115 | // Update mouse speed 116 | speedX = FlxG.mouse.screenX - oldX; 117 | speedY = FlxG.mouse.screenY - oldY; 118 | 119 | oldX = FlxG.mouse.screenX; 120 | oldY = FlxG.mouse.screenY; 121 | 122 | // Is the mouse currently pressed down on a target? 123 | if (hasClickTarget) 124 | { 125 | if (FlxG.mouse.pressed()) 126 | { 127 | // Has the mouse moved? If so then we're candidate for a drag 128 | if (isDragging == false && clickTarget.draggable && (clickCoords.x != FlxG.mouse.x || clickCoords.y != FlxG.mouse.y)) 129 | { 130 | // Drag on 131 | isDragging = true; 132 | 133 | dragTarget = clickTarget; 134 | 135 | dragTarget.startDrag(); 136 | } 137 | } 138 | else 139 | { 140 | releaseMouse(); 141 | } 142 | 143 | if (linkToDeadZone) 144 | { 145 | if (FlxMath.mouseInFlxRect(false, FlxG.camera.deadzone) == false) 146 | { 147 | releaseMouse(); 148 | } 149 | } 150 | else if (FlxMath.mouseInFlxRect(true, mouseZone) == false) 151 | { 152 | // Is a mouse zone enabled? In which case check if we're still in it 153 | releaseMouse(); 154 | } 155 | } 156 | else 157 | { 158 | // No target, but is the mouse down? 159 | 160 | if (FlxG.mouse.justPressed()) 161 | { 162 | clickStack.length = 0; 163 | } 164 | 165 | // If you are wondering how the brand new array can have anything in it by now, it's because FlxExtendedSprite 166 | // adds itself to the clickStack 167 | 168 | if (FlxG.mouse.pressed() && clickStack.length > 0) 169 | { 170 | assignClickedSprite(); 171 | } 172 | } 173 | } 174 | 175 | /** 176 | * Internal function used to release the click / drag targets and reset the mouse state 177 | */ 178 | private function releaseMouse():void 179 | { 180 | // Mouse is no longer down, so tell the click target it's free - this will also stop dragging if happening 181 | clickTarget.mouseReleasedHandler(); 182 | 183 | hasClickTarget = false; 184 | clickTarget = null; 185 | 186 | isDragging = false; 187 | dragTarget = null; 188 | } 189 | 190 | /** 191 | * Once the clickStack is created this sorts it and then picks the sprite with the highest priority (based on sortIndex and sortOrder) 192 | */ 193 | private function assignClickedSprite():void 194 | { 195 | // If there is more than one potential target then sort them 196 | if (clickStack.length > 1) 197 | { 198 | clickStack.sort(sortHandler); 199 | } 200 | 201 | clickTarget = clickStack.pop(); 202 | 203 | clickCoords = clickTarget.point; 204 | 205 | hasClickTarget = true; 206 | 207 | clickTarget.mousePressedHandler(); 208 | 209 | clickStack.length = 0; 210 | } 211 | 212 | /** 213 | * Helper function for the sort process. 214 | * 215 | * @param item1 The first object being sorted. 216 | * @param item2 The second object being sorted. 217 | * 218 | * @return An integer value: -1 (item1 before item2), 0 (same), or 1 (item1 after item2) 219 | */ 220 | private function sortHandler(item1:FlxExtendedSprite, item2:FlxExtendedSprite):int 221 | { 222 | if (item1[sortIndex] < item2[sortIndex]) 223 | { 224 | return sortOrder; 225 | } 226 | else if (item1[sortIndex] > item2[sortIndex]) 227 | { 228 | return -sortOrder; 229 | } 230 | 231 | return 0; 232 | } 233 | 234 | /** 235 | * Removes all references to any click / drag targets and resets this class 236 | */ 237 | public static function clear():void 238 | { 239 | hasClickTarget = false; 240 | 241 | if (clickTarget) 242 | { 243 | clickTarget.mouseReleasedHandler(); 244 | } 245 | 246 | clickTarget = null; 247 | 248 | isDragging = false; 249 | 250 | if (dragTarget) 251 | { 252 | dragTarget.stopDrag(); 253 | } 254 | 255 | speedX = 0; 256 | speedY = 0; 257 | dragTarget = null; 258 | mouseZone = null; 259 | linkToDeadZone = false; 260 | } 261 | 262 | /** 263 | * Runs when this plugin is destroyed 264 | */ 265 | override public function destroy():void 266 | { 267 | clear(); 268 | } 269 | 270 | } 271 | 272 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FlxPowerTools.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Flixel Power Tools 3 | * 4 | * Version information and constants the other classes in this package can reference 5 | * 6 | * @version 1.9 7 | * @link http://www.photonstorm.com 8 | * @author Richard Davey / Photon Storm 9 | */ 10 | 11 | package org.flixel.plugin.photonstorm 12 | { 13 | public class FlxPowerTools 14 | { 15 | public static const LIBRARY_NAME:String = "flixel power tools"; 16 | public static const LIBRARY_MAJOR_VERSION:int = 1; 17 | public static const LIBRARY_MINOR_VERSION:int = 9; 18 | 19 | public function FlxPowerTools() 20 | { 21 | } 22 | 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FlxScreenGrab.as: -------------------------------------------------------------------------------- 1 | /** 2 | * FlxScreenGrab 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.0 Updated for the Flixel 2.5 Plugin system 6 | * 7 | * @version 1.0 - April 28th 2011 8 | * @link http://www.photonstorm.com 9 | * @author Richard Davey / Photon Storm 10 | */ 11 | 12 | package org.flixel.plugin.photonstorm 13 | { 14 | import org.flixel.*; 15 | import flash.geom.Rectangle; 16 | import flash.display.Bitmap; 17 | import flash.display.BitmapData; 18 | import flash.geom.Matrix; 19 | import flash.net.FileReference; 20 | import flash.utils.ByteArray; 21 | import flash.utils.getTimer; 22 | 23 | /** 24 | * Captures a screen grab of the game and stores it locally, optionally saving as a PNG. 25 | */ 26 | public class FlxScreenGrab extends FlxBasic 27 | { 28 | public static var screenshot:Bitmap; 29 | private static var hotkey:String = ""; 30 | private static var autoSave:Boolean = false; 31 | private static var autoHideMouse:Boolean = false; 32 | private static var region:Rectangle; 33 | 34 | public function FlxScreenGrab() 35 | { 36 | } 37 | 38 | /** 39 | * Defines the region of the screen that should be captured. If you need it to be a fixed location then use this.
40 | * If you want to grab the whole SWF size, you don't need to set this as that is the default.
41 | * Remember that if your game is running in a zoom mode > 1 you need to account for this here. 42 | * 43 | * @param x The x coordinate (in Flash display space, not Flixel game world) 44 | * @param y The y coordinate (in Flash display space, not Flixel game world) 45 | * @param width The width of the grab region 46 | * @param height The height of the grab region 47 | */ 48 | public static function defineCaptureRegion(x:int, y:int, width:int, height:int):void 49 | { 50 | region = new Rectangle(x, y, width, height); 51 | } 52 | 53 | /** 54 | * Clears a previously defined capture region 55 | */ 56 | public static function clearCaptureRegion():void 57 | { 58 | region = null; 59 | } 60 | 61 | /** 62 | * Specify which key will capture a screen shot. Use the String value of the key in the same way FlxG.keys does (so "F1" for example)
63 | * Optionally save the image to a file immediately. This uses the file systems "Save as" dialog window and pauses your game during the process.
64 | * 65 | * @param key String The key you press to capture the screen (i.e. "F1", "SPACE", etc - see system.input.Keyboard.as source for reference) 66 | * @param saveToFile Boolean If set to true it will immediately encodes the grab to a PNG and open a "Save As" dialog window when the hotkey is pressed 67 | * @param hideMouse Boolean If set to true the mouse will be hidden before capture and displayed afterwards when the hotkey is pressed 68 | */ 69 | public static function defineHotKey(key:String, saveToFile:Boolean = false, hideMouse:Boolean = false):void 70 | { 71 | hotkey = key; 72 | autoSave = saveToFile; 73 | autoHideMouse = hideMouse; 74 | } 75 | 76 | /** 77 | * Clears a previously defined hotkey 78 | */ 79 | public static function clearHotKey():void 80 | { 81 | hotkey = ""; 82 | autoSave = false; 83 | autoHideMouse = false; 84 | } 85 | 86 | /** 87 | * Takes a screen grab immediately of the given region or a previously defined region 88 | * 89 | * @param captureRegion A Rectangle area to capture. This over-rides that set by "defineCaptureRegion". If neither are set the full SWF size is used. 90 | * @param saveToFile Boolean If set to true it will immediately encode the grab to a PNG and open a "Save As" dialog window 91 | * @param hideMouse Boolean If set to true the mouse will be hidden before capture and displayed again afterwards 92 | * @return Bitmap The screen grab as a Flash Bitmap image 93 | */ 94 | public static function grab(captureRegion:Rectangle = null, saveToFile:Boolean = false, hideMouse:Boolean = false):Bitmap 95 | { 96 | var bounds:Rectangle; 97 | 98 | if (captureRegion) 99 | { 100 | bounds = new Rectangle(captureRegion.x, captureRegion.y, captureRegion.width, captureRegion.height); 101 | } 102 | else if (region) 103 | { 104 | bounds = new Rectangle(region.x, region.y, region.width, region.height); 105 | } 106 | else 107 | { 108 | bounds = new Rectangle(0, 0, FlxG.stage.stageWidth, FlxG.stage.stageHeight); 109 | } 110 | 111 | var theBitmap:Bitmap = new Bitmap(new BitmapData(bounds.width, bounds.height, true, 0x0)); 112 | 113 | var m:Matrix = new Matrix(1, 0, 0, 1, -bounds.x, -bounds.y); 114 | 115 | if (autoHideMouse || hideMouse) 116 | { 117 | FlxG.mouse.hide(); 118 | } 119 | 120 | theBitmap.bitmapData.draw(FlxG.stage, m); 121 | 122 | if (autoHideMouse || hideMouse) 123 | { 124 | FlxG.mouse.show(); 125 | } 126 | 127 | screenshot = theBitmap; 128 | 129 | if (saveToFile || autoSave) 130 | { 131 | save(); 132 | } 133 | 134 | return theBitmap; 135 | } 136 | 137 | private static function save(filename:String = ""):void 138 | { 139 | if (screenshot.bitmapData == null) 140 | { 141 | return; 142 | } 143 | 144 | var png:ByteArray = PNGEncoder.encode(screenshot.bitmapData); 145 | 146 | var file:FileReference = new FileReference(); 147 | 148 | if (filename == "") 149 | { 150 | filename = "grab" + getTimer().toString() + ".png"; 151 | } 152 | else if (filename.substr( -4) != ".png") 153 | { 154 | filename = filename.concat(".png"); 155 | } 156 | 157 | file.save(png, filename); 158 | } 159 | 160 | override public function update():void 161 | { 162 | if (hotkey != "") 163 | { 164 | if (FlxG.keys.justReleased(hotkey)) 165 | { 166 | trace("key pressed"); 167 | grab(); 168 | } 169 | } 170 | } 171 | 172 | override public function destroy():void 173 | { 174 | clearCaptureRegion(); 175 | clearHotKey(); 176 | } 177 | 178 | } 179 | 180 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FlxScrollZone.as: -------------------------------------------------------------------------------- 1 | /** 2 | * FlxScrollZone 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.4 Added "clearRegion" support for when you use Sprites with transparency and renamed parameter to onlyScrollOnscreen 6 | * v1.3 Swapped plugin update for draw, now smoother / faster in some fps cases 7 | * v1.2 Updated for the Flixel 2.5 Plugin system 8 | * 9 | * @version 1.4 - May 16th 2011 10 | * @link http://www.photonstorm.com 11 | * @author Richard Davey / Photon Storm. My thanks to Ralph Hauwert for help with this. 12 | */ 13 | 14 | package org.flixel.plugin.photonstorm 15 | { 16 | import flash.display.BitmapData; 17 | import flash.display.Sprite; 18 | import flash.geom.Matrix; 19 | import flash.geom.Point; 20 | import flash.geom.Rectangle; 21 | import flash.utils.Dictionary; 22 | import org.flixel.*; 23 | 24 | /** 25 | * FlxScrollZone allows you to scroll the content of an FlxSprites bitmapData in any direction you like. 26 | */ 27 | public class FlxScrollZone extends FlxBasic 28 | { 29 | private static var members:Dictionary = new Dictionary(true); 30 | private static var zeroPoint:Point = new Point; 31 | 32 | public function FlxScrollZone() 33 | { 34 | } 35 | 36 | /** 37 | * Add an FlxSprite to the Scroll Manager, setting up one scrolling region.
38 | * To add extra scrolling regions on the same sprite use addZone() 39 | * 40 | * @param source The FlxSprite to apply the scroll to 41 | * @param region The region, specified as a Rectangle, of the FlxSprite that you wish to scroll 42 | * @param distanceX The distance in pixels you want to scroll on the X axis. Negative values scroll left. Positive scroll right. Floats allowed (0.5 would scroll at half speed) 43 | * @param distanceY The distance in pixels you want to scroll on the Y axis. Negative values scroll up. Positive scroll down. Floats allowed (0.5 would scroll at half speed) 44 | * @param onlyScrollOnscreen Only update this FlxSprite if visible onScreen (default true) Saves performance by not scrolling offscreen sprites, but this isn't always desirable 45 | * @param clearRegion Set to true if you want to clear the scrolling area of the FlxSprite with a 100% transparent fill before applying the scroll texture (default false) 46 | * @see createZone 47 | */ 48 | public static function add(source:FlxSprite, region:Rectangle, distanceX:Number, distanceY:Number, onlyScrollOnscreen:Boolean = true, clearRegion:Boolean = false):void 49 | { 50 | if (members[source]) 51 | { 52 | throw Error("FlxSprite already exists in FlxScrollZone, use addZone to add a new scrolling region to an already added FlxSprite"); 53 | } 54 | 55 | var data:Object = new Object(); 56 | 57 | data.source = source; 58 | data.scrolling = true; 59 | data.onlyScrollOnscreen = onlyScrollOnscreen; 60 | data.zones = new Array; 61 | 62 | members[source] = data; 63 | 64 | createZone(source, region, distanceX, distanceY, clearRegion); 65 | } 66 | 67 | /** 68 | * Creates a new scrolling region to an FlxSprite already in the Scroll Manager (see add())
69 | * 70 | * @param source The FlxSprite to apply the scroll to 71 | * @param region The region, specified as a Rectangle, of the FlxSprite that you wish to scroll 72 | * @param distanceX The distance in pixels you want to scroll on the X axis. Negative values scroll left. Positive scroll right. Floats allowed (0.5 would scroll at half speed) 73 | * @param distanceY The distance in pixels you want to scroll on the Y axis. Negative values scroll up. Positive scroll down. Floats allowed (0.5 would scroll at half speed) 74 | * @param clearRegion Set to true if you want to fill the scroll region of the FlxSprite with a 100% transparent fill before scrolling it (default false) 75 | */ 76 | public static function createZone(source:FlxSprite, region:Rectangle, distanceX:Number, distanceY:Number, clearRegion:Boolean = false):void 77 | { 78 | var texture:BitmapData = new BitmapData(region.width, region.height, true, 0x00000000); 79 | texture.copyPixels(source.framePixels, region, zeroPoint, null, null, true); 80 | 81 | var data:Object = new Object(); 82 | 83 | data.buffer = new Sprite; 84 | data.texture = texture; 85 | data.region = region; 86 | data.clearRegion = clearRegion; 87 | data.distanceX = distanceX; 88 | data.distanceY = distanceY; 89 | data.scrollMatrix = new Matrix(); 90 | data.drawMatrix = new Matrix(1, 0, 0, 1, region.x, region.y); 91 | 92 | members[source].zones.push(data); 93 | } 94 | 95 | /** 96 | * Sets the draw Matrix for the given FlxSprite scroll zone
97 | * Warning: Modify this at your own risk! 98 | * 99 | * @param source The FlxSprite to set the draw matrix on 100 | * @param matrix The Matrix to use during the scroll update draw 101 | * @param zone If the FlxSprite has more than 1 scrolling zone, use this to target which zone to apply the update to (default 0) 102 | * @return Matrix The draw matrix used in the scroll update 103 | */ 104 | public static function updateDrawMatrix(source:FlxSprite, matrix:Matrix, zone:int = 0):void 105 | { 106 | members[source].zones[zone].drawMatrix = matrix; 107 | } 108 | 109 | /** 110 | * Returns the draw Matrix for the given FlxSprite scroll zone 111 | * 112 | * @param source The FlxSprite to get the draw matrix from 113 | * @param zone If the FlxSprite has more than 1 scrolling zone, use this to target which zone to apply the update to (default 0) 114 | * @return Matrix The draw matrix used in the scroll update 115 | */ 116 | public static function getDrawMatrix(source:FlxSprite, zone:int = 0):Matrix 117 | { 118 | return members[source].zones[zone].drawMatrix; 119 | } 120 | 121 | /** 122 | * Removes an FlxSprite and all of its scrolling zones. Note that it doesn't restore the sprite bitmapData. 123 | * 124 | * @param source The FlxSprite to remove all scrolling zones for. 125 | * @return Boolean true if the FlxSprite was removed, otherwise false. 126 | */ 127 | public static function remove(source:FlxSprite):Boolean 128 | { 129 | if (members[source]) 130 | { 131 | delete members[source]; 132 | 133 | return true; 134 | } 135 | 136 | return false; 137 | } 138 | 139 | /** 140 | * Removes all FlxSprites, and all of their scrolling zones.
141 | * This is called automatically if the plugin is ever destroyed. 142 | */ 143 | public static function clear():void 144 | { 145 | for each (var obj:Object in members) 146 | { 147 | delete members[obj.source]; 148 | } 149 | } 150 | 151 | /** 152 | * Update the distance in pixels to scroll on the X axis. 153 | * 154 | * @param source The FlxSprite to apply the scroll to 155 | * @param distanceX The distance in pixels you want to scroll on the X axis. Negative values scroll left. Positive scroll right. Floats allowed (0.5 would scroll at half speed) 156 | * @param zone If the FlxSprite has more than 1 scrolling zone, use this to target which zone to apply the update to (default 0) 157 | */ 158 | public static function updateX(source:FlxSprite, distanceX:Number, zone:int = 0):void 159 | { 160 | members[source].zones[zone].distanceX = distanceX; 161 | } 162 | 163 | /** 164 | * Update the distance in pixels to scroll on the X axis. 165 | * 166 | * @param source The FlxSprite to apply the scroll to 167 | * @param distanceY The distance in pixels you want to scroll on the Y axis. Negative values scroll up. Positive scroll down. Floats allowed (0.5 would scroll at half speed) 168 | * @param zone If the FlxSprite has more than 1 scrolling zone, use this to target which zone to apply the update to (default 0) 169 | */ 170 | public static function updateY(source:FlxSprite, distanceY:Number, zone:int = 0):void 171 | { 172 | members[source].zones[zone].distanceY = distanceY; 173 | } 174 | 175 | /** 176 | * Starts scrolling on the given FlxSprite. If no FlxSprite is given it starts scrolling on all FlxSprites currently added.
177 | * Scrolling is enabled by default, but this can be used to re-start it if you have stopped it via stopScrolling.
178 | * 179 | * @param source The FlxSprite to start scrolling on. If left as null it will start scrolling on all sprites. 180 | */ 181 | public static function startScrolling(source:FlxSprite = null):void 182 | { 183 | if (source) 184 | { 185 | members[source].scrolling = true; 186 | } 187 | else 188 | { 189 | for each (var obj:Object in members) 190 | { 191 | obj.scrolling = true; 192 | } 193 | } 194 | } 195 | 196 | /** 197 | * Stops scrolling on the given FlxSprite. If no FlxSprite is given it stops scrolling on all FlxSprites currently added.
198 | * Scrolling is enabled by default, but this can be used to stop it.
199 | * 200 | * @param source The FlxSprite to stop scrolling on. If left as null it will stop scrolling on all sprites. 201 | */ 202 | public static function stopScrolling(source:FlxSprite = null):void 203 | { 204 | if (source) 205 | { 206 | members[source].scrolling = false; 207 | } 208 | else 209 | { 210 | for each (var obj:Object in members) 211 | { 212 | obj.scrolling = false; 213 | } 214 | } 215 | } 216 | 217 | override public function draw():void 218 | { 219 | for each (var obj:Object in members) 220 | { 221 | if ((obj.onlyScrollOnscreen == true && obj.source.onScreen()) && obj.scrolling == true && obj.source.exists) 222 | { 223 | scroll(obj); 224 | } 225 | } 226 | } 227 | 228 | private function scroll(data:Object):void 229 | { 230 | // Loop through the scroll zones defined in this object 231 | for each (var zone:Object in data.zones) 232 | { 233 | zone.scrollMatrix.tx += zone.distanceX; 234 | zone.scrollMatrix.ty += zone.distanceY; 235 | 236 | zone.buffer.graphics.clear(); 237 | zone.buffer.graphics.beginBitmapFill(zone.texture, zone.scrollMatrix, true, false); 238 | zone.buffer.graphics.drawRect(0, 0, zone.region.width, zone.region.height); 239 | zone.buffer.graphics.endFill(); 240 | 241 | if (zone.clearRegion) 242 | { 243 | data.source.pixels.fillRect(zone.region, 0x0); 244 | } 245 | 246 | data.source.pixels.draw(zone.buffer, zone.drawMatrix); 247 | } 248 | 249 | data.source.dirty = true; 250 | } 251 | 252 | override public function destroy():void 253 | { 254 | clear(); 255 | } 256 | 257 | } 258 | 259 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FlxScrollingText.as: -------------------------------------------------------------------------------- 1 | /** 2 | * FlxScrollingText 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.0 First version released 6 | * 7 | * @version 1.0 - May 5th 2011 8 | * @link http://www.photonstorm.com 9 | * @author Richard Davey / Photon Storm 10 | */ 11 | 12 | package org.flixel.plugin.photonstorm 13 | { 14 | import flash.display.BitmapData; 15 | import flash.geom.Point; 16 | import flash.geom.Rectangle; 17 | import flash.utils.Dictionary; 18 | import flash.utils.getTimer; 19 | 20 | import org.flixel.*; 21 | 22 | /** 23 | * FlxScrollingText takes an FlxBitmapFont object and creates a horizontally scrolling FlxSprite from it 24 | */ 25 | public class FlxScrollingText extends FlxBasic 26 | { 27 | private static var members:Dictionary = new Dictionary(true); 28 | private static var zeroPoint:Point = new Point; 29 | 30 | public function FlxScrollingText() 31 | { 32 | } 33 | 34 | /** 35 | * Adds an FlxBitmapFont to the Scrolling Text Manager and returns an FlxSprite which contains the text scroller in it.
36 | * The FlxSprite will automatically update itself via this plugin, but can be treated as a normal FlxSprite in all other regards
37 | * re: positioning, collision, rotation, etc. 38 | * 39 | * @param bitmapFont A pre-prepared FlxBitmapFont object (see the Test Suite examples for details on how this works) 40 | * @param region A Rectangle that defines the size of the scrolling FlxSprite. The sprite will be placed at region.x/y and be region.width/height in size. 41 | * @param pixels The number of pixels to scroll per step. For a smooth (but slow) scroll use low values. Keep the value proportional to the font width, so if the font width is 16 use a value like 1, 2, 4 or 8. 42 | * @param steps How many steps should pass before the text is next scrolled? Default 0 means every step we scroll. Higher values slow things down. 43 | * @param text The default text for your scrolling message. Can be changed in real-time via the addText method. 44 | * @param onlyScrollOnscreen Only update the text scroller when this FlxSprite is visible on-screen? Default true. 45 | * @param loopOnWrap When the scroller reaches the end of the given "text" should it wrap to the start? Default true. If false it will clear the screen then set itself to not update. 46 | * 47 | * @return An FlxSprite of size region.width/height, positioned at region.x/y, that auto-updates its contents while this plugin runs 48 | */ 49 | public static function add(bitmapFont:FlxBitmapFont, region:Rectangle, pixels:uint = 1, steps:uint = 0, text:String = "FLIXEL ROCKS!", onlyScrollOnscreen:Boolean = true, loopOnWrap:Boolean = true):FlxSprite 50 | { 51 | var data:Object = new Object; 52 | 53 | // Sanity checks 54 | if (pixels > bitmapFont.characterWidth) 55 | { 56 | pixels = bitmapFont.characterWidth; 57 | } 58 | 59 | if (pixels == 0) 60 | { 61 | pixels = 1; 62 | } 63 | 64 | if (text == "") 65 | { 66 | text = " "; 67 | } 68 | 69 | data.bitmapFont = bitmapFont; 70 | data.bitmapChar = FlxBitmapFont(data.bitmapFont).getCharacterAsBitmapData(text.charAt(0)); 71 | data.charWidth = bitmapFont.characterWidth; 72 | data.charHeight = bitmapFont.characterHeight; 73 | data.shiftRect = new Rectangle(pixels, 0, region.width - pixels, region.height); 74 | data.bufferRect = new Rectangle(0, 0, region.width, region.height); 75 | data.slice = new Rectangle(0, 0, pixels, data.charHeight); 76 | data.endPoint = new Point(region.width - pixels, 0); 77 | data.x = 0; 78 | 79 | data.sprite = new FlxSprite(region.x, region.y).makeGraphic(region.width, region.height, 0x0, true); 80 | data.buffer = new BitmapData(region.width, region.height, true, 0x0); 81 | 82 | data.region = region; 83 | data.step = steps; 84 | data.maxStep = steps; 85 | data.pixels = pixels; 86 | data.clearCount = 0; 87 | data.clearDistance = region.width - pixels; 88 | 89 | data.text = text; 90 | data.currentChar = 0; 91 | data.maxChar = text.length; 92 | 93 | data.wrap = loopOnWrap; 94 | data.complete = false; 95 | data.scrolling = true; 96 | data.onScreenScroller = onlyScrollOnscreen; 97 | 98 | scroll(data); 99 | 100 | members[data.sprite] = data; 101 | 102 | return data.sprite; 103 | } 104 | 105 | /** 106 | * Adds or replaces the text in the given Text Scroller.
107 | * Can be called while the scroller is still active. 108 | * 109 | * @param source The FlxSprite Text Scroller you wish to update (must have been added to FlxScrollingText via a call to add() 110 | * @param text The text to add or update to the Scroller 111 | * @param overwrite If true the given text will fully replace the previous scroller text. If false it will be appended to the end (default) 112 | */ 113 | public static function addText(source:FlxSprite, text:String, overwrite:Boolean = false):void 114 | { 115 | if (overwrite) 116 | { 117 | members[source].text = text; 118 | } 119 | else 120 | { 121 | members[source].text = String(members[source].text).concat(text); 122 | } 123 | 124 | members[source].maxChar = members[source].text.length; 125 | } 126 | 127 | override public function draw():void 128 | { 129 | for each (var obj:Object in members) 130 | { 131 | if (obj && (obj.onScreenScroller == true && obj.sprite.onScreen()) && obj.scrolling == true && obj.sprite.exists) 132 | { 133 | scroll(obj); 134 | } 135 | } 136 | } 137 | 138 | private static function scroll(data:Object):void 139 | { 140 | // Have we reached enough steps? 141 | 142 | if (data.maxStep > 0 && (data.step < data.maxStep)) 143 | { 144 | data.step++; 145 | 146 | return; 147 | } 148 | else 149 | { 150 | // It's time to render, so reset the step counter and lets go 151 | data.step = 0; 152 | } 153 | 154 | // CLS 155 | data.buffer.fillRect(data.bufferRect, 0x0); 156 | 157 | // Shift the current contents of the buffer along by "speed" pixels 158 | data.buffer.copyPixels(data.sprite.pixels, data.shiftRect, zeroPoint, null, null, true); 159 | 160 | // Copy the side of the character 161 | if (data.complete == false) 162 | { 163 | data.buffer.copyPixels(data.bitmapChar, data.slice, data.endPoint, null, null, true); 164 | 165 | // Update 166 | data.x += data.pixels; 167 | 168 | if (data.x >= data.charWidth) 169 | { 170 | // Get the next character 171 | data.currentChar++; 172 | 173 | if (data.currentChar > data.maxChar) 174 | { 175 | // At the end of the text 176 | if (data.wrap) 177 | { 178 | data.currentChar = 0; 179 | } 180 | else 181 | { 182 | data.complete = true; 183 | data.clearCount = 0; 184 | } 185 | } 186 | 187 | if (data.complete == false) 188 | { 189 | data.bitmapChar = FlxBitmapFont(data.bitmapFont).getCharacterAsBitmapData(String(data.text).charAt(data.currentChar)); 190 | data.x = 0; 191 | } 192 | } 193 | 194 | if (data.complete == false) 195 | { 196 | data.slice.x = data.x; 197 | } 198 | } 199 | else 200 | { 201 | data.clearCount += data.pixels; 202 | 203 | // It's all over now 204 | if (data.clearCount >= data.clearDistance) 205 | { 206 | // No point updating something that has since left the screen 207 | data.scrolling = false; 208 | } 209 | } 210 | 211 | data.sprite.pixels = data.buffer.clone(); 212 | data.sprite.dirty = true; 213 | } 214 | 215 | /** 216 | * Removes all FlxSprites
217 | * This is called automatically if the plugin is destroyed, but should be called manually by you if you change States
218 | * as all the FlxSprites will be destroyed by Flixel otherwise 219 | */ 220 | public static function clear():void 221 | { 222 | for each (var obj:Object in members) 223 | { 224 | delete members[obj.sprite]; 225 | } 226 | } 227 | 228 | /** 229 | * Starts scrolling on the given FlxSprite. If no FlxSprite is given it starts scrolling on all FlxSprites currently added.
230 | * Scrolling is enabled by default, but this can be used to re-start it if you have stopped it via stopScrolling.
231 | * 232 | * @param source The FlxSprite to start scrolling on. If left as null it will start scrolling on all sprites. 233 | */ 234 | public static function startScrolling(source:FlxSprite = null):void 235 | { 236 | if (source) 237 | { 238 | members[source].scrolling = true; 239 | } 240 | else 241 | { 242 | for each (var obj:Object in members) 243 | { 244 | obj.scrolling = true; 245 | } 246 | } 247 | } 248 | 249 | /** 250 | * Stops scrolling on the given FlxSprite. If no FlxSprite is given it stops scrolling on all FlxSprites currently added.
251 | * Scrolling is enabled by default, but this can be used to stop it.
252 | * 253 | * @param source The FlxSprite to stop scrolling on. If left as null it will stop scrolling on all sprites. 254 | */ 255 | public static function stopScrolling(source:FlxSprite = null):void 256 | { 257 | if (source) 258 | { 259 | members[source].scrolling = false; 260 | } 261 | else 262 | { 263 | for each (var obj:Object in members) 264 | { 265 | obj.scrolling = false; 266 | } 267 | } 268 | } 269 | 270 | /** 271 | * Checks to see if the given FlxSprite is a Scrolling Text, and is actively scrolling or not
272 | * Note: If the text is set to only scroll when on-screen, but if off-screen when this is called, it will still return true. 273 | * 274 | * @param source The FlxSprite to check for scrolling on. 275 | * @return Boolean true is the FlxSprite was found and is scrolling, otherwise false 276 | */ 277 | public static function isScrolling(source:FlxSprite):Boolean 278 | { 279 | if (members[source]) 280 | { 281 | return members[source].scrolling; 282 | } 283 | 284 | return false; 285 | } 286 | 287 | /** 288 | * Removes an FlxSprite from the Text Scroller. Note that it doesn't restore the sprite bitmapData. 289 | * 290 | * @param source The FlxSprite to remove scrolling for. 291 | * @return Boolean true if the FlxSprite was removed, otherwise false. 292 | */ 293 | public static function remove(source:FlxSprite):Boolean 294 | { 295 | if (members[source]) 296 | { 297 | delete members[source]; 298 | 299 | return true; 300 | } 301 | 302 | return false; 303 | } 304 | 305 | override public function destroy():void 306 | { 307 | clear(); 308 | } 309 | 310 | } 311 | 312 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/FlxSpecialFX.as: -------------------------------------------------------------------------------- 1 | /** 2 | * FlxSpecialFX 3 | * -- Part of the Flixel Power Tools set 4 | * 5 | * v1.6 Added WowCopperFX 6 | * v1.5 Added RevealFX 7 | * v1.4 Added BlurFX and CenterSlideFX 8 | * v1.3 Renamed DropDown to FloodFill 9 | * v1.2 Added GlitchFX and StarfieldFX 10 | * v1.1 Added SineWaveFX 11 | * v1.0 First release of the new FlxSpecialFX system 12 | * 13 | * @version 1.6 - September 19th 2011 14 | * @link http://www.photonstorm.com 15 | * @author Richard Davey / Photon Storm 16 | */ 17 | 18 | package org.flixel.plugin.photonstorm 19 | { 20 | import flash.utils.Dictionary; 21 | import org.flixel.*; 22 | import org.flixel.plugin.photonstorm.FX.BlurFX; 23 | import org.flixel.plugin.photonstorm.FX.CenterSlideFX; 24 | import org.flixel.plugin.photonstorm.FX.FloodFillFX; 25 | import org.flixel.plugin.photonstorm.FX.GlitchFX; 26 | import org.flixel.plugin.photonstorm.FX.PlasmaFX; 27 | import org.flixel.plugin.photonstorm.FX.RainbowLineFX; 28 | import org.flixel.plugin.photonstorm.FX.RevealFX; 29 | import org.flixel.plugin.photonstorm.FX.SineWaveFX; 30 | import org.flixel.plugin.photonstorm.FX.StarfieldFX; 31 | import org.flixel.plugin.photonstorm.FX.WowCopperFX; 32 | 33 | /** 34 | * FlxSpecialFX is a single point of access to all of the FX Plugins available in the Flixel Power Tools 35 | */ 36 | public class FlxSpecialFX extends FlxBasic 37 | { 38 | private static var members:Dictionary = new Dictionary(true); 39 | 40 | public function FlxSpecialFX() 41 | { 42 | } 43 | 44 | // THE SPECIAL FX PLUGINS AVAILABLE 45 | 46 | /** 47 | * Creates a Plama field Effect 48 | * 49 | * @return PlasmaFX 50 | */ 51 | public static function plasma():PlasmaFX 52 | { 53 | var temp:PlasmaFX = new PlasmaFX; 54 | 55 | members[temp] = temp; 56 | 57 | return members[temp]; 58 | } 59 | 60 | /** 61 | * Creates a Rainbow Line Effect 62 | * 63 | * @return RainbowLineFX 64 | */ 65 | public static function rainbowLine():RainbowLineFX 66 | { 67 | var temp:RainbowLineFX = new RainbowLineFX; 68 | 69 | members[temp] = temp; 70 | 71 | return members[temp]; 72 | } 73 | 74 | /** 75 | * Creates a Flood Fill Effect 76 | * 77 | * @return FloodFillFX 78 | */ 79 | public static function floodFill():FloodFillFX 80 | { 81 | var temp:FloodFillFX = new FloodFillFX; 82 | 83 | members[temp] = temp; 84 | 85 | return members[temp]; 86 | } 87 | 88 | /** 89 | * Creates a Sine Wave Down Effect 90 | * 91 | * @return SineWaveFX 92 | */ 93 | public static function sineWave():SineWaveFX 94 | { 95 | var temp:SineWaveFX = new SineWaveFX; 96 | 97 | members[temp] = temp; 98 | 99 | return members[temp]; 100 | } 101 | 102 | /** 103 | * Creates a Glitch Effect 104 | * 105 | * @return GlitchFX 106 | */ 107 | public static function glitch():GlitchFX 108 | { 109 | var temp:GlitchFX = new GlitchFX; 110 | 111 | members[temp] = temp; 112 | 113 | return members[temp]; 114 | } 115 | 116 | /** 117 | * Creates a 2D or 3D Starfield Effect 118 | * 119 | * @return StarfieldFX 120 | */ 121 | public static function starfield():StarfieldFX 122 | { 123 | var temp:StarfieldFX = new StarfieldFX; 124 | 125 | members[temp] = temp; 126 | 127 | return members[temp]; 128 | } 129 | 130 | /** 131 | * Creates a Blur Effect 132 | * 133 | * @return BlurFX 134 | */ 135 | public static function blur():BlurFX 136 | { 137 | var temp:BlurFX = new BlurFX; 138 | 139 | members[temp] = temp; 140 | 141 | return members[temp]; 142 | } 143 | 144 | /** 145 | * Creates a Center Slide Effect 146 | * 147 | * @return CenterSlideFX 148 | */ 149 | public static function centerSlide():CenterSlideFX 150 | { 151 | var temp:CenterSlideFX = new CenterSlideFX 152 | 153 | members[temp] = temp; 154 | 155 | return members[temp]; 156 | } 157 | 158 | /** 159 | * Creates a Reveal Effect 160 | * 161 | * @return RevealFX 162 | */ 163 | public static function reveal():RevealFX 164 | { 165 | var temp:RevealFX = new RevealFX 166 | 167 | members[temp] = temp; 168 | 169 | return members[temp]; 170 | } 171 | 172 | /** 173 | * Creates a WOW Copper Effect 174 | * 175 | * @return WowCopperFX 176 | */ 177 | public static function wowCopper():WowCopperFX 178 | { 179 | var temp:WowCopperFX = new WowCopperFX 180 | 181 | members[temp] = temp; 182 | 183 | return members[temp]; 184 | } 185 | 186 | 187 | 188 | 189 | 190 | // GLOBAL FUNCTIONS 191 | 192 | /** 193 | * Starts the given FX Plugin running 194 | * 195 | * @param source A reference to the FX Plugin you wish to run. If null it will start all currently added FX Plugins 196 | */ 197 | public static function startFX(source:Class = null):void 198 | { 199 | if (source) 200 | { 201 | members[source].active = true; 202 | } 203 | else 204 | { 205 | for each (var obj:Object in members) 206 | { 207 | obj.active = true; 208 | } 209 | } 210 | } 211 | 212 | /** 213 | * Stops the given FX Plugin running 214 | * 215 | * @param source A reference to the FX Plugin you wish to stop. If null it will stop all currently added FX Plugins 216 | */ 217 | public static function stopFX(source:Class = null):void 218 | { 219 | if (source) 220 | { 221 | members[source].active = false; 222 | } 223 | else 224 | { 225 | for each (var obj:Object in members) 226 | { 227 | obj.active = false; 228 | } 229 | } 230 | } 231 | 232 | /** 233 | * Returns the active state of the given FX Plugin running 234 | * 235 | * @param source A reference to the FX Plugin you wish to run. If null it will start all currently added FX Plugins 236 | * @return Boolean true if the FX Plugin is active, false if not 237 | */ 238 | public static function isActive(source:Class):Boolean 239 | { 240 | if (members[source]) 241 | { 242 | return members[source].active; 243 | } 244 | 245 | return false; 246 | } 247 | 248 | /** 249 | * Called automatically by Flixels Plugin handler 250 | */ 251 | override public function draw():void 252 | { 253 | if (FlxG.paused) 254 | { 255 | return; 256 | } 257 | 258 | for each (var obj:Object in members) 259 | { 260 | if (obj.active) 261 | { 262 | obj.draw(); 263 | } 264 | } 265 | } 266 | 267 | /** 268 | * Removes a FX Plugin from the Special FX Handler 269 | * 270 | * @param source The FX Plugin to remove 271 | * @return Boolean true if the plugin was removed, otherwise false. 272 | */ 273 | public static function remove(source:Object):Boolean 274 | { 275 | if (members[source]) 276 | { 277 | members[source].destroy(); 278 | 279 | delete members[source]; 280 | 281 | return true; 282 | } 283 | 284 | return false; 285 | } 286 | 287 | /** 288 | * Removes all FX Plugins
289 | * This is called automatically if the plugin is destroyed, but should be called manually by you if you change States 290 | */ 291 | public static function clear():void 292 | { 293 | for each (var obj:Object in members) 294 | { 295 | remove(obj); 296 | } 297 | } 298 | 299 | /** 300 | * Destroys all FX Plugins currently added and then destroys this instance of the FlxSpecialFX Plugin 301 | */ 302 | override public function destroy():void 303 | { 304 | clear(); 305 | } 306 | 307 | 308 | } 309 | 310 | } -------------------------------------------------------------------------------- /src/org/flixel/plugin/photonstorm/PNGEncoder.as: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008, Adobe Systems Incorporated 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of Adobe Systems Incorporated nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 21 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.flixel.plugin.photonstorm 33 | { 34 | import flash.geom.*; 35 | import flash.display.Bitmap; 36 | import flash.display.BitmapData; 37 | import flash.utils.ByteArray; 38 | 39 | /** 40 | * Class that converts BitmapData into a valid PNG 41 | */ 42 | public class PNGEncoder 43 | { 44 | /** 45 | * Created a PNG image from the specified BitmapData 46 | * 47 | * @param image The BitmapData that will be converted into the PNG format. 48 | * @return a ByteArray representing the PNG encoded image data. 49 | * @langversion ActionScript 3.0 50 | * @playerversion Flash 9.0 51 | * @tiptext 52 | */ 53 | public static function encode(img:BitmapData):ByteArray { 54 | // Create output byte array 55 | var png:ByteArray = new ByteArray(); 56 | // Write PNG signature 57 | png.writeUnsignedInt(0x89504e47); 58 | png.writeUnsignedInt(0x0D0A1A0A); 59 | // Build IHDR chunk 60 | var IHDR:ByteArray = new ByteArray(); 61 | IHDR.writeInt(img.width); 62 | IHDR.writeInt(img.height); 63 | IHDR.writeUnsignedInt(0x08060000); // 32bit RGBA 64 | IHDR.writeByte(0); 65 | writeChunk(png,0x49484452,IHDR); 66 | // Build IDAT chunk 67 | var IDAT:ByteArray= new ByteArray(); 68 | for(var i:int=0;i < img.height;i++) { 69 | // no filter 70 | IDAT.writeByte(0); 71 | var p:uint; 72 | var j:int; 73 | if ( !img.transparent ) { 74 | for(j=0;j < img.width;j++) { 75 | p = img.getPixel(j,i); 76 | IDAT.writeUnsignedInt( 77 | uint(((p&0xFFFFFF) << 8)|0xFF)); 78 | } 79 | } else { 80 | for(j=0;j < img.width;j++) { 81 | p = img.getPixel32(j,i); 82 | IDAT.writeUnsignedInt( 83 | uint(((p&0xFFFFFF) << 8)| 84 | (p>>>24))); 85 | } 86 | } 87 | } 88 | IDAT.compress(); 89 | writeChunk(png,0x49444154,IDAT); 90 | // Build IEND chunk 91 | writeChunk(png,0x49454E44,null); 92 | // return PNG 93 | return png; 94 | } 95 | 96 | private static var crcTable:Array; 97 | private static var crcTableComputed:Boolean = false; 98 | 99 | private static function writeChunk(png:ByteArray, 100 | type:uint, data:ByteArray):void { 101 | if (!crcTableComputed) { 102 | crcTableComputed = true; 103 | crcTable = []; 104 | var c:uint; 105 | for (var n:uint = 0; n < 256; n++) { 106 | c = n; 107 | for (var k:uint = 0; k < 8; k++) { 108 | if (c & 1) { 109 | c = uint(uint(0xedb88320) ^ 110 | uint(c >>> 1)); 111 | } else { 112 | c = uint(c >>> 1); 113 | } 114 | } 115 | crcTable[n] = c; 116 | } 117 | } 118 | var len:uint = 0; 119 | if (data != null) { 120 | len = data.length; 121 | } 122 | png.writeUnsignedInt(len); 123 | var p:uint = png.position; 124 | png.writeUnsignedInt(type); 125 | if ( data != null ) { 126 | png.writeBytes(data); 127 | } 128 | var e:uint = png.position; 129 | png.position = p; 130 | c = 0xffffffff; 131 | for (var i:int = 0; i < (e-p); i++) { 132 | c = uint(crcTable[ 133 | (c ^ png.readUnsignedByte()) & 134 | uint(0xff)] ^ uint(c >>> 8)); 135 | } 136 | c = uint(c^uint(0xffffffff)); 137 | png.position = e; 138 | png.writeUnsignedInt(c); 139 | } 140 | } 141 | } --------------------------------------------------------------------------------