使用FLEX和 Actionscript 开发FLASH游戏(三)-1
2011-06-30 22:29
477 查看
使用FLEX 和 Actionscript开发FLASH 游戏—嵌入资源和增加游戏元素
“使用FLEX开发游戏”系列之三
写自Matthew Casperson Casperson
2008年10月31日出版
在第三部分我们将增加一些图像资源并把它们显示在屏幕上
标签:Flex,Flash,tutorial,Actionscript,game
转到:第一部分
在写一个新程序的时候,总存在这么一个点,从这儿你可以看见你的劳动成果。通过实现状态和绘制的管道,我们现在可以开始做有趣的事情了,比如在游戏中添加图像,把它们显示在屏幕上。但在我们这么做之前先让我们看看我们得在main.mxml文件中做些什么改变。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
width="600"
height="400"
frameRate="100"
creationComplete="creationComplete()"
enterFrame="enterFrame(event)"
currentState="MainMenu">
<mx:states>
<mx:State
name="Game"
enterState="enterGame(event)"
exitState="exitGame(event)">
</mx:State>
<mx:State name="MainMenu">
<mx:AddChild relativeTo="{myCanvas}"position="lastChild">
<mx:Button x="525" y="368" label="Start" id="btnStart"
click="startGameClicked(event)"/>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:Canvas x="0" y="0" width="100%" height="100%" id="myCanvas"/>
<mx:Script>
<![CDATA[
protected var inGame:Boolean=false;
public function creationComplete():void
{
}
public function enterFrame(event:Event):void
{
if(inGame)
{
GameObjectManager.Instance.enterFrame();
myCanvas.graphics.clear();
myCanvas.graphics.beginBitmapFill
(GameObjectManager.Instance.backBuffer,null,false,false);
myCanvas.graphics.drawRect(0,0,this.width,this.height);
myCanvas.graphics.endFill();
}
}
public function startGameClicked(event:Event):void
{
currentState="Game"
}
protected function enterGame(event:Event):void
{
GameObjectManager.Instance.startup();
inGame=ture;
}
protected funciong exitGame(event:Event):void
{
GameObjectManager.Instance.shutdown();
inGame=false;
}
]]>
</mx:Script>
</mx:Application>
只在exitGame函数做了一个改变,该函数调用GameObjectManager的shutdown(关闭)函数。这将允许我们在离开游戏状态时GameObjectManager清除资源。现在让我们来看看在GameObjectManager中做的改变。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/literza/archive/2009/06/04/4241413.aspx
“使用FLEX开发游戏”系列之三
写自Matthew Casperson Casperson
2008年10月31日出版
在第三部分我们将增加一些图像资源并把它们显示在屏幕上
标签:Flex,Flash,tutorial,Actionscript,game
转到:第一部分
在写一个新程序的时候,总存在这么一个点,从这儿你可以看见你的劳动成果。通过实现状态和绘制的管道,我们现在可以开始做有趣的事情了,比如在游戏中添加图像,把它们显示在屏幕上。但在我们这么做之前先让我们看看我们得在main.mxml文件中做些什么改变。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
width="600"
height="400"
frameRate="100"
creationComplete="creationComplete()"
enterFrame="enterFrame(event)"
currentState="MainMenu">
<mx:states>
<mx:State
name="Game"
enterState="enterGame(event)"
exitState="exitGame(event)">
</mx:State>
<mx:State name="MainMenu">
<mx:AddChild relativeTo="{myCanvas}"position="lastChild">
<mx:Button x="525" y="368" label="Start" id="btnStart"
click="startGameClicked(event)"/>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:Canvas x="0" y="0" width="100%" height="100%" id="myCanvas"/>
<mx:Script>
<![CDATA[
protected var inGame:Boolean=false;
public function creationComplete():void
{
}
public function enterFrame(event:Event):void
{
if(inGame)
{
GameObjectManager.Instance.enterFrame();
myCanvas.graphics.clear();
myCanvas.graphics.beginBitmapFill
(GameObjectManager.Instance.backBuffer,null,false,false);
myCanvas.graphics.drawRect(0,0,this.width,this.height);
myCanvas.graphics.endFill();
}
}
public function startGameClicked(event:Event):void
{
currentState="Game"
}
protected function enterGame(event:Event):void
{
GameObjectManager.Instance.startup();
inGame=ture;
}
protected funciong exitGame(event:Event):void
{
GameObjectManager.Instance.shutdown();
inGame=false;
}
]]>
</mx:Script>
</mx:Application>
只在exitGame函数做了一个改变,该函数调用GameObjectManager的shutdown(关闭)函数。这将允许我们在离开游戏状态时GameObjectManager清除资源。现在让我们来看看在GameObjectManager中做的改变。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/literza/archive/2009/06/04/4241413.aspx
相关文章推荐
- [新闻资讯] 使用Flex和Actionscript开发Flash游戏——重复背景绘制
- 使用FLEX和 Actionscript 开发FLASH游戏(五)
- 使用FLEX和 Actionscript 开发FLASH游戏(六) -1
- 使用Flex和Actionscript开发Flash游戏——碰撞检测
- 使用FLEX和 Actionscript 开发FLASH游戏(六) -2
- [新闻资讯] 使用Flex和Actionscript开发Flash游戏——设定关卡
- 使用FLEX和 Actionscript 开发FLASH游戏(六) -3
- 使用FLEX和 Actionscript 开发FLASH游戏(六) -4
- 使用FLEX和 Actionscript 开发FLASH游戏(三)-3
- 使用FLEX和 Actionscript 开发FLASH游戏(六)-6
- 使用FLEX和 Actionscript 开发FLASH游戏(七)-1
- 使用FLEX和 Actionscript 开发FLASH游戏(三)-4
- 使用FLEX和 Actionscript 开发FLASH游戏(七)-2
- 使用FLEX和 Actionscript 开发FLASH游戏(七)-3
- 使用Flex和Actionscript开发Flash游戏 —— 双缓冲渲染
- 使用FLEX和 Actionscript 开发FLASH游戏(四)-2
- 使用FLEX 和 Actionscript开发FLASH 游戏—嵌入资源和增加游戏元素
- [转]深入浅出Flex组件生命周期Part1─ 使用ActionScript3开发Spark组件Component类
- 自定义Flex4+的Spark组件part1:使用ActionScript3开发Spark组件Component类
- 使用FLEX 和 Actionscript开发FLASH 游戏(一)