中国开发网: 论坛: 程序员情感CBD: 贴子 736542
JoJo: 主控
package com.thinkspace.MoonMark
{
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;

public class StarSpace extends Sprite implements ISizeDraw
{
private var bgShape:Shape;
public function StarSpace()
{
super();
bgShape = new Shape();
this.addChild(bgShape);

this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}

private var _isPlay:Boolean = false;

public function get isStarSpacePlay():Boolean{return _isPlay;};

public function playStarSpace():void{
_isPlay = true;
}
public function stopStarSpace():void{
_isPlay = false;
}

private var _h:int;
private var _w:int;
public function sizeDraw(w:int, h:int):void
{
_w = w;
_h = h;
this.setChildIndex(bgShape, 0);
var g:Graphics = this.bgShape.graphics;
g.clear();
g.beginFill(0x00000);
g.drawRect(0,0,w,h);
}

private var starArray:Array = null;
private function onEnterFrame(event:Event):void{
if (_isPlay){
if (starArray == null){
starArray = new Array();
for (var i:int = 0;i < 400; i ++){
var st:Star = new Star(uint(Math.random()*4), Math.random() + 0.2, Math.random() * 10 + 1);
starArray.push(st);
this.addChild(st);
st.draw();
st.resetLocation(Math.random() * _w, Math.random() * _h);
}
}
for each(var star:Star in starArray){
star.moveNextStep();
if ((star.y > _h) || (star.x > _w) || (star.x < 0)){
star.resetLocation(Math.random() * _w, 0);
}
}
}else{
for each(var item:Star in starArray){
this.removeChild(item);
}
starArray = null;
}
}
}
}

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录