还在观望?CocosCreator3D小案例《小鸭快跑》新鲜出炉!

摘要

CocosCreator 的 3D 版本正式上线!激动干嘛? 愣着啊! KUOKUO 正好手里有个小鸭子模型,于是就把它做成了一个小游戏。

正文

风骚的走位


系统事件来监听触摸

cc.systemEvent.on(SystemEventType.TOUCH_START, (e: EventTouch) => {
    let pos = e.getLocation();
    // ......
});
cc.systemEvent.on(SystemEventType.TOUCH_END, (e: EventTouch) => {
    let pos = e.getLocation();
    if (this.startPos.x > pos.x) {
        console.log('左');
        // ......
    } else {
        console.log('右');
        // ......
    }
});

编辑器界面

灯光打在路面上很是丝滑

层级关系与UI布局

模型阴影

脚底生风

使用了 3D 粒子组件
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-wo7XNrKj-1571229549697)(http://cdn.kuokuo666.com/20191016/foot.png)]

死亡界面

代码相关

原来习惯 CocosCreator 的伙伴们注意下,不用打 cc 了。
比如实例化预制体代码

createOneEnemy () {
    let n1 = Math.floor(3 * Math.random());
    let x = -150 + n1 * 150;
    let y = 0;
    let z = 5000;
    let e = instantiate(this.enemy);
    this.node.addChild(e);
    e.setPosition(cc.v3(x, y, z));
}

结语

体验很棒,期待国产引擎称霸的那一天!

(*^▽^*)

工程源码在我的微信公众号回复关键词【小鸭快跑】即可获得

O(∩_∩)O~~

微信公众号

O(∩_∩)O~~

微信公众号

[外链图片转存中…(img-5WjcpcR9-1571229549698)]

相关推荐
Cocos Creator模拟砸金蛋3d旋转效果 | 附代码egg.zip // Learn TypeScript: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html // Learn Attribute: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html const {ccclass, property} = cc._decorator; @ccclass export default class Game extends cc.Component { @property Count: number = 5; @property(cc.Prefab) prefab: cc.Prefab = null; @property(cc.Node) nodeParent: cc.Node = null; private mEggs: cc.Node[] = []; // LIFE-CYCLE CALLBACKS: // onLoad () {} start () { } // update (dt) {} onClick(event, data){ switch(data){ case 'add':{ this.addEggs(); break; } case 'move':{ this.moveEggs(); break; } case 'stop':{ this.stopMoveEggs(); break; } } } addEggs(){ if(this.Count <= 0){ return; } this.mEggs = []; const N = 360 / this.Count; for(let i = 0; i < this.Count; i++){ let egg = cc.instantiate(this.prefab); let js = egg.getComponent('Egg'); js.setRadian(i * N * Math.PI / 180); js.updatePos(); egg.parent = this.nodeParent; this.mEggs.push(egg); } } moveEggs(){ for(let i = 0; i < this.mEggs.length; i++){
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页