Menu

1. Menu自适应显示 

moveMenu:function (delta) {
        var newY = this._itemMenu.y + delta.y;

        if (newY < 0)
            newY = 0;

        if (newY > ((DenshionTests.length + 1) * LINE_SPACE - winSize.height))
            newY = ((DenshionTests.length + 1) * LINE_SPACE - winSize.height);

        this._itemMenu.y = newY;
    }
2. 加入一系列菜单

 for (var i = 0; i < DenshionTests.length; i++) {
            var label = cc.LabelTTF.create(DenshionTests[i].title, "Arial", 24);
            var menuItem = cc.MenuItemLabel.create(label, this.onMenuCallback, this);
            this._itemMenu.addChild(menuItem, i + 10000);
            menuItem.x = winSize.width / 2;
            menuItem.y = winSize.height - (i + 1) * LINE_SPACE;
        }
        this._testCount = i;
        this._itemMenu.width = winSize.width;
	    this._itemMenu.height = (this._testCount + 1) * LINE_SPACE;
        this._itemMenu.x = 0;
        this._itemMenu.y = 0;
        this.addChild(this._itemMenu);
3. 加入监听

if( 'touches' in cc.sys.capabilities ) {
            cc.eventManager.addListener({
                event: cc.EventListener.TOUCH_ALL_AT_ONCE,
                onTouchesMoved: function (touches, event) {
                    event.getCurrentTarget().moveMenu(touches[0].getDelta());
                }
            }, this);
        } else if ('mouse' in cc.sys.capabilities )
             cc.eventManager.addListener({
                event: cc.EventListener.MOUSE,
                 onMouseMove: function(event){
                     event.getCurrentTarget().moveMenu(event.getDelta());
                 }
             }, this);


4. 回调

 onMenuCallback:function (sender) {
        var idx = sender.zIndex - 10000;
        // create the test scene and run it
        var scene = DenshionTests[idx].playFunc();
    },




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值