[Stage3D] Starlingを試すのだ! (16) ~ParticleSystem~

Flash Player 11 から採用された Stage3D を学習するよ。 :bouzu:
Starling Framework を試しちゃうんだからね。 :girl:

starling316

ParticleSystemクラス(PDParticleSystemクラス)を使ってみちゃうよ。 :boy:

particle.pex データは、@taikiken 先生 :hakase: に教えていただきました! :beer:

:caution: 要 Flash Player 11.8 以上

This movie requires Flash Player 11.8.0

Main.as
package {

  import flash.display.Sprite;
  import flash.display.StageScaleMode;
  import flash.display.StageAlign;

  import starling.core.Starling;

  [SWF(backgroundColor="#FFFFFF", width="600", height="400", frameRate="60")]

  public class Main extends Sprite {
    // プロパティ
    private var starling:Starling;

    // コンストラクタ
    public function Main() {
      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.align = StageAlign.TOP_LEFT;
      init();
    }

    // メソッド
    private function init():void {
      starling = new Starling(MainView, stage, null, null);
      starling.enableErrorChecking = true;
      starling.start();
    }

  }

}



import flash.geom.Rectangle;
import starling.core.Starling;
import starling.display.Sprite;
import starling.extensions.ParticleSystem;
import starling.extensions.PDParticleSystem;
import starling.textures.Texture;
import starling.events.Event;
import starling.events.ResizeEvent;
import starling.events.Touch;
import starling.events.TouchEvent;


internal class MainView extends Sprite {
  [Embed(source="assets/particle.pex", mimeType="application/octet-stream")]
  private var StarConfig:Class;
  [Embed(source="assets/star.png")]
  private var StarParticle:Class;
  // プロパティ
  private var particles:ParticleSystem;

  // コンストラクタ
  public function MainView() {
    addEventListener(Event.ADDED_TO_STAGE, init);
    addEventListener(Event.REMOVED_FROM_STAGE, remove);
  }

  // メソッド
  private function init(evt:Event):void {
    removeEventListener(Event.ADDED_TO_STAGE, init);
    particles = new PDParticleSystem(XML(new StarConfig()), Texture.fromBitmap(new StarParticle()));
    addChild(particles);
    particles.start();

    particles.emitterX = 300;
    particles.emitterY = 200;

    Starling.juggler.add(particles);
    stage.addEventListener(TouchEvent.TOUCH, touch);
    stage.addEventListener(ResizeEvent.RESIZE, resize);
  }
  private function remove(evt:Event):void {
    removeEventListener(Event.REMOVED_FROM_STAGE, remove);
    Starling.juggler.remove(particles);
  }
  override public function dispose():void {
    removeEventListener(Event.ADDED_TO_STAGE, init);
    removeEventListener(Event.REMOVED_FROM_STAGE, remove);
    super.dispose();
  }
  private function touch(evt:TouchEvent):void {
    var touch:Touch = evt.getTouch(stage);
    if (touch) {
      particles.emitterX = touch.globalX;
      particles.emitterY = touch.globalY;

    }
  }
  private function resize(evt:ResizeEvent):void {
    var sw:uint = evt.width;
    var sh:uint = evt.height;
    Starling.current.viewPort = new Rectangle(0, 0, sw, sh);
    stage.stageWidth = sw;
    stage.stageHeight = sh;
  }

}

particle.pex
<particleEmitterConfig>
  <texture name="star.png"/>
  <sourcePosition x="0.00" y="0.00"/>
  <sourcePositionVariance x="0.00" y="0.00"/>
  <speed value="320.00"/>
  <speedVariance value="40.00"/>
  <particleLifeSpan value="1.6000"/>
  <particleLifespanVariance value="0.0000"/>
  <angle value="360.00"/>
  <angleVariance value="320.00"/>
  <gravity x="0.00" y="0.00"/>

  <radialAcceleration value="-1000.00"/>
  <tangentialAcceleration value="-4.00"/>

  <radialAccelVariance value="5.00"/>
  <tangentialAccelVariance value="225.00"/>

  <startColor red="1.00" green="0.16" blue="0.64" alpha="0.50"/>
  <startColorVariance red="0.50" green="0.50" blue="0.75" alpha="0.40"/>
  <finishColor red="0.00" green="0.32" blue="0.50" alpha="0.80"/>
  <finishColorVariance red="0.32" green="0.64" blue="0.60" alpha="0.64"/>

  <maxParticles value="320"/>
  <startParticleSize value="4.00"/>
  <startParticleSizeVariance value="40.00"/>
  <finishParticleSize value="4.00"/>
  <FinishParticleSizeVariance value="4.00"/>

  <duration value="0.00"/>
  <emitterType value="0"/>
  <maxRadius value="100.00"/>
  <maxRadiusVariance value="0.00"/>
  <minRadius value="0.00"/>
  <rotatePerSecond value="0.00"/>
  <rotatePerSecondVariance value="0.00"/>

  <blendFuncSource value="1"/>
  <blendFuncDestination value="1"/>

  <rotationStart value="120.00"/>
  <rotationStartVariance value="0.00"/>
  <rotationEnd value="0.00"/>
  <rotationEndVariance value="0.00"/>
</particleEmitterConfig>


[修正] (13/01/17 Thu 11:42)
Starling 1.3 にバージョンアップ。
[修正] (13/09/26 Thu 00:11)
Starling 1.4 にバージョンアップ。
[修正] (13/11/12 Tue 18:32)
Starling 1.4.1 にバージョンアップ。
[修正] (14/06/25 Wed 15:00)
Starling 1.5 にバージョンアップ。
[修正] (14/06/25 Wed 17:05)
Starling 1.5.1 にバージョンアップ。
[修正] (14/12/14 Sun 20:27)
Starling 1.6 にバージョンアップ。