PageRenderTime 56ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/org/haxel/HxlCamera.hx

http://github.com/sluther/haXel
Haxe | 712 lines | 376 code | 47 blank | 289 comment | 67 complexity | 43292428f22a1f8f04426df424f36537 MD5 | raw file
  1. package org.haxel;
  2. import flash.display.Bitmap;
  3. import flash.display.BitmapData;
  4. import flash.display.Sprite;
  5. import flash.geom.ColorTransform;
  6. import flash.geom.Point;
  7. import flash.geom.Rectangle;
  8. /**
  9. * The camera class is used to display the game's visuals in the Flash player.
  10. * By default one camera is created automatically, that is the same size as the Flash player.
  11. * You can add more cameras or even replace the main camera using utilities in <code>HxlG</code>.
  12. *
  13. * @author Adam Atomic
  14. */
  15. class HxlCamera extends HxlBasic
  16. {
  17. /**
  18. * Camera "follow" style preset: camera has no deadzone, just tracks the focus object directly.
  19. */
  20. public static inline var STYLE_LOCKON:UInt = 0;
  21. /**
  22. * Camera "follow" style preset: camera deadzone is narrow but tall.
  23. */
  24. public static inline var STYLE_PLATFORMER:UInt = 1;
  25. /**
  26. * Camera "follow" style preset: camera deadzone is a medium-size square around the focus object.
  27. */
  28. public static inline var STYLE_TOPDOWN:UInt = 2;
  29. /**
  30. * Camera "follow" style preset: camera deadzone is a small square around the focus object.
  31. */
  32. public static inline var STYLE_TOPDOWN_TIGHT:UInt = 3;
  33. /**
  34. * Camera "shake" effect preset: shake camera on both the X and Y axes.
  35. */
  36. public static inline var SHAKE_BOTH_AXES:UInt = 0;
  37. /**
  38. * Camera "shake" effect preset: shake camera on the X axis only.
  39. */
  40. public static inline var SHAKE_HORIZONTAL_ONLY:UInt = 1;
  41. /**
  42. * Camera "shake" effect preset: shake camera on the Y axis only.
  43. */
  44. public static inline var SHAKE_VERTICAL_ONLY:UInt = 2;
  45. /**
  46. * While you can alter the zoom of each camera after the fact,
  47. * this variable determines what value the camera will start at when created.
  48. */
  49. public static var defaultZoom:Float;
  50. /**
  51. * The X position of this camera's display. Zoom does NOT affect this number.
  52. * Measured in pixels from the left side of the flash window.
  53. */
  54. public var x:Float;
  55. /**
  56. * The Y position of this camera's display. Zoom does NOT affect this number.
  57. * Measured in pixels from the top of the flash window.
  58. */
  59. public var y:Float;
  60. /**
  61. * How wide the camera display is, in game pixels.
  62. */
  63. public var width:UInt;
  64. /**
  65. * How tall the camera display is, in game pixels.
  66. */
  67. public var height:UInt;
  68. /**
  69. * Tells the camera to follow this <code>HxlObject</code> object around.
  70. */
  71. public var target:HxlObject;
  72. /**
  73. * You can assign a "dead zone" to the camera in order to better control its movement.
  74. * The camera will always keep the focus object inside the dead zone,
  75. * unless it is bumping up against the bounds rectangle's edges.
  76. * The deadzone's coordinates are measured from the camera's upper left corner in game pixels.
  77. * For rapid prototyping, you can use the preset deadzones (e.g. <code>STYLE_PLATFORMER</code>) with <code>follow()</code>.
  78. */
  79. public var deadzone:HxlRect;
  80. /**
  81. * The edges of the camera's range, i.e. where to stop scrolling.
  82. * Measured in game pixels and world coordinates.
  83. */
  84. public var bounds:HxlRect;
  85. /**
  86. * Stores the basic parallax scrolling values.
  87. */
  88. public var scroll:HxlPoint;
  89. /**
  90. * The actual bitmap data of the camera display itself.
  91. */
  92. public var buffer:BitmapData;
  93. /**
  94. * The natural background color of the camera. Defaults to HxlG.bgColor.
  95. * NOTE: can be transparent for crazy FX!
  96. */
  97. public var bgColor:UInt;
  98. /**
  99. * Sometimes it's easier to just work with a <code>HxlSprite</code> than it is to work
  100. * directly with the <code>BitmapData</code> buffer. This sprite reference will
  101. * allow you to do exactly that.
  102. */
  103. public var screen:HxlSprite;
  104. /**
  105. * Indicates how far the camera is zoomed in.
  106. */
  107. private var _zoom:Float;
  108. /**
  109. * Internal, to help avoid costly allocations.
  110. */
  111. private var _point:HxlPoint;
  112. /**
  113. * Internal, help with color transforming the flash bitmap.
  114. */
  115. private var _color:UInt;
  116. /**
  117. * Internal, used to render buffer to screen space.
  118. */
  119. private var _flashBitmap:Bitmap;
  120. /**
  121. * Internal, used to render buffer to screen space.
  122. */
  123. public var _flashSprite:Sprite;
  124. /**
  125. * Internal, used to render buffer to screen space.
  126. */
  127. public var _flashOffsetX:Float;
  128. /**
  129. * Internal, used to render buffer to screen space.
  130. */
  131. public var _flashOffsetY:Float;
  132. /**
  133. * Internal, used to render buffer to screen space.
  134. */
  135. private var _flashRect:Rectangle;
  136. /**
  137. * Internal, used to render buffer to screen space.
  138. */
  139. private var _flashPoint:Point;
  140. /**
  141. * Internal, used to control the "flash" special effect.
  142. */
  143. private var _fxFlashColor:UInt;
  144. /**
  145. * Internal, used to control the "flash" special effect.
  146. */
  147. private var _fxFlashDuration:Float;
  148. /**
  149. * Internal, used to control the "flash" special effect.
  150. */
  151. private var _fxFlashComplete:Dynamic;
  152. /**
  153. * Internal, used to control the "flash" special effect.
  154. */
  155. private var _fxFlashAlpha:Float;
  156. /**
  157. * Internal, used to control the "fade" special effect.
  158. */
  159. private var _fxFadeColor:UInt;
  160. /**
  161. * Internal, used to control the "fade" special effect.
  162. */
  163. private var _fxFadeDuration:Float;
  164. /**
  165. * Internal, used to control the "fade" special effect.
  166. */
  167. private var _fxFadeComplete:Dynamic;
  168. /**
  169. * Internal, used to control the "fade" special effect.
  170. */
  171. private var _fxFadeAlpha:Float;
  172. /**
  173. * Internal, used to control the "shake" special effect.
  174. */
  175. private var _fxShakeIntensity:Float;
  176. /**
  177. * Internal, used to control the "shake" special effect.
  178. */
  179. private var _fxShakeDuration:Float;
  180. /**
  181. * Internal, used to control the "shake" special effect.
  182. */
  183. private var _fxShakeComplete:Dynamic;
  184. /**
  185. * Internal, used to control the "shake" special effect.
  186. */
  187. private var _fxShakeOffset:HxlPoint;
  188. /**
  189. * Internal, used to control the "shake" special effect.
  190. */
  191. private var _fxShakeDirection:UInt;
  192. /**
  193. * Internal helper variable for doing better wipes/fills between renders.
  194. */
  195. private var _fill:BitmapData;
  196. /**
  197. * Instantiates a new camera at the specified location, with the specified size and zoom level.
  198. *
  199. * @param X X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
  200. * @param Y Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
  201. * @param Width The width of the camera display in pixels.
  202. * @param Height The height of the camera display in pixels.
  203. * @param Zoom The initial zoom level of the camera. A zoom level of 2 will make all pixels display at 2x resolution.
  204. */
  205. public function new(X:Int,Y:Int,Width:Int,Height:Int,Zoom:Float=0)
  206. {
  207. x = X;
  208. y = Y;
  209. width = Width;
  210. height = Height;
  211. target = null;
  212. deadzone = null;
  213. scroll = new HxlPoint();
  214. _point = new HxlPoint();
  215. bounds = null;
  216. screen = new HxlSprite();
  217. screen.makeGraphic(width,height,0,true);
  218. screen.setOriginToCorner();
  219. buffer = screen.pixels;
  220. bgColor = HxlG.bgColor;
  221. _color = 0xffffff;
  222. _flashBitmap = new Bitmap(buffer);
  223. _flashBitmap.x = -width*0.5;
  224. _flashBitmap.y = -height*0.5;
  225. _flashSprite = new Sprite();
  226. zoom = Zoom; //sets the scale of flash sprite, which in turn loads flashoffset values
  227. _flashOffsetX = width*0.5*zoom;
  228. _flashOffsetY = height*0.5*zoom;
  229. _flashSprite.x = x + _flashOffsetX;
  230. _flashSprite.y = y + _flashOffsetY;
  231. _flashSprite.addChild(_flashBitmap);
  232. _flashRect = new Rectangle(0,0,width,height);
  233. _flashPoint = new Point();
  234. _fxFlashColor = 0;
  235. _fxFlashDuration = 0.0;
  236. _fxFlashComplete = null;
  237. _fxFlashAlpha = 0.0;
  238. _fxFadeColor = 0;
  239. _fxFadeDuration = 0.0;
  240. _fxFadeComplete = null;
  241. _fxFadeAlpha = 0.0;
  242. _fxShakeIntensity = 0.0;
  243. _fxShakeDuration = 0.0;
  244. _fxShakeComplete = null;
  245. _fxShakeOffset = new HxlPoint();
  246. _fxShakeDirection = 0;
  247. _fill = new BitmapData(width,height,true,0);
  248. }
  249. /**
  250. * Clean up memory.
  251. */
  252. override public function destroy():Void
  253. {
  254. screen.destroy();
  255. screen = null;
  256. target = null;
  257. scroll = null;
  258. deadzone = null;
  259. bounds = null;
  260. buffer = null;
  261. _flashBitmap = null;
  262. _flashRect = null;
  263. _flashPoint = null;
  264. _fxFlashComplete = null;
  265. _fxFadeComplete = null;
  266. _fxShakeComplete = null;
  267. _fxShakeOffset = null;
  268. _fill = null;
  269. }
  270. /**
  271. * Updates the camera scroll as well as special effects like screen-shake or fades.
  272. */
  273. override public function update():Void
  274. {
  275. //Either follow the object closely,
  276. //or doublecheck our deadzone and update accordingly.
  277. if(target != null)
  278. {
  279. if(deadzone == null)
  280. focusOn(target.getMidpoint(_point));
  281. else
  282. {
  283. var edge:Float;
  284. var targetX:Float = target.x + ((target.x > 0)?0.0000001:-0.0000001);
  285. var targetY:Float = target.y + ((target.y > 0)?0.0000001:-0.0000001);
  286. edge = targetX - deadzone.x;
  287. if(scroll.x > edge)
  288. scroll.x = edge;
  289. edge = targetX + target.width - deadzone.x - deadzone.width;
  290. if(scroll.x < edge)
  291. scroll.x = edge;
  292. edge = targetY - deadzone.y;
  293. if(scroll.y > edge)
  294. scroll.y = edge;
  295. edge = targetY + target.height - deadzone.y - deadzone.height;
  296. if(scroll.y < edge)
  297. scroll.y = edge;
  298. }
  299. }
  300. //Make sure we didn't go outside the camera's bounds
  301. if(bounds != null)
  302. {
  303. if(scroll.x < bounds.left)
  304. scroll.x = bounds.left;
  305. if(scroll.x > bounds.right - width)
  306. scroll.x = bounds.right - width;
  307. if(scroll.y < bounds.top)
  308. scroll.y = bounds.top;
  309. if(scroll.y > bounds.bottom - height)
  310. scroll.y = bounds.bottom - height;
  311. }
  312. //Update the "flash" special effect
  313. if(_fxFlashAlpha > 0.0)
  314. {
  315. _fxFlashAlpha -= HxlG.elapsed/_fxFlashDuration;
  316. if((_fxFlashAlpha <= 0) && (_fxFlashComplete != null))
  317. _fxFlashComplete();
  318. }
  319. //Update the "fade" special effect
  320. if((_fxFadeAlpha > 0.0) && (_fxFadeAlpha < 1.0))
  321. {
  322. _fxFadeAlpha += HxlG.elapsed/_fxFadeDuration;
  323. if(_fxFadeAlpha >= 1.0)
  324. {
  325. _fxFadeAlpha = 1.0;
  326. if(_fxFadeComplete != null)
  327. _fxFadeComplete();
  328. }
  329. }
  330. //Update the "shake" special effect
  331. if(_fxShakeDuration > 0)
  332. {
  333. _fxShakeDuration -= HxlG.elapsed;
  334. if(_fxShakeDuration <= 0)
  335. {
  336. _fxShakeOffset.make();
  337. if(_fxShakeComplete != null)
  338. _fxShakeComplete();
  339. }
  340. else
  341. {
  342. if((_fxShakeDirection == SHAKE_BOTH_AXES) || (_fxShakeDirection == SHAKE_HORIZONTAL_ONLY))
  343. _fxShakeOffset.x = (HxlG.random()*_fxShakeIntensity*width*2-_fxShakeIntensity*width)*_zoom;
  344. if((_fxShakeDirection == SHAKE_BOTH_AXES) || (_fxShakeDirection == SHAKE_VERTICAL_ONLY))
  345. _fxShakeOffset.y = (HxlG.random()*_fxShakeIntensity*height*2-_fxShakeIntensity*height)*_zoom;
  346. }
  347. }
  348. }
  349. /**
  350. * Tells this camera object what <code>HxlObject</code> to track.
  351. *
  352. * @param Target The object you want the camera to track. Set to null to not follow anything.
  353. * @param Style Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling <code>follow()</code>.
  354. */
  355. public function follow(Target:HxlObject, Style:UInt=STYLE_LOCKON):Void
  356. {
  357. target = Target;
  358. var helper:Float;
  359. switch(Style)
  360. {
  361. case STYLE_PLATFORMER:
  362. var w:Float = width/8;
  363. var h:Float = height/3;
  364. deadzone = new HxlRect((width-w)/2,(height-h)/2 - h*0.25,w,h);
  365. case STYLE_TOPDOWN:
  366. helper = HxlU.max(width,height)/4;
  367. deadzone = new HxlRect((width-helper)/2,(height-helper)/2,helper,helper);
  368. case STYLE_TOPDOWN_TIGHT:
  369. helper = HxlU.max(width,height)/8;
  370. deadzone = new HxlRect((width-helper)/2,(height-helper)/2,helper,helper);
  371. case STYLE_LOCKON:
  372. default:
  373. deadzone = null;
  374. }
  375. }
  376. /**
  377. * Move the camera focus to this location instantly.
  378. *
  379. * @param Point Where you want the camera to focus.
  380. */
  381. public function focusOn(Point:HxlPoint):Void
  382. {
  383. Point.x += (Point.x > 0)?0.0000001:-0.0000001;
  384. Point.y += (Point.y > 0)?0.0000001:-0.0000001;
  385. scroll.make(Point.x - width*0.5,Point.y - height*0.5);
  386. }
  387. /**
  388. * Specify the boundaries of the level or where the camera is allowed to move.
  389. *
  390. * @param X The smallest X value of your level (usually 0).
  391. * @param Y The smallest Y value of your level (usually 0).
  392. * @param Width The largest X value of your level (usually the level width).
  393. * @param Height The largest Y value of your level (usually the level height).
  394. * @param UpdateWorld Whether the global quad-tree's dimensions should be updated to match (default: false).
  395. */
  396. public function setBounds(X:Float=0, Y:Float=0, Width:Float=0, Height:Float=0, UpdateWorld:Bool=false):Void
  397. {
  398. if(bounds == null)
  399. bounds = new HxlRect();
  400. bounds.make(X,Y,Width,Height);
  401. if(UpdateWorld)
  402. HxlG.worldBounds.copyFrom(bounds);
  403. update();
  404. }
  405. /**
  406. * The screen is filled with this color and gradually returns to normal.
  407. *
  408. * @param Color The color you want to use.
  409. * @param Duration How long it takes for the flash to fade.
  410. * @param OnComplete A function you want to run when the flash finishes.
  411. * @param Force Force the effect to reset.
  412. */
  413. public function flash(Color:UInt=0xffffffff, Duration:Float=1, OnComplete:Dynamic=null, Force:Bool=false):Void
  414. {
  415. if(!Force && (_fxFlashAlpha > 0.0))
  416. return;
  417. _fxFlashColor = Color;
  418. if(Duration <= 0)
  419. Duration = 0.01;
  420. _fxFlashDuration = Duration;
  421. _fxFlashComplete = OnComplete;
  422. _fxFlashAlpha = 1.0;
  423. }
  424. /**
  425. * The screen is gradually filled with this color.
  426. *
  427. * @param Color The color you want to use.
  428. * @param Duration How long it takes for the fade to finish.
  429. * @param OnComplete A function you want to run when the fade finishes.
  430. * @param Force Force the effect to reset.
  431. */
  432. public function fade(Color:UInt=0xff000000, Duration:Float=1, OnComplete:Dynamic=null, Force:Bool=false):Void
  433. {
  434. if(!Force && (_fxFadeAlpha > 0.0))
  435. return;
  436. _fxFadeColor = Color;
  437. if(Duration <= 0)
  438. Duration = 0.01;
  439. _fxFadeDuration = Duration;
  440. _fxFadeComplete = OnComplete;
  441. _fxFadeAlpha = 0.01;
  442. }
  443. /**
  444. * A simple screen-shake effect.
  445. *
  446. * @param Intensity Percentage of screen size representing the maximum distance that the screen can move while shaking.
  447. * @param Duration The length in seconds that the shaking effect should last.
  448. * @param OnComplete A function you want to run when the shake effect finishes.
  449. * @param Force Force the effect to reset (default = true, unlike flash() and fade()!).
  450. * @param Direction Whether to shake on both axes, just up and down, or just side to side (use class constants SHAKE_BOTH_AXES, SHAKE_VERTICAL_ONLY, or SHAKE_HORIZONTAL_ONLY).
  451. */
  452. public function shake(Intensity:Float=0.05, Duration:Float=0.5, OnComplete:Dynamic=null, Force:Bool=true, Direction:UInt=SHAKE_BOTH_AXES):Void
  453. {
  454. if(!Force && ((_fxShakeOffset.x != 0) || (_fxShakeOffset.y != 0)))
  455. return;
  456. _fxShakeIntensity = Intensity;
  457. _fxShakeDuration = Duration;
  458. _fxShakeComplete = OnComplete;
  459. _fxShakeDirection = Direction;
  460. _fxShakeOffset.make();
  461. }
  462. /**
  463. * Just turns off all the camera effects instantly.
  464. */
  465. public function stopFX():Void
  466. {
  467. _fxFlashAlpha = 0.0;
  468. _fxFadeAlpha = 0.0;
  469. _fxShakeDuration = 0;
  470. _flashSprite.x = x + width*0.5;
  471. _flashSprite.y = y + height*0.5;
  472. }
  473. /**
  474. * Copy the bounds, focus object, and deadzone info from an existing camera.
  475. *
  476. * @param Camera The camera you want to copy from.
  477. *
  478. * @return A reference to this <code>HxlCamera</code> object.
  479. */
  480. public function copyFrom(Camera:HxlCamera):HxlCamera
  481. {
  482. if(Camera.bounds == null)
  483. bounds = null;
  484. else
  485. {
  486. if(bounds == null)
  487. bounds = new HxlRect();
  488. bounds.copyFrom(Camera.bounds);
  489. }
  490. target = Camera.target;
  491. if(target != null)
  492. {
  493. if(Camera.deadzone == null)
  494. deadzone = null;
  495. else
  496. {
  497. if(deadzone == null)
  498. deadzone = new HxlRect();
  499. deadzone.copyFrom(Camera.deadzone);
  500. }
  501. }
  502. return this;
  503. }
  504. /**
  505. * The zoom level of this camera. 1 = 1:1, 2 = 2x zoom, etc.
  506. */
  507. public var zoom(getZoom, setZoom):Float;
  508. public function getZoom():Float
  509. {
  510. return _zoom;
  511. }
  512. /**
  513. * @private
  514. */
  515. public function setZoom(Zoom:Float):Float
  516. {
  517. if(Zoom == 0)
  518. _zoom = defaultZoom;
  519. else
  520. _zoom = Zoom;
  521. setScale(_zoom,_zoom);
  522. }
  523. /**
  524. * The alpha value of this camera display (a Number between 0.0 and 1.0).
  525. */
  526. public var alpha(getAlpha, setAlpha):Float;
  527. public function getAlpha():Float
  528. {
  529. return _flashBitmap.alpha;
  530. }
  531. /**
  532. * @private
  533. */
  534. public function setAlpha(Alpha:Float):Float
  535. {
  536. _flashBitmap.alpha = Alpha;
  537. }
  538. /**
  539. * The angle of the camera display (in degrees).
  540. * Currently yields weird display results,
  541. * since cameras aren't nested in an extra display object yet.
  542. */
  543. public var angle(getAngle, setAngle):Float;
  544. public function getAngle():Float
  545. {
  546. return _flashSprite.rotation;
  547. }
  548. /**
  549. * @private
  550. */
  551. public function setAngle(Angle:Float):Float
  552. {
  553. _flashSprite.rotation = Angle;
  554. }
  555. /**
  556. * The color tint of the camera display.
  557. */
  558. public var color(getColor, setColor):UInt;
  559. public function getColor():UInt
  560. {
  561. return _color;
  562. }
  563. /**
  564. * @private
  565. */
  566. public function setColor(Color:UInt):UInt
  567. {
  568. _color = Color;
  569. var colorTransform:ColorTransform = _flashBitmap.transform.colorTransform;
  570. colorTransform.redMultiplier = (_color>>16)*0.00392;
  571. colorTransform.greenMultiplier = (_color>>8&0xff)*0.00392;
  572. colorTransform.blueMultiplier = (_color&0xff)*0.00392;
  573. _flashBitmap.transform.colorTransform = colorTransform;
  574. }
  575. /**
  576. * Whether the camera display is smooth and filtered, or chunky and pixelated.
  577. * Default behavior is chunky-style.
  578. */
  579. public var antialiasing(getAntialiasing, setAntialiasing):Bool;
  580. public function getAntialiasing():Bool
  581. {
  582. return _flashBitmap.smoothing;
  583. }
  584. /**
  585. * @private
  586. */
  587. public function setAntialiasing(Antialiasing:Bool):Bool
  588. {
  589. _flashBitmap.smoothing = Antialiasing;
  590. }
  591. /**
  592. * The scale of the camera object, irrespective of zoom.
  593. * Currently yields weird display results,
  594. * since cameras aren't nested in an extra display object yet.
  595. */
  596. public var scale(getScale, setScale):HxlPoint;
  597. public function getScale():HxlPoint
  598. {
  599. /**
  600. * due to haXe getter and setter restrictions,
  601. * we can't accept Float arguments for the setter
  602. * and return a HxlPoint for the getter, so we
  603. * accept <code>HxlPoint</code>s instead.
  604. */
  605. return _point.make(_flashSprite.scaleX,_flashSprite.scaleY);
  606. }
  607. /**
  608. * @private
  609. */
  610. public function setScale(Point:HxlPoint):HxlPoint
  611. {
  612. _flashSprite.scaleX = Point.x;
  613. _flashSprite.scaleY = Point.y;
  614. }
  615. /**
  616. * Fetches a reference to the Flash <code>Sprite</code> object
  617. * that contains the camera display in the Flash display list.
  618. * Uses include 3D projection, advanced display list modification, and more.
  619. * NOTE: We don't recommend modifying this directly unless you are
  620. * fairly experienced. For simple changes to the camera display,
  621. * like scaling, rotation, and color tinting, we recommend
  622. * using the existing <code>HxlCamera</code> variables.
  623. *
  624. * @return A Flash <code>Sprite</code> object containing the camera display.
  625. */
  626. public function getContainerSprite():Sprite
  627. {
  628. return _flashSprite;
  629. }
  630. /**
  631. * Fill the camera with the specified color.
  632. *
  633. * @param Color The color to fill with in 0xAARRGGBB hex format.
  634. * @param BlendAlpha Whether to blend the alpha value or just wipe the previous contents. Default is true.
  635. */
  636. public function fill(Color:UInt,BlendAlpha:Bool=true):Void
  637. {
  638. _fill.fillRect(_flashRect,Color);
  639. buffer.copyPixels(_fill,_flashRect,_flashPoint,null,null,BlendAlpha);
  640. }
  641. /**
  642. * Internal helper function, handles the actual drawing of all the special effects.
  643. */
  644. public function drawFX():Void
  645. {
  646. var alphaComponent:Float;
  647. //Draw the "flash" special effect onto the buffer
  648. if(_fxFlashAlpha > 0.0)
  649. {
  650. alphaComponent = _fxFlashColor>>24;
  651. fill((uint(((alphaComponent <= 0)?0xff:alphaComponent)*_fxFlashAlpha)<<24)+(_fxFlashColor&0x00ffffff));
  652. }
  653. //Draw the "fade" special effect onto the buffer
  654. if(_fxFadeAlpha > 0.0)
  655. {
  656. alphaComponent = _fxFadeColor>>24;
  657. fill((uint(((alphaComponent <= 0)?0xff:alphaComponent)*_fxFadeAlpha)<<24)+(_fxFadeColor&0x00ffffff));
  658. }
  659. if((_fxShakeOffset.x != 0) || (_fxShakeOffset.y != 0))
  660. {
  661. _flashSprite.x = x + _flashOffsetX + _fxShakeOffset.x;
  662. _flashSprite.y = y + _flashOffsetY + _fxShakeOffset.y;
  663. }
  664. }
  665. }