游戏命令说明-小白快速入门

第一种:显示图片

在加载完成的处理,即onResourceLoadComplete中,通过检查当前加载完成的资源组名称,来做对应的处理。确认当前加载的资源组是heroes后,便进入程序的正式流程createGameScene中。

HTM代码为:

默认的default.res.json已经包含若干资源的配置:

 default.res.json:

{
    "groups": [
        {
            "keys": "bg_jpg,egret_icon_png,description_json,hui01_png,hui02_png",
            "name": "preload"
        }
    ],
    "resources": [
        {
            "name": "bg_jpg",
            "type": "image",
            "url": "assets/bg.jpg"
        },
        {
            "name": "egret_icon_png",
            "type": "image",
            "url": "assets/egret_icon.png"
        },
        {
            "name": "description_json",
            "type": "json",
            "url": "config/description.json"
        },
        {
            "name": "hui01_png",
            "type": "image",
            "url": "assets/hui01.png"
        },
        {
            "name": "hui02_png",
            "type": "image",
            "url": "assets/hui02.png"
        }
    ]
}

Main.ts:

private createGameScene() {
       let sky=this.createBitmapByName("bg_jpg");
       this.addChild(sky);
       let batman=this.createBitmapByName("hui01_png");
       batman.x=0;
       batman.y=20;
       this.addChild(batman);
       let captain=this.createBitmapByName("hui02_png");
       captain.x=50;
       captain.y=20;
       this.addChild(captain);

       console.log("display indexes:",this.getChildIndex(sky),this.getChildIndex(batman),this.getChildIndex(captain))

        //根据name关键字,异步获取一个json配置文件,name属性请参考resources/resource.json配置文件的内容。
        // Get asynchronously a json configuration file according to name keyword. As for the property of name please refer to the configuration file of resources/resource.json.
        //RES.getResAsync("description_json", this.startAnimation, this)
    }

显示深度控制

 

修改显示深度

 在createGameScene底部增加这一行:

this.setChildIndex(batman,this.getChildIndex(captain))

显示:

 

 

 

小白快速入门手册:http://edn.egret.com/cn/docs/page/639

posted @ 2017-11-02 16:13  chenguiya  阅读(239)  评论(0)    收藏  举报