Created
July 3, 2012 05:53
-
-
Save lizhi525/3037959 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import flash.display.Bitmap; | |
import flash.display.BitmapData; | |
import flash.display.Sprite; | |
import flash.display.StageAlign; | |
import flash.display.StageScaleMode; | |
import flash.events.Event; | |
import flash.events.MouseEvent; | |
import flash.text.TextField; | |
import flash.text.TextFieldAutoSize; | |
import net.game_develop.animation.gpu.display.GpuAnimationData; | |
import net.game_develop.animation.gpu.display.GpuAnimationParser; | |
import net.game_develop.animation.gpu.display.GpuAnimationSprite; | |
import net.game_develop.animation.gpu.display.GpuObj2d; | |
import net.game_develop.animation.gpu.display.GpuSpriteLayer; | |
import net.game_develop.animation.gpu.GpuView2d; | |
import net.game_develop.animation.utils.Stats; | |
/** | |
* ... | |
* @author lizhi http://game-develop.net/ | |
*/ | |
public class Test extends GpuView2d | |
{ | |
[Embed(source = "assets/all.xml", mimeType="application/octet-stream")]private var xmlc:Class; | |
private var xml:XML = new XML(new xmlc); | |
[Embed(source = "assets/all.png")]private var bmdc:Class; | |
private var bmd:BitmapData = (new bmdc as Bitmap).bitmapData; | |
private var frameNames:Array = ["GUPPY_G_SWIM", "GUPPY_G_TURN", "GUPPY_G_EAT", "GUPPY_G_DIE", "GUPPY_O_SWIM", "GUPPY_O_EAT", "GUPPY_O_TURN","monkey"]; | |
private var anms:Array = []; | |
private var onceCount:int = 100; | |
private var layer:GpuObj2d; | |
private var tf:TextField; | |
private var images:Array=[]; | |
public function Test() | |
{ | |
super(stage.stageWidth, stage.stageHeight); | |
bgcolor = 0xff000000; | |
antiAlias = 0; | |
tf = new TextField; | |
tf.autoSize = TextFieldAutoSize.LEFT; | |
tf.background = true; | |
tf.backgroundColor = 0xffffff; | |
addChild(tf); | |
tf.selectable = tf.mouseWheelEnabled = false; | |
tf.x = 100; | |
for each(var name:String in frameNames) { | |
var anm:GpuAnimationData = GpuAnimationParser.parserFromTexturePack(bmd, xml,name); | |
anms.push(anm); | |
} | |
//改变这行来决定用哪种显示 | |
layer = new GpuSpriteLayer(this, onceCount); | |
//layer = new GpuObj2d; | |
add(layer); | |
addChild(new Stats); | |
stage.addEventListener(MouseEvent.CLICK,addSomeBody); | |
stage.scaleMode = StageScaleMode.NO_SCALE; | |
stage.align = StageAlign.TOP_LEFT; | |
addSprite(); | |
} | |
private function addSomeBody(e:MouseEvent):void | |
{ | |
addSprite(); | |
} | |
public function addSprite():void | |
{ | |
for(var i:int=0;i<onceCount;i++) | |
{ | |
var sprite:GpuAnimationSprite = new GpuAnimationSprite; | |
var anm:GpuAnimationData=anms[int(anms.length*Math.random())] | |
sprite.addAnimation(anm); | |
sprite.play(anm.name); | |
layer.add(sprite); | |
images.push(sprite); | |
sprite.x = viewWidth * Math.random(); | |
sprite.y = viewHeight * Math.random(); | |
sprite.scaleX = (Math.random() > .5) ? -1 : 1; | |
sprite.scaleGap = .5; | |
} | |
tf.text = images.length + ""; | |
} | |
override public function render(e:Event = null):void | |
{ | |
super.render(); | |
var s:GpuObj2d; | |
for (var i:int=0, l:int=images.length; i < l; i++) | |
{ | |
s=images[i]; | |
translateSprite(s); | |
} | |
} | |
protected function translateSprite(sprite:GpuObj2d):void | |
{ | |
sprite.x+=((sprite.scaleX < 0) ? -2 : 2); | |
if (sprite.x > viewWidth || sprite.x < 0) | |
{ | |
sprite.scaleX = -sprite.scaleX; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment