飞机界面设置

游戏的制作就是在于开始界面还有死亡界面,另外再加上界面上按钮的设置功能。

说的简单一些吧,游戏开始的界面上需要包括的是开始游戏按钮,按下开始游戏就会跳入界面开始游戏。

首先我们设置一张背景图

 var  sp = new cc.Sprite(res.pic_4)  //res.pic_4就是你的背景图
         this.setPosition(cc.winSize.width>>1,cc.winSize.height>>1)
         this.addChild(sp)```



```设置上方的开始按钮
     var menuFont = new cc.MenuItemFont("START GAME", this.startGame,this)
        menuFont.fontSize = 40 ;
        menuFont.fontName = "Arial";
        menuFont.setColor(cc.color(0,255,0,100))
        menuFont.setPosition(-cc.winSize.width>>1,-cc.winSize.height>>1)
        var menu = new cc.Menu(menuFont)
        this.addChild(menu);
    },
    startGame : function(){
        cc.director.pushScene(new cc.TransitionFlipAngular(1, new HelloWorldScene(),
            cc.color(0,255,255)));

    }, 




<div class="se-preview-section-delimiter"></div>

这里要注意的是,背景是重新建立的一个层,但是要显示在最前面,所以需要把这里设置成HelloWorldScene。在main里面的那里设置成这个类的名字,这样一点进去的时候就会显示这个开始界面。

接下来还可以设置游戏里面的背景,就是让背景动起来,这样会看起来有画面感一些,这里也需要照一张图片,然后用这一张变成两张来循环做到画面动的效果

 sp1:null,
        sp2:null,
        moveSpeed:10,
        ctor:function(res){
            this._super()
            this.sp1 = new cc.Sprite("res/beijing.png")
            this.sp2 = new cc.Sprite("res/beijing.png")
            this.addChild(this.sp1)
            this.addChild(this.sp2)
            this.sp1.setAnchorPoint(0,0)
            this.sp1.setPosition(0,0)
            this.sp2.setAnchorPoint(0,0)
            this.sp2.setPosition(0, this.sp2.height)
            this.scheduleUpdate()
        },
        update:function(){
            this.sp1.y-= this.moveSpeed
            this.sp2.y-= this.moveSpeed
            if(this.sp1.y< -this.sp1.height){
                this.sp1.y = this.sp2.y+this.sp2.height
            }
            if(this.sp2.y< -this.sp2.height){
                this.sp2.y = this.sp1.y+this.sp2.height
            }
        },




<div class="se-preview-section-delimiter"></div>

在游戏里面设置一个返回键,这个要添加到舞台的时候要注意层级,需添加到道具层级的上方

 var menuFont = new cc.MenuItemFont("BACK", this.startGame,this)
        menuFont.fontSize = 40  ;
        menuFont.fontName = "Arial";
        menuFont.setColor(0,255,0,100)
        menuFont.setPosition((cc.winSize.width>>1)-100,(cc.winSize.height>>1)-50)
        var menu = new cc.Menu(menuFont)
        this.addChild(menu);




<div class="se-preview-section-delimiter"></div>

游戏死亡界面的设置,这个层级也需要注意

var Lable_1 = new cc.LabelBMFont("GAME OVER",res.wenzi)
        Lable_1.fontSize = 40;
        Lable_1.setColor(0,255,0,100)
        Lable_1.setPosition(cc.winSize.width>>1,cc.winSize.height>>1)
        this.addChild(Lable_1)
        Lable_1.visible = false;
          this.over = cc.eventManager.addCustomListener(GAME_OVER,function(event){
            Lable_1.visible = true;
        })
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值