starlingswf egret swf 怎么拿只元件

Starling外部资源管理 - CSDN博客
Starling外部资源管理
&?xml version="1.0" encoding="UTF-8"?&
&!-- Created with TexturePacker &
&!-- $TexturePacker:SmartUpdate:a9479bcf80444cacbc2cb7cb2411210b$ --&
&TextureAtlas imagePath="config_ui.png"&
&&&&&SubTexture name="0_num" x="1008" y="42" width="12" height="18" frameX="-10" frameY="-5" frameWidth="30" frameHeight="30"/&
&&&&&SubTexture name="1_num" x="1016" y="82" width="6" height="16" frameX="-12" frameY="-6" frameWidth="30" frameHeight="30"/&
&&&&&SubTexture name="1_panel" x="933" y="263" width="60" height="126" frameX="-55" frameY="-84" frameWidth="200" frameHeight="300"/&
&&&&&SubTexture name="2_num" x="1008" y="62" width="12" height="18" frameX="-10" frameY="-4" frameWidth="30" frameHeight="30"/&
&&&&&SubTexture name="2_panel" x="806" y="425" width="92" height="126" frameX="-52" frameY="-84" frameWidth="200" frameHeight="300"/&
&&&&&SubTexture name="3_num" x="1002" y="138" width="10" height="18" frameX="-10" frameY="-5" frameWidth="30" frameHeight="30"/&
&&&&&SubTexture name="3_panel" x="900" y="485" width="90" height="126" frameX="-52" frameY="-84" frameWidth="200" frameHeight="300"/&
&&&&&SubTexture name="4_num" x="1002" y="102" width="12" height="16" frameX="-10" frameY="-6" frameWidth="30" frameHeight="30"/&
&&&&&SubTexture name="5_num" x="1002" y="158" width="10" height="18" frameX="-11" frameY="-5" frameWidth="30" frameHeight="30"/&
&&&&&SubTexture name="6_num" x="1008" y="2" width="14" height="18" frameX="-8" frameY="-5" frameWidth="30" frameHeight="30"/&
&&&&&SubTexture name="7_num" x="1002" y="120" width="12" height="16" frameX="-10" frameY="-6" frameWidth="30" frameHeight="30"/&
&&&&&SubTexture name="8_num" x="1002" y="82" width="12" height="18" frameX="-10" frameY="-5" frameWidth="30" frameHeight="30"/&
&&&&&SubTexture name="9_num" x="1008" y="22" width="14" height="18" frameX="-8" frameY="-5" frameWidth="30" frameHeight="30"/&
&&&&&SubTexture name="aircraft_enemy_0" x="933" y="194" width="67" height="67"/&
&&&&&SubTexture name="aircraft_enemy_1" x="806" y="194" width="125" height="125"/&
&&&&&SubTexture name="aircraft_enemy_2" x="911" y="391" width="93" height="92"/&
&&&&&SubTexture name="aircraft_player" x="806" y="321" width="103" height="102"/&
&&&&&SubTexture name="and_btn" x="858" y="594" width="39" height="39"/&
&&&&&SubTexture name="back_btn" x="653" y="727" width="247" height="60" frameX="-5" frameY="-5" frameWidth="257" frameHeight="72"/&
&&&&&SubTexture name="blood" x="806" y="553" width="50" height="50"/&
&&&&&SubTexture name="blood_line" x="806" y="2" width="200" height="30"/&
&&&&&SubTexture name="blood_line_context" x="806" y="34" width="200" height="30"/&
&&&&&SubTexture name="change_missile" x="899" y="613" width="50" height="50"/&
&&&&&SubTexture name="get_skill" x="951" y="613" width="50" height="50"/&
&&&&&SubTexture name="go_panel" x="806" y="66" width="194" height="126" frameX="-4" frameY="-82" frameWidth="200" frameHeight="300"/&
&&&&&SubTexture name="help_back_ground" x="404" y="2" width="400" height="600"/&
&&&&&SubTexture name="help_game_btn" x="404" y="666" width="247" height="60" frameX="-5" frameY="-5" frameWidth="257" frameHeight="72"/&
&&&&&SubTexture name="invincible" x="653" y="604" width="50" height="50"/&
&&&&&SubTexture name="setting_back_ground" x="2" y="604" width="400" height="600"/&
&&&&&SubTexture name="setting_game_btn" x="653" y="665" width="247" height="60" frameX="-5" frameY="-5" frameWidth="257" frameHeight="72"/&
&&&&&SubTexture name="start_game_back_ground" x="2" y="2" width="400" height="600"/&
&&&&&SubTexture name="start_game_btn" x="404" y="604" width="247" height="60" frameX="-5" frameY="-5" frameWidth="257" frameHeight="72"/&
&&&&&SubTexture name="sub_btn" x="858" y="553" width="39" height="39"/&
&/TextureAtlas&
& & & 好了,到此位置,UI素材部分已经准备妥当,你需要在程序中编写你的代码来获取这些资源。那么在Starling中图片素材资源最终都会被处理为贴图资源,也就是Texture对象。但不幸的是starling.textures.Texture类只能处理一张位图图片,不能够处理sprite sheet类型的素材,此时你就需要使用到starling.textures.TextureAtlas这个类来进行制作,具体代码如下:
var textures:Texture = Texture.fromBitmapData( PublicData.texturesBitmapData );
&&&&&&&&&&&&PublicData.UI_TEXTURES_ATLAS = new TextureAtlas( textures, PublicData.texturesXML );
&&&&&&&&&&&&textures = null;
通过这样的操作后,你可以使用类似于下面的语句来方便的获取单独的贴图资源。
PublicData.UI_TEXTURES_ATLAS.getTexture("background");
注意,这里的"background"字符串来自于XML配置表中SubTexture节点的name属性。
& & & 通过这种方法,我们对现在的所有资源进行统一管理,并且能够很好的进行内存控制。当然,我不建议你将所有的资源全部放到一张图片中,你需要根据你的项目需要进行有效的分配管理。
& & & 下面则是使用Starling来制作位图字体。对于制作webgame的同学来说,在网页中使用个性化字体是非常纠结的事情,尤其中中文字体,我们不可能将一个30M+的字体文件打包到swf文件中让用户加载,对于国内的网速来说是非常不乐观的。使用问题字体你会有效的缓解这方面的压力。当然,对于中文还是无能为力。下面的图片是笔者用GlyphDesigner这款软件来制作的,不幸的是这方面的软件我目前找到了三款MAC系统的,而且质量都不错,对于windows平台还没有发现比较好的软件。图片和配置文件如下:
XML配置文件:
&&&&&info face="mebius" size="32" bold="0" italic="0" chasrset="" unicode="0" stretchH="100" smooth="1" aa="1" padding="0,0,0,0" spacing="2,2"/&
&&&&&common lineHeight="36" base="29" scaleW="128" scaleH="64" pages="1" packed="0"/&
&&&&&pages&
&&&&&&&&&page id="0" file="number text.png"/&
&&&&&/pages&
&&&&&chars count="11"&
&&&&&&&&&char id="57" x="2" y="3" width="20" height="28" xoffset="1" yoffset="4" xadvance="18" page="0" chnl="0" letter="9"/&
&&&&&&&&&char id="56" x="24" y="3" width="20" height="28" xoffset="1" yoffset="4" xadvance="18" page="0" chnl="0" letter="8"/&
&&&&&&&&&char id="54" x="46" y="3" width="20" height="28" xoffset="1" yoffset="4" xadvance="18" page="0" chnl="0" letter="6"/&
&&&&&&&&&char id="48" x="68" y="3" width="19" height="28" xoffset="1" yoffset="4" xadvance="18" page="0" chnl="0" letter="0"/&
&&&&&&&&&char id="51" x="89" y="3" width="19" height="28" xoffset="1" yoffset="4" xadvance="18" page="0" chnl="0" letter="3"/&
&&&&&&&&&char id="52" x="2" y="33" width="20" height="27" xoffset="0" yoffset="5" xadvance="18" page="0" chnl="0" letter="4"/&
&&&&&&&&&char id="53" x="24" y="33" width="20" height="27" xoffset="1" yoffset="5" xadvance="18" page="0" chnl="0" letter="5"/&
&&&&&&&&&char id="50" x="46" y="33" width="20" height="27" xoffset="1" yoffset="5" xadvance="18" page="0" chnl="0" letter="2"/&
&&&&&&&&&char id="55" x="68" y="33" width="20" height="27" xoffset="2" yoffset="5" xadvance="18" page="0" chnl="0" letter="7"/&
&&&&&&&&&char id="49" x="90" y="33" width="13" height="27" xoffset="3" yoffset="5" xadvance="18" page="0" chnl="0" letter="1"/&
&&&&&&&&&char id="32" x="105" y="33" width="0" height="0" xoffset="9" yoffset="49" xadvance="9" page="0" chnl="0" letter=" "/&
&&&&&/chars&
&&&&&kernings count="1"&
&&&&&&&&&kerning first="49" second="49" amount="-2"/&
&&&&&/kernings&
& & & 下面我们将使用Starling为我们提供的位图字体类来实现文图文本。
private function drawBitmapFont():void
&&&&&&&&&&&&var fontTexture:Texture = Texture.fromBitmapData( PublicData.numbertexturesBitmapData );
&&&&&&&&&&&&PublicData.BitmapFontToNumber = new BitmapFont(fontTexture, PublicData.numberXML);
&&&&&&&&&&&&TextField.registerBitmapFont( PublicData.BitmapFontToNumber );
& & & 在后面编写程序的时候,当你实例化一个TextField的时候只需要设置字体为mebius即可。这里你需要注意一个问题,你定义的字体名称千万不能可系统以后或者市面上已有的字体名称想冲突,否则在用户的及其中显示为系统字体样式。
& & & 最后我来介绍一个我自己编写的UI描述格式,这个格式非常的简单,我们只需要在面板中定义资源的id标签和位置即可。配置文件格式如下:
&&&&&scene name="start"&
&&&&&&&&&element type="image" name="startbg" texturesname="start_game_back_ground" x="0" y="0" /&
&&&&&&&&&element type="button" name="start_btn" texturesname="start_game_btn" x="0" y="300" /&
&&&&&&&&&element type="button" name="setting_btn" texturesname="setting_game_btn" x="0" y="390" /&
&&&&&&&&&element type="button" name="help_btn" texturesname="help_game_btn" x="0" y="480" /&
&&&&&/scene&
&&&&&scene name="setting"&
&&&&&&&&&element type="image" name="setting_bg" texturesname="setting_back_ground" x="0" y="0" /&
&&&&&&&&&element type="button" name="soundsub_btn" texturesname="sub_btn" x="50" y="100" /&
&&&&&&&&&element type="numtext" name="Volumetext" texturesname="" x="100" y="100" /&
&&&&&&&&&element type="button" name="soundand_btn" texturesname="and_btn" x="200" y="100" /&
&&&&&&&&&element type="button" name="quality_level_sub_btn" texturesname="sub_btn" x="50" y="200" /&
&&&&&&&&&element type="numtext" name="qualityleveltext" texturesname="" x="100" y="200" /&
&&&&&&&&&element type="button" name="quality_level_and_btn" texturesname="and_btn" x="200" y="200" /&
&&&&&&&&&element type="button" name="back_btn" texturesname="back_btn" x="0" y="300" /&
&&&&&/scene&
&&&&&scene name="help"&
&&&&&&&&&element type="image" name="helpbg" texturesname="help_back_ground" x="0" y="0" /&
&&&&&&&&&element type="button" name="back_btn" texturesname="back_btn" x="0" y="300" /&
&&&&&/scene&
& & & 这个描述文件中scene标签标识一个场景,里面的element标识一个UI空间,其中type用来分辨UI空间类型。请注意,这仅仅是一个前期模型的简单版本,并非最终版本。最后的数据格式会更加复杂,解析模块如下:
package ashan.res
&&&&import ashan.data.PublicD
&&&&import starling.display.DisplayO
&&&&import starling.display.DisplayObjectC
&&&&import starling.display.I
&&&&import starling.display.S
&&&&import starling.text.TextF
&&&&import starling.text.BitmapF
&&&&import starling.utils.C
&&&&public class SceneRead
&&&&&&&&&&
&&&&&&&&private var _mSceneV:Vector.&Sprite&;
&&&&&&&&private var _mSceneNameList:Vector.&String&;
&&&&&&&&&&
&&&&&&&&public function SceneRead()
&&&&&&&&&&&&init();
&&&&&&&&&&
&&&&&&&&private function init():void
&&&&&&&&&&&&this._mSceneV = new Vector.&Sprite&;
&&&&&&&&&&&&this._mSceneNameList = new Vector.&String&;
&&&&&&&&&&
&&&&&&&&public function getSceneByName(_name:String):Sprite
&&&&&&&&&&&&var _scene:S
&&&&&&&&&&&&var _isCreated:Boolean = false;
&&&&&&&&&&&&&&
&&&&&&&&&&&&var i:uint = 0;
&&&&&&&&&&&&var t:uint = this._mSceneNameList.
&&&&&&&&&&&&while( i & t )
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&if( this._mSceneNameList[i] == _name )
&&&&&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&&&&&_isCreated = true;
&&&&&&&&&&&&&&&&&&&&break;
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&else
&&&&&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&&&&&_isCreated = false;
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&i++;
&&&&&&&&&&&&}
&&&&&&&&&&&&&&
&&&&&&&&&&&&if( !_isCreated )
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&this.drawScene( _name );
&&&&&&&&&&&&}
&&&&&&&&&&&&&&
&&&&&&&&&&&&_scene = this._mSceneV[i];
&&&&&&&&&&&&return _
&&&&&&&&&&
&&&&&&&&private function drawScene(_name:String):void
&&&&&&&&{&&&
&&&&&&&&&&&&var _scene:Sprite = new Sprite();
&&&&&&&&&&&&var _xmlElement:XMLList = new XMLList( PublicData.sceneXML.scene.(@name == _name ) );
&&&&&&&&&&&&//
&&&&&&&&&&&&var i:uint = 0;
&&&&&&&&&&&&var t:uint = _xmlElement.element.length();
&&&&&&&&&&&&while( i & t )
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&var _element:DisplayObject = drawElement( new XMLList(_xmlElement.element[i]));
&&&&&&&&&&&&&&&&_scene.addChild( _element );
&&&&&&&&&&&&&&&&//
&&&&&&&&&&&&&&&&i++;
&&&&&&&&&&&&}
&&&&&&&&&&&&&&
&&&&&&&&&&&&this._mSceneV.push( _scene );
&&&&&&&&&&&&this._mSceneNameList.push( _name );
&&&&&&&&&&
&&&&&&&&private function drawElement(_xmllist:XMLList):DisplayObject
&&&&&&&&&&&&var _element:DisplayO
&&&&&&&&&&&&var type:String = _xmllist.@
&&&&&&&&&&&&var _texturesNameStr:String = _xmllist.@
&&&&&&&&&&&&switch( type )
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&case "image":
&&&&&&&&&&&&&&&&&&&&_element = new Image( PublicData.UI_TEXTURES_ATLAS.getTexture(_texturesNameStr) );
&&&&&&&&&&&&&&&&&&&&break;
&&&&&&&&&&&&&&&&case "button":
&&&&&&&&&&&&&&&&&&&&_element = new Image( PublicData.UI_TEXTURES_ATLAS.getTexture(_texturesNameStr) );
&&&&&&&&&&&&&&&&&&&&break;
&&&&&&&&&&&&&&&&case "numtext":
&&&&&&&&&&&&&&&&&&&&_element = new TextField(100,50,"0","mebius");
&&&&&&&&&&&&&&&&&&&&( _element as TextField ).fontName = "mebius";
&&&&&&&&&&&&&&&&&&&&( _element as TextField ).fontSize = BitmapFont.NATIVE_SIZE;
&&&&&&&&&&&&&&&&&&&&( _element as TextField ).color = Color.WHITE;
&&&&&&&&&&&&&&&&&&&&break;
&&&&&&&&&&&&}
&&&&&&&&&&&&_element.x = uint( _xmllist.@x );
&&&&&&&&&&&&_element.y = uint( _xmllist.@y );
&&&&&&&&&&&&_element.name = _xmllist.@
&&&&&&&&&&&&//
&&&&&&&&&&&&return _
& & & &我们通过这个SceneRead类来将XML数据转化为对象,并且方便我们的代码管理。最终我们来看一下如何实例化操作一个场景,并且为这个场景中的UI添加逻辑(这部分代码也是demo模型,后期会更加复杂)。
package ashan.scene
&&&&import ashan.data.PublicD
&&&&import ashan.events.SceneE
&&&&import ashan.res.SceneR
&&&&import flash.events.EventD
&&&&import starling.display.DisplayO
&&&&import starling.display.S
&&&&import starling.events.T
&&&&import starling.events.TouchE
&&&&import starling.events.TouchP
&&&&import starling.text.TextF
&&&&public class SettingScene extends EventDispatcher
&&&&&&&&private var _scene:S
&&&&&&&&private var _mSceneRead:SceneR
&&&&&&&&&&
&&&&&&&&public function SettingScene(_sceneRead:SceneRead)
&&&&&&&&&&&&this._mSceneRead = _sceneR
&&&&&&&&&&&&init();
&&&&&&&&&&
&&&&&&&&private function init():void
&&&&&&&&&&&&&&
&&&&&&&&&&&&//
&&&&&&&&&&&&this._scene = this._mSceneRead.getSceneByName(PublicData.SETTING_SCENE_NAME);
&&&&&&&&&&&&this._scene.getChildByName("back_btn").addEventListener(TouchEvent.TOUCH,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&back_btn_event);
&&&&&&&&&&&&this._scene.getChildByName("soundsub_btn").addEventListener(TouchEvent.TOUCH,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&sub_volume);
&&&&&&&&&&&&this._scene.getChildByName("soundand_btn").addEventListener(TouchEvent.TOUCH,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&and_volume);
&&&&&&&&&&&&this._scene.getChildByName("quality_level_sub_btn").addEventListener(TouchEvent.TOUCH,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&sub_quality);
&&&&&&&&&&&&this._scene.getChildByName("quality_level_and_btn").addEventListener(TouchEvent.TOUCH,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&and_quality);
&&&&&&&&&&&&//
&&&&&&&&&&&&var txt:TextField = this._scene.getChildByName("Volumetext") as TextF
&&&&&&&&&&&&txt.text = PublicData.Volume.toString();
&&&&&&&&&&&&var qtxt:TextField = this._scene.getChildByName("qualityleveltext") as TextF
&&&&&&&&&&&&qtxt.text = PublicData.QualityLevel.toString();
&&&&&&&&&&
&&&&&&&&private function sub_quality(evt:TouchEvent):void
&&&&&&&&&&&&var btn:DisplayObject = this._scene.getChildByName("quality_level_sub_btn");
&&&&&&&&&&&&var touch:Touch = evt.getTouch(btn, TouchPhase.BEGAN);
&&&&&&&&&&&&if (touch)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&if( PublicData.QualityLevel != PublicData.QualityLevel_MIN )
&&&&&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&&&&&PublicData.QualityLevel--;
&&&&&&&&&&&&&&&&&&&&var txt:TextField = this._scene.getChildByName("qualityleveltext") as TextF
&&&&&&&&&&&&&&&&&&&&txt.text = PublicData.QualityLevel.toString();
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&}
&&&&&&&&&&
&&&&&&&&private function and_quality(evt:TouchEvent):void
&&&&&&&&&&&&var btn:DisplayObject = this._scene.getChildByName("quality_level_and_btn");
&&&&&&&&&&&&var touch:Touch = evt.getTouch(btn, TouchPhase.BEGAN);
&&&&&&&&&&&&if (touch)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&if( PublicData.QualityLevel != PublicData.QualityLevel_MAX )
&&&&&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&&&&&PublicData.QualityLevel++;
&&&&&&&&&&&&&&&&&&&&var txt:TextField = this._scene.getChildByName("qualityleveltext") as TextF
&&&&&&&&&&&&&&&&&&&&txt.text = PublicData.QualityLevel.toString();
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&}
&&&&&&&&&&
&&&&&&&&private function sub_volume(evt:TouchEvent):void
&&&&&&&&&&&&var btn:DisplayObject = this._scene.getChildByName("soundsub_btn");
&&&&&&&&&&&&var touch:Touch = evt.getTouch(btn, TouchPhase.BEGAN);
&&&&&&&&&&&&if (touch)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&if( PublicData.Volume != PublicData.Volume_MIN )
&&&&&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&&&&&PublicData.Volume--;
&&&&&&&&&&&&&&&&&&&&var txt:TextField = this._scene.getChildByName("Volumetext") as TextF
&&&&&&&&&&&&&&&&&&&&txt.text = PublicData.Volume.toString();
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&}
&&&&&&&&&&&&&&
&&&&&&&&&&
&&&&&&&&private function and_volume(evt:TouchEvent):void
&&&&&&&&&&&&var btn:DisplayObject = this._scene.getChildByName("soundand_btn");
&&&&&&&&&&&&var touch:Touch = evt.getTouch(btn, TouchPhase.BEGAN);
&&&&&&&&&&&&if (touch)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&if( PublicData.Volume != PublicData.Volume_MAX )
&&&&&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&&&&&PublicData.Volume++;
&&&&&&&&&&&&&&&&&&&&var txt:TextField = this._scene.getChildByName("Volumetext") as TextF
&&&&&&&&&&&&&&&&&&&&txt.text = PublicData.Volume.toString();
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&}
&&&&&&&&&&&&&&
&&&&&&&&&&
&&&&&&&&private function back_btn_event(evt:TouchEvent):void
&&&&&&&&&&&&var btn:DisplayObject = this._scene.getChildByName("back_btn");
&&&&&&&&&&&&var touch:Touch = evt.getTouch(btn, TouchPhase.BEGAN);
&&&&&&&&&&&&if (touch)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&var evts:SceneEvent = new SceneEvent( SceneEvent.BACK_START_SCENE_WINDOWS );
&&&&&&&&&&&&&&&&this.dispatchEvent( evts );
&&&&&&&&&&&&}
&&&&&&&&&&
&&&&&&&&public function get scene():Sprite
&&&&&&&&&&&&return _
&&&&&&&&&&
&&&&&&&&&&
本文已收录于以下专栏:
相关文章推荐
目前在我们广电局中已经有了一套早期基于Access开发的20多万用户的信息管理系统,因一直很稳定,所以也没更换其它系统。里面目前有各种用户数据需要利用,譬如姓名、家庭住址、编号、联系电话等等。而在用V...
人力资源管理之二十个经典故事(下篇)
  父子两住山上,每天都要赶牛车下山卖柴。老父较有经验,坐镇驾车,山路崎岖,弯道特多,儿子眼神较好,总是在要转弯时提醒道:"爹,转弯啦!”
