/examples3D/ExplodeImage/PureAs3/Main.as

https://github.com/404Assassin/Flint-examples · ActionScript · 102 lines · 63 code · 11 blank · 28 comment · 2 complexity · f4e3720a9cec76083d5f94a1b648351e MD5 · raw file

  1. /*
  2. * FLINT PARTICLE SYSTEM
  3. * .....................
  4. *
  5. * Author: Richard Lord
  6. * Copyright (c) Richard Lord 2008-2011
  7. * http://flintparticles.org/
  8. *
  9. * Licence Agreement
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a copy
  12. * of this software and associated documentation files (the "Software"), to deal
  13. * in the Software without restriction, including without limitation the rights
  14. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. * copies of the Software, and to permit persons to whom the Software is
  16. * furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be included in
  19. * all copies or substantial portions of the Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27. * THE SOFTWARE.
  28. */
  29. package
  30. {
  31. import org.flintparticles.common.events.EmitterEvent;
  32. import org.flintparticles.common.particles.Particle;
  33. import org.flintparticles.threeD.actions.DeathZone;
  34. import org.flintparticles.threeD.actions.Explosion;
  35. import org.flintparticles.threeD.actions.Move;
  36. import org.flintparticles.threeD.emitters.Emitter3D;
  37. import org.flintparticles.threeD.particles.Particle3DUtils;
  38. import org.flintparticles.threeD.renderers.DisplayObjectRenderer;
  39. import org.flintparticles.threeD.zones.FrustrumZone;
  40. import flash.display.BitmapData;
  41. import flash.display.Sprite;
  42. import flash.events.MouseEvent;
  43. import flash.geom.Point;
  44. import flash.geom.Rectangle;
  45. import flash.geom.Vector3D;
  46. [SWF(width='500', height='350', frameRate='60', backgroundColor='#000000')]
  47. public class Main extends Sprite
  48. {
  49. private var emitter:Emitter3D;
  50. private var bitmap:BitmapData;
  51. private var renderer:DisplayObjectRenderer;
  52. private var explosion:Explosion;
  53. public function Main()
  54. {
  55. bitmap = new Image1( 384, 255 );
  56. renderer = new DisplayObjectRenderer();
  57. renderer.camera.dolly( -400 );
  58. renderer.camera.projectionDistance = 400;
  59. renderer.y = 175;
  60. renderer.x = 250;
  61. addChild( renderer );
  62. emitter = new Emitter3D();
  63. emitter.addAction( new Move() );
  64. emitter.addAction( new DeathZone( new FrustrumZone( renderer.camera, new Rectangle( -290, -215, 580, 430 ) ), true ) );
  65. prepare();
  66. renderer.addEmitter( emitter );
  67. emitter.start();
  68. stage.addEventListener( MouseEvent.CLICK, explode, false, 0, true );
  69. emitter.addEventListener( EmitterEvent.EMITTER_EMPTY, prepare );
  70. }
  71. private function prepare( event:EmitterEvent = null ):void
  72. {
  73. if( explosion )
  74. {
  75. emitter.removeAction( explosion );
  76. explosion = null;
  77. }
  78. var particles:Vector.<Particle> = Particle3DUtils.createRectangleParticlesFromBitmapData( bitmap, 12, emitter.particleFactory, new Vector3D( -192, -127, 0 ) );
  79. emitter.addParticles( particles, false );
  80. }
  81. private function explode( ev:MouseEvent ):void
  82. {
  83. if( !explosion )
  84. {
  85. var p:Point = renderer.globalToLocal( new Point( ev.stageX, ev.stageY ) );
  86. explosion = new Explosion( 8, new Vector3D( p.x, p.y, 50 ), 500 );
  87. emitter.addAction( explosion );
  88. }
  89. }
  90. }
  91. }