使用 cocos creator 完成的第一个游戏

Cocos create项目笔记(fly Bird)

第一次使用cocos creator 来编写游戏,这个算是我的第一个自己独立完成的游戏,虽然是模仿flappy bird这款游戏来写,不过过程很开心,下面是总结一下再编写游戏时用到的一些API.
(文章底部有游戏github地址)

添加音效
//创建一个 audioClip对象
    audio:{
        default:null,
        url:cc.AudioClip
    }

//播放音效
cc.audioEngine.play(this.audio,false,1);

audioEngine.play(path, false, 0.5);
- 参数1:音频文件的路径
- 参数2:音效是否循环
- 参数3:音量的大小(1为标准音量)

位置移动
var actionTo = cc.moveBy(2, cc.p(windowSize.width - 40, windowSize.height - 40));

cc.moveBy(2, cc.p(windowSize.width - 40, windowSize.height - 40))
- 参数1:持续时间
- 参数2:x轴移动的像素值
- 参数3:y轴移动的像素值

注:

cc.moveBy() 方法是移动节点的x,y的像素距离

cc.MoveTo() 方法是将节点移动到对应

cocos creator实现的推箱子游戏,含源码和功能;游戏一共有100关卡。 cc.Class({ extends: cc.Component, properties: { // foo: { // // ATTRIBUTES: // default: null, // The default value will be used only when the component attaching // // to a node for the first time // type: cc.SpriteFrame, // optional, default is typeof default // serializable: true, // optional, default is true // }, // bar: { // get () { // return this._bar; // }, // set (value) { // this._bar = value; // } // }, starImg : cc.Node, itemBg : cc.Node, levelTxt : cc.Node, }, // LIFE-CYCLE CALLBACKS: onLoad () { }, start () { }, //--------显示星星数量-------- /** * @description: 显示星星数量 * @param {boolean} isOpen 是否开启 * @param {starCount} 星星数量 * @param {cc.SpriteAtlas} levelImgAtlas 纹理图 * @param {number} level 关卡 * @return: */ showStar : function(isOpen, starCount, levelImgAtlas, level){ this.itemBg.attr({"_level_" : level}); if(isOpen){ this.itemBg.getComponent(cc.Sprite).spriteFrame = levelImgAtlas.getSpriteFrame("pass_bg"); this.starImg.active = true; this.starImg.getComponent(cc.Sprite).spriteFrame = levelImgAtlas.getSpriteFrame("point" + starCount); this.levelTxt.opacity = 255; this.itemBg.getComponent(cc.Button).interactable = true; }else{ this.itemBg.getComponent(cc.Sprite).spriteFrame = levelImgAtlas.getSpriteFrame("lock"); this.starImg.active = false; this.levelTxt.opacity = 125; this.itemBg.getComponent(cc.Button).interactable = false; } this.levelTxt.getComponent(cc.Label).string = level; }, /
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值