Cocos2d-js02_实现UI流程和场景跳转

Cocos2d-js02_实现UI流程和场景跳转

1、菜单场景代码:

/**
 * Created by chaoge on 15/6/19.
 */
var MenuLayer = cc.Layer.extend({
    sprite:null,
    helloLabel:null,
    size:null,
    ctor:function () {
        this._super();

        size = cc.winSize;

        //开始按钮
        var start = new cc.MenuItemImage(
            res.start,
            res.start,
            function () {
                cc.log("Menu is clicked!");
                cc.director.runScene(new GameScene());

            }, this);
        start.attr({
            x: size.width/2,
            y: size.height/2-120,
            anchorX: 0.5,
            anchorY: 0.5
        });

        //关于按钮
        var about = new cc.MenuItemImage(
            res.about,
            res.about,
            function () {
                cc.log("Menu is clicked!");
                cc.director.runScene(new AboutGame());

            }, this);
        about.attr({
            x: size.width/2,
            y: size.height/2-280,
            anchorX: 0.5,
            anchorY: 0.5
        });

        var menu = new cc.Menu(start,about);
        menu.x = 0;
        menu.y = 0;
        this.addChild(menu, 1);


        //滚动菜单
        helloLabel = new cc.LabelTTF("看谁最长", "Arial", 38);
        // position the label on the center of the screen
        helloLabel.x = size.width / 2;
        helloLabel.y = size.height-100;
        // add the label as a child to this layer
        this.addChild(helloLabel, 5);

        // add "HelloWorld" splash screen"
        this.sprite = new cc.Sprite(res.zhuye);
        this.sprite.attr({
            x: size.width / 2,
            y: size.height / 2
        });
        this.addChild(this.sprite, 0);

        this.schedule(this.LabelMove,0.2);
    },
    LabelMove : function(){
        helloLabel.setPositionX(helloLabel.getPositionX()-10);
        if(helloLabel.getPositionX() <= -50){
            helloLabel.setPositionX(size.width);
        }

    }
});
var MenuGame = cc.Scene.extend({
    onEnter:function () {
        this._super();
        var layer = new MenuLayer();
        this.addChild(layer);
    }
});
 

}

 

2、关于界面的代码,实现网页链接AboutScene.js:

var labjiumiao = new cc.LabelTTF("9秒课堂", "Arial", 38);
var ketang = new cc.MenuItemLabel(labjiumiao,function(){
    window.location.href = "http://www.9miaoketang.com";
});
ketang.setPosition(cc.p(size.width/2,size.height-200));

var h5kaifa = new cc.LabelTTF("COCOS2D-HTML5 游戏开发", "Arial", 38);
var H5 = new cc.MenuItemLabel(h5kaifa,function(){
    window.location.href = "http://h5.9miao.com";
});
H5.setPosition(cc.p(size.width/2,size.height/2));


var menu = new cc.Menu(ketang,H5);
menu.x = 0;
menu.y = 0;
this.addChild(menu, 1);

 



视频地址:http://www.9miaoketang.com/course/37

课程讨论帖地址:http://www.9miao.com/thread-64587-1-1.html

源码地址:https://store.cocos.com/stuff/show/128289.html

QQ交流群:83459374

后期也会把该源码传在群里面去,欢迎大家加入讨论!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值