AIR移动(Starling)开发笔记基础篇

AIR移动(Starling)开发笔记基础篇

                                        ---------kiddy
                                        Ps:文档写的不是很好,欢迎指正和扩展

Starling相关

自定义移动动画

A.自定义函数
var tw:Tween = new Tween(_ball, 1, transFun);
Starling.juggler.add(tw);

private function transFun(pre:Number):void
{   //pre的范围[0-1],执行比列
        _ball.x = 100 + Math.sin(pre) * 300;
        _ball.y = 100 + Math.cos(pre) * 200;
}
B.自定义更新方法
var tw:Tween = new Tween(_ball, Number.MAX_VALUE);
tw.onUpdate = upDate;
Starling.juggler.add(tw);

private function upDate():void 
{
    .....
}
C.最后一种方法和前面的相识,也就相当于扩展Tween的功能。

比如说MyRotationTween之类的,详情请看如下代码:写的并不是很好,见谅!
Demo:

/**
 * @author kiddy
 * 创建时间:2014-1-20
 * 介绍:
 */
package game.view.general.player {  
    import starling.animation.Tween;
    import starling.core.Starling;
    import starling.display.Image;
    import starling.display.Sprite;

    public class MoveTween extends Sprite {
        private var _delay:Number;
        private var _image:Image;
        private var _onComFun:Function = null;
        private var _tween:Tween;

        public function MoveTween (delay:Number)
        {
            _delay = delay;

            _image= new Image(GameData.instance.getUITexture("coin"));
        }

        public function doAnimation(onCom:Function):void 
        {
            _onComFun = onCom;


            _tween = new Tween(_image, Number.MAX_VALUE, onUpDateMove);
            _tween.delay = _delay;
            _tween.onComplete = onComplete;
            _tween.onStart = onStart;       //动画开始时,才将显示对象显示

            Starling.juggler.add(_tween);
        }

        private function onStart():void {
            this.addChild(_image);
        }


        private function onUpDateMove(value:Number):void 
        {//跳出Tween的条件,并且调用动画结束      
            if (_image.x  >  600) {
                Starling.juggler.remove(_tween);
                this.onComplete();
            } else {
                _image.x += 1;
            }
        }

        private function onComplete():void 
        {
            this.dispose();

            if (_onComFun != null) {
                _onComFun();
            }
        }

        override public function dispose():void {
            this.removeChildren(0, -1, true);

            super.dispose();
        }
    }
}

查看网络连接情况

注:该种查看网络连接情况并不太可行,一般可以通过扩展ANE来实现
相关ANE 请查看ANE 扩展相关

/**
 * 检测网络连接情况
 * @param callFun
 */
public function getNetWorkInfo(callFun:Function):void
{
    monitor = new URLMonitor(new URLRequest("http://www.7k7k.com"));
    monitor.addEventListener(StatusEvent.STATUS, announceStatus);
    monitor.start();

    netCallFun = callFun;
}

private function announceStatus(e:StatusEvent):void 
{
    trace("Status change. Current status: " + monitor.available);

    if (netCallFun != null) {//回调
        netCallFun(monitor.available);
    }

    monitor.stop();
    monitor.removeEventListener(StatusEvent.STATUS, announceStatus);
    monitor = null;
    netCallFun = null;
}

分辨率适配方法

A.拉伸适配…
_starling.addEventListener(starling.events.Event.ROOT_CREATED, onRootCreated);

private function onRootCreated(e:starling.events.Event):void 
{
    var v:Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
    _starling.viewPort = v;
    _starling.stage.stageWidth = GameData.WIDTH;
    _starling.stage.stageHeight = GameData.HEIGHT;
}
B.留黑边……
private function onRootCreated(e:starling.events.Event):void
{
    var viewport:Rectangle = new Rectangle(0, 0, GameData.WIDTH, GameData.
                                                   HEIGHT);
    var aspect:Number = stage.stageWidth / stage.stageHeight;

    if (aspect > GameData.ASPECT_RATIO) {
        var moveX:Number = (stage.stageWidth - stage.stageHeight * GameData.
                    ASPECT_RATIO) / 2;

        viewport = new Rectangle(moveX, 0, stage.stageHeight * GameData.
                                         ASPECT_RATIO, stage.stageHeight);
    } else if (aspect < GameData.ASPECT_RATIO) {
        var moveY:Number = (stage.stageHeight - stage.stageWidth / GameData.
                    ASPECT_RATIO) / 2;

        viewport = new Rectangle(0, moveY, stage.stageWidth, stage.stageWidth /
                                         GameData.ASPECT_RATIO);
    } else {
        viewport = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
    }

    _starling.viewPort = viewport;
    //          _starling.stage.stageWidth = GameData.WIDTH;
    //          _starling.stage.stageHeight = GameData.HEIGHT;

自定义手机按键

注:只适合Android系统

if (isAndroid) { //如果是在安卓手机上,则监听按键和是否监听设备丢失
                NativeApplication.nativeApplication.addEventListener(KeyboardEvent.
                                                                KEY_DOWN, CheckKeypress);

    Starling.handleLostContext = true;
}

protected function CheckKeypress(event:KeyboardEvent):void {
    switch (event.keyCode) {
        case Keyboard.BACK:
            event.preventDefault();
            App.instance.ClickBack();
            break;
        case Keyboard.HOME:
            event.preventDefault();
            break;
        case Keyboard.SEARCH:
            event.preventDefault();
            break;
        case Keyboard.MENU:
            event.preventDefault();
            break;
        default:
            break;
    }
}

Starling滤镜

注:在Starling中,一个显示对象只能添加一种滤镜,滤镜需要慎用,消耗大量性能

var colorF:ColorMatrixFilter = new ColorMatrixFilter();
colorF.adjustSaturation(-1);    //变灰

var blurF:BlurFilter = new BlurFilter();//模糊
BlurFilter.createGlow();//发光滤镜
BlurFilter.createDropShadow(); //阴影 

禁止进入休闲模式

注:只适合Android系统
修改 **-app.xml中的节点

<android>   
            <manifestAdditions>
                <![CDATA[
                <manifest android:installLocation="auto">
                    <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
                    <uses-permission android:name="android.permission.WAKE_LOCK"/>
                </manifest>
            ]]>
            </manifestAdditions>
</android>

框架开发应用如何设置背景为透明

修改 **-app.xml中的节点

    <systemChrome>none</systemChrome>
    <transparent> true </transparent>

AIR移动应用图标尺寸(2013年)

Android: 24*24,32*32,36*36,48*48,72*72
iOS: 29*29,48*48,57*57,58*58,72*72,96*96,114*114,144*144,512*512
Android 上的图标

在 Android 上,应用程序描述符中指定的图标会用作应用程序 Launcher 图标。应用程序 Launcher 图标应作为 36x36、48x48、72x72 和 96x96 像素的 PNG 图像集来提供。这些图标尺寸分别用于低密度、中密度和高密度屏幕。

iOS 上的图标

在应用程序描述符中定义的图标用于 iOS 应用程序的以下位置:
29x29 像素图标 — 较低分辨率 iPhone/iPod 的 Spotlight 搜索图标和较低分辨率 iPad 的设置图标。
48x48 像素图标 — AIR 给该图像添加一个边框,且在较低分辨率 iPad 上将其用作一个 50x50 的 Spotlight 搜索图标。
50x50 像素图标 — 较低分辨率 iPad 的 Spotlight 搜索图标。
57x57 像素图标 — 较低分辨率 iPhone/iPod 的应用程序图标。
58x58 像素图标 — Retina 显示屏 iPhone/iPod 的 Spotlight 图标和 Retina 显示屏 iPad 的设置图标。
72x72 像素图标(可选)— 较低分辨率 iPad 的应用程序图标。
100x100 像素图标 — Retina 显示屏 iPad 的 Spotlight 搜索图标。
114x114 像素图标 — Retina 显示屏 iPhone/iPod 的应用程序图标。
144x144 像素图标 — Retina 显示屏 iPad 的应用程序图标。
512x512 像素图标 — 较低分辨率 iPhone/iPod/iPad 的应用程序图标。iTunes 显示此图标。当您将最终应用程序提交给 Apple 应用程序库时,512 像素 PNG 文件仅用于测试应用程序的开发版本,须单独以 JPG 文件格式提交 512 图像。它不包含在 IPA 中。
1024x1024 像素图标 — Retina 显示屏 iPhone/iPod/iPad 的应用程序图标。

Starling自带素材管理器

AssetMan = new AssetManager();
AssetMan.verbose = true;
//加载xml文件
AssetMan.enqueue("resource/config/player.xml");
//加载素材
AssetMan.enqueue("resource/bitmap/GameInfoUI.png");
AssetMan.enqueue("resource/bitmap/GameInfoUI.xml");
//加载字体
AssetMan.enqueue("resource/font/yellowfont.fnt");
AssetMan.enqueue("resource/font/yellowfont.png");
//加载声音
AssetMan.enqueue("resource/sound/click.mp3");
AssetMan.loadQueue(onLoadingConfig);

private function onLoadingConfig(value:Number):void {
    if (value < 1) {
        App.instance.loadInfo(value , "正在加载文件...");
    } else {
        _xml = AssetMan.getXml("player")

        _infoAtlas = AssetMan.getTextureAtlas("GameInfoUI");

        _sound =  AssetMan.getSound("click");

        _moneyTf = new TextField(GameData.WIDTH, 64, "0", "YellowFont", 40, 0xffffff);
    }
}

Starling嵌入ATF格式

[Embed(source="/../attchment/UI_Loading.atf",mimeType="application/octet-stream"))]
private static var LoadingUI_PNG:Class

[Embed(source = "/../attchment/UI_Loading.xml", mimeType = "application/octet-stream")]
private static var LoadingUI_XML:Class

private var _texAltas:TextureAtlas = null;
_texAltas = new TextureAtlas(starling.textures.Texture.fromAtfData(new LoadingUI_PNG()),    XML(new LoadingUI_XML()));
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值