这应该是在大学做的最后一个开发项目。
刚刚经历的3S技术应用综合实习,分为三个模块,遥感实习,外业实习,GIS项目设计。时间长度达到11天。
这篇博文记录的主要是GIS项目设计的一些问题及关键步骤...
RAII是指C++语言中的一个惯用法(idiom),它是“ResourceAcquisitionIsInitialization”的首字母缩写。中文可将其翻译为“资源获取就是初始化”。虽然从某种程度上...
第一部分:招标邀请人力资源管理平台数据库项目公开进行招标,先邀请有意参加本次招标活动的投标人参与本项目。 1. 项目名称:人力资源管理平台数据库建设2. 投标须知:详见第二部分3. 项目时间:二个星期...
系统特点:
本系统是一个综合性的管理平台:既集成了技术信息的管理,又有用户信息、业务数据、工作任务的管理。既适合于技术人员进行管理维护,又适合与行政管理人员、财务人员以及业务人员的使用。贯穿了我...
信息资源管理讲述了信息资源如何从获取到转化为知识的过程,企业如何通过细化该过程提高资源利用率,为社会创造财富。...
笔者最近在用VS2015开发MFC项目时遇到一个纠结的问题,在进行界面编辑时发现VS报一个 “ error RC2104 :undefined keyWord or key name:WS_EX_CO...
Effective C++读书笔记
--By Nathan.Yu --
资源管理(之一)
常见的资源:文件描述器(file descriptors)、互斥锁(mutex...
Android如何加载第三方的资源,Resources与AssetManager获取资源的机制,本文教你如何快速了解...
他的最新文章
讲师:何宇健
讲师:董岩
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)starling教程-触摸事件(Touch Events) - CSDN博客
starling教程-触摸事件(Touch Events)
在前面提到过,Starling是Sparrow的姊妹篇,正因为这样,Starling里的touch事件的机制其实是为移动设备的触摸交互设计的,所以当你使用它进行使用鼠标交互的桌面应用开发时,第一眼会感觉有些困惑。
首先,如果你看一下starling的类结构图的话,你会发现starling和本地显示列表结构不同的地方在于它没有InteractiveObject类(InteractiveObject 类是用户可以使用鼠标和键盘与之交互的所有显示对象的抽象基类),所有的显示对象使用默认的交互,换句话说,在displayobject中定义了这些交互行为(starling其实从本地stage中注册事件,然后通过自己的结构将本地MouseEvent和TouchEvent结合成为它自己的独有的TouchEvent,这样开发桌面应用时,基本不用做什么修改就可以移植到移动平台了,大家知道的,现在平板电脑正在疯狂普及呐!)。
我们在前面已经用到过touch事件了。我们从最基本的东西开始,比如捕捉当鼠标触碰到quad时触发的事件。为了实现这点我们使用&TouchEvent.TOUCH事件:
1 // when the sprite is touched 2 _customSprite.addEventListener(TouchEvent.TOUCH, onTouchedSprite);
你会不会认为这是一个相当有限的功能?事实上它是非常强大的,因为你可以从这个单一的事件里得到许多不同的状态。每当鼠标或手指和图形对象发生交互时,TouchEvent.TOUCH就会被触发。
让我们在进一步看看下面的代码,我们在onTouch方法里trace了一下Touch对象的phase属性:
1 private function onTouch (e:TouchEvent):void
// get the mouse location related to the stage
var touch:Touch = e.getTouch(stage);
var pos:Point = touch.getLocation(stage);
trace ( touch.phase );
// store the mouse coordinates 10
_mouseY = pos.y; 11
_mouseX = pos.x; 12 }
当我们开始和一个quad交互直到点击了它,这个过程会触发不同的phase。下面是TouchPhase类中所有phase的常量属性:
began : A mouse or finger starts interacting (similar to a mouse down state). 2 o
ended : A mouse or finger stop interacting (similar to a native click state). 3 o
hover : A mouse or finger is hovering an object. (similar to a native mouse over state) 4 o
moved : A mouse or finger is moving an object (similar to a native
mouse down state + a mouse move state). 5 o
stationary : A mouse or finger stopped interactng with an object and stays over it.
我们再来看看TouchEvent类的其他一些常用的属性:
ctrlKey : A boolean returning the state of the ctrl key (down or not). 2 o
getTouch: Gets the first Touch object that originated over a certain target and are in a certain phase. 3 o
getTouches : Gets a set of Touch objects that originated over a certain target and are in a certain phase. 4 o
shiftKey: A boolean returning the state of the shift key (down or not). 5 o
timestamp : The time the event occurred (in seconds since application launch). 6 o
touches : All touches that are currently happening.
在使用键盘组合键的时候shiftKey和ctrlKey属性就非常有用了。综上,每当有交互发生不论是鼠标还是手指,都会有一个Touch事件相关联。
让我们来看看Touch类的pai:
clone : Clones the object.
getLocation: Converts the current location of a touch to the local coordinate system of a display object.
getPreviousLocation: Converts the previous location of a touch to the local coordinate system of a display
globalX: The x-position of the touch in screen coordinates.
globalY : The y-position of the touch in screen coordinates.
id: A unique id for the object.
phase : The current phase the touch is in.
previousGlobalX : The previous x-position of the touch in screen coordinates. 10 o
previousGlobalY : The previous y-position of the touch in screen coordinates 11 o
tapCount : The number of taps the finger made in a short amount of time. Use this to detect double-taps, etc. 12 o
target : The display object at which the touch occurred. 13 o
timestamp : The moment the event occurred (in seconds since application start). 14
模拟多点触摸
当进行移动设备的开发时,你会有很多时候想要使用多点触摸的交互操作,比如放大缩小图片。当你再台式电脑上进行开发时,手里没有移动设备,这时你就会需要使用到Starling内建的一个很好的模拟多点触摸的机制。
使用这个机制需要你将Starling类的simulateMultiTouch属性设置为true:
import flash.display.S
import flash.display.StageA
import flash.display.StageScaleM
import starling.core.S
[SWF(width=&1280&, height=&752&, frameRate=&60&, backgroundColor=&#002143&)]
public class Startup extends Sprite
private var mStarling:S
public function Startup()
// stats class for fps
addChild ( new Stats() );
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
// create our Starling instance
mStarling = new Starling(Game, stage);
// emulate multi-touch
mStarling.simulateMultitouch = true;
// set anti-aliasing (higher the better quality but slower performance)
mStarling.antiAliasing = 1;
// start it!
mStarling.start();
按照上面的代码进行设置之后,按住ctrl键,这时会出现两个小圆圈来模拟多点触摸,下面的插图说明了这一点:
在下面的代码中,我们将使用模拟多点触摸的小圆点来将一个quad进行形变,就像使用两个手指一样。
我们取出两个触摸点并计算它们之间的距离:
import flash.geom.P
import starling.display.S
import starling.events.E
import starling.events.T
import starling.events.TouchE
import starling.events.TouchP 10
public class Game extends Sprite 12
private var customSprite:CustomS 14
public function Game() 16
addEventListener(Event.ADDED_TO_STAGE, onAdded); 18
private function onAdded ( e:Event ):void 21
// create the custom sprite 23
customSprite = new CustomSprite(200, 200); 24
// positions it by default in the center of the stage 26
// we add half width because of the registration point of the custom sprite (middle) 27
customSprite.x = (stage.stageWidth - customSprite.width && 1 ) + (customSprite.width && 1); 28
customSprite.y = (stage.stageHeight - customSprite.height && 1) + (customSprite.height && 1); 29
// show it 31
addChild(customSprite); 32
// we listen to the mouse movement on the stage 34
//stage.addEventListener(TouchEvent.TOUCH, onTouch); 35
// need to comment this one ? ;) 36
stage.addEventListener(Event.ENTER_FRAME, onFrame); 37
// when the sprite is touched 38
customSprite.addEventListener(TouchEvent.TOUCH, onTouchedSprite); 39
private function onFrame (e:Event):void 42
// we update our custom sprite 44
customSprite.update(); 45
private function onTouchedSprite(e:TouchEvent):void 48
// retrieves the touch points 50
var touches:Vector.&Touch& = e. 51
// if two fingers 53
if ( touches.length == 2 ) 54
var finger1:Touch = touches[0]; 56
var finger2:Touch = touches[1]; 57
var distance: 59
var dx: 60
var dy: 61
// if both fingers moving (dragging) 63
if ( finger1.phase == TouchPhase.MOVED && finger2.phase == TouchPhase.MOVED ) 64
// calculate the distance between each axes 66
dx = Math.abs ( finger1.globalX - finger2.globalX ); 67
dy = Math.abs ( finger1.globalY - finger2.globalY ); 68
// calculate the distance 70
distance = Math.sqrt(dx*dx+dy*dy); 71
trace ( distance ); 73
本文已收录于以下专栏:
相关文章推荐
starling 笔记 :
基于Stage3Dg开发出来的一个可以使用GPU加速2D应用程序的框架。是一个渲染框架!
特色:直观,轻量,免费。
Starling与Sparro...
在项目中出现过当前问题本来以为在程序里面用事件截断处理就可以
在前面提到过,Starling是Sparrow的姊妹篇,正因为这样,Starling里的touch事件的机制其实是为移动设备的触摸交互设计的,所以当你使用它进行使用鼠标交互的桌面应用开发时,第一眼会感...
原文地址://741-using-touch-manipulation-events-to-translate-an-eleme...
一、touch触摸事件
在给定的触摸阶段,如果发生触摸事件,应用程序就会发送下列消息
//触屏开始
-(void)touchesBegan:(NSSet *)touches withEvent:(U...
触摸事件 Touch MotionEvent ACTION
MotionEvent简介
当用户触摸屏幕时,将创建一个MontionEvent对象,Motio...
在 jQuery Mobile 中有一些触摸事件是可定制的。然而,这些事件仅当与支持触摸功能的设备进行交互的用户访问您的 jQuery Mobile 网站时才可用。当这些事件可用时,您可以触发任何自定...
在项目中遇到了ScrollView 与内部的Gallery Touch事件的问题,学习了网上大侠们的研究成果,以及Android官网的文档,根据个人理解在此做个学习记录,也希望对大家有所帮助。
触摸事件的传递机制和与Touch相结合的实践学习
学习目标:
很长一段时间,一致对触摸事件似懂非懂,具体的事件传递机制都很清楚,但是对其应用实践却知道的不是很多,所以,今天特别地对触摸事件进行有...
他的最新文章
讲师:何宇健
讲师:董岩
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)}

我要回帖

更多关于 juliet starling 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信