- 浏览: 13989 次
最新评论
FLEX和Actionscript开发FLASH游戏 3-2
2010年10月26日
使用FLEX和Actionscript开发FLASH 游戏-嵌入资源等
package
{
import flash.display.*;
import mx.collection.*;
import mx.core.*;
public class GameObjectManager
{
//double buffer
public var backBuffer:BitmapData;
//colour to use to clear backbuffer with
public var clearColor:uint=0xFF0043AB;
//static instance
protected static var instance:GameObjectManager=null;
//the last frame time
protected var lastFrame:Date;
//a collection of the GameObjects
protected var gameObjects:ArrayCollection=new ArrayCollection();
//a collection where new GameObjects are placed,to avoid adding items
//a gameObjects while in the gameObjects collection while it is in a loop
protected var newGameObjects:ArrayCollection = new ArrayCollection();
//a collection where removed GameObjects are placed,to avoid removing items
//to gameObjects while in the gameObjects collection while it is in a loop
protected var removedGameObjects:ArrayCollection=new ArrayCollection();
static public function get Instance():GameObjectManager
{
if(instance == null)
instance=new GameObjectManager();
return instance;
}
public function GameObjectManager()
{
if(instance!=null)
throw new Error("Only one Singleton instance should be instantiated");
backBuffer=new BitmapData (Application.application.width,Application.applica tion.height,false);
}
public function startup():void
{
lastFrame=new Date();
new Bounce().startupBounce();
}
public function shutdown():void
{
shutdownAll();
}
public function enterFrame():void
{
//Calculate the time since the lastframe
var thisFrame:Date=new Date();
var seconds:Number=(thisFrame.getTime()-lastFrame.getT ime())/1000.0;
lastFrame=thisFrame;
removeDeletedGameObjects();
insertNewGameObjects();
//now allow objects to update themselves
for each(var gameObject:GameObject in gameObjects)
{
if(gameObject.inuse)
gameObject.enterFrame(seconds);
}
drawObjects();
} protected function drawObjects():void { backBuffer.fillRect(backBuffer.rect,clearColor); //draw the objects for each(var gameObject:GameObject in gameObjects) { if(gameObject.inuse) gameObject.copyToBackBuffer(backBuffer); } } public function addGameObject(gameObject:GameObject):viod { newGameObjects.addItem(gameObject); } public function removeGameObject(gameObject:GameObject):void { removedGameObjects.addItem(gameObject); } protected function shutdownAll():void { //don't dispose objects twice for each(var gameObject:GameObject in gameObjects) { var found:Boolean=false; for each (var removedObject:GameObject in removedGameObjects) { if(removedObject==gameObject) { found=true; break; } } if (!found) gameObject.shutdown(); } } protected function insertNewGameObjects():void { for each(var gameObject:GameObject in newGameObjects) { for (var i:int=0;igameObject.zOrde r|| gameObjects.getItemAt(i).zOrder==-1) break; } gameObjects.addItemAt(gameObject,i); } newGameObjects.removedAll(); } protected function removedDeletedGameObjects():void { //insert the object acording to it's z position for each(var removedObject:GameObject in removedGameObjects) { var i:int=0; for (i=0;i<gameObjects.length;++i) { if(gameObjects.getItemAt(i)==removedObject) { gameObjects.removeItemAt(i); break; } } } removedGameObjects.removedAll(); } }
发表评论
-
DEMO:字符串反转
2012-07-06 09:52 717这个例子主要是让用户输入的字符串反转之后显示出来,主要是用 ... -
用正则表达式做内容关键字链接
2012-07-06 09:46 685private void rc() { strin ... -
基于ASP.NET的JQueryUI控件开发(1) - JQueryScriptManager
2012-07-06 09:30 389前面基本实现了ASP.NET MVC的 JQueryUI控 ... -
Javascript模式- 命令模式(Command)
2012-07-05 20:45 749前言 博客园谈设计 ... -
自定义android RadioPreference组件
2012-07-03 13:44 1390今天用到了android的preferences组件,可是 ... -
flex4 设置 圆角
2012-07-02 12:51 858height="100%" left= ... -
flex AS中TabNavigator子项后报超出索引 commitProperties解决
2012-07-02 12:51 542height="200" > ... -
Dom4j java编程
2012-07-02 12:51 833dom4j 是一种解析 XML 文档的开放源代码 XML ... -
Event propagation事件传播
2012-07-02 12:51 788当事件被触发时,F ... -
flex 给DataGrid每行加上tooltip
2012-07-02 12:51 690在初始化时加上tooltip的字体大小 mx.sty ... -
Flex4自定义事件类型Event的相关应用
2012-07-01 10:18 762基于松耦合的概念 自定义事件类型将取到很重要的作用 当您 ... -
flex学习-----事件机制的工作流程
2012-07-01 10:18 8388.2 事件机制的工作流程 8.2.1 关于事件流 ... -
Flex事件机制一
2012-07-01 10:17 770一:事件流机制 由于OOP编程将程序看成一个个对象、 ... -
Flex FTP文件上传
2012-07-01 10:17 660Flex FTP文件上传原理就是利用Flex Socket ... -
使用Flex实现FTP文件上传功能
2012-07-01 10:17 953最近需要使用Flex实现Ftp文件上传功能,Google到 ... -
未来的移动游戏
2012-06-30 16:43 595未来的移动游戏 2011年07月14日 手机游戏是娱乐 ... -
游戏战歌网 仿soso音乐 flex播放器
2012-06-30 16:42 749游戏战歌网 仿soso音乐 flex播放器 2010年08月 ... -
Flash游戏开发技术分析
2012-06-30 16:42 661Flash游戏开发技术分析 2010年12月31日 1、 ...
相关推荐
使用FLEX 和 Actionscript 开发FLASH 游戏3-1
使用FLEX 和 Actionscript 开发FLASH 游戏8-1
使用FLEX和Actionscript开发FLASH 游戏
使用FLEX和Actionscript开发FLASH 游戏
使用FLEX 和 Actionscript 开发FLASH 游戏
使用FLEX和Actionscript开发FLASH 游戏
使用FLEX和Actionscript开发FLASH 游戏
使用FLEX 和 Actionscript 开发FLASH 游戏
使用FLEX和Actionscript开发FLASH 游戏
使用FLEX和Actionscript开发FLASH 游戏
使用FLEX和Actionscript开发FLASH 游戏
使用FLEX 和 Actionscript 开发FLASH 游戏
使用FLEX 和 Actionscript 开发FLASH 游戏
FLEX和Actionscript开发FLASH游戏的中文文档,内容和详细 希望对你有用~
使用FLEX 和 Actionscript开发FLASH 游戏(一)
使用FLEX 和 Actionscript开发FLASH 游戏
使用FLEX和 Actionscript 开发FLASH游戏
使用FLEX 和 Actionscript开发FLASH 游戏
使用FLEX 和 Actionscript开发FLASH 游戏
使用FLEX 和 Actionscript开发FLASH 游戏