麒麟子Cocos Creator 3D研究笔记八:3D坐标转2D&人物血条

夜深了,咱就直接进入正题吧,容麒麟子先上张图。

截自cc.d.ts

我们主要用到的就是这个CameraComponent中的converToUINode函数。它这个注释有点问题。

第一个参数 wpos:传入的是世界坐标点,比如人物头顶某个位置的世界坐标点

第二个参数 uiNode:传入的是你想要观察的UI节点的父节点,注意是父节点。不要问我为什么,因为传子节点不顶用。

第三个参数 out: 如果你需要获得位置,那么你传入一个自建的vec3变量,用于获取转换后的2d坐标点。

这篇 文章告诉大家两个事情

1、uiNode参数一定要是父节点。

2、我写好了一个血条组件给大家。


忍不住想吐槽一下,写这个API的人,是从laya挖过来的吗?3D转2D坐标,为什么要把uiNode传进去。为了效率吗?这是麒麟子第一见到有引擎的摄像机组件提供这样的转换API。


源码白嫖地址:https://gitee.com/qilinzi/qfw    下载下来后,在里面搜索TitleBar即可


如果觉得文章有帮助,请关注麒麟子,后面的文章更精彩。

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++){ this.mEggs[i].getComponent('Egg').setMove(true); } } stopMoveEggs(){ for(let i = 0; i < this.mEggs.length; i++){ this.mEggs[i].getComponent('Egg').setMove(false); } } }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值