cocoscreator制作鱼的阴影

方法1:

常用的简单方案是使用材质,effect里输出颜色为黑色与调整下透明度就可以实现,由于使用了shader,会打断drawcall,这样我们就很难达到批渲染了,也就没法对游戏做进一步的优化了

方法2:

(1)这里介绍的是另一种解决方案,思路是在鱼身上添加一个节点,节点添加sprite,然后在update函数里重置下新节点的图片(spriteFrame)

(2)图片是有了,那怎么显示阴影,这个很简单,只要把节点颜色调成黑色,在调下透明度和位置就可以了

initShadom() {
    this.shadow = new cc.Node()
    this.shadow.color = new cc.Color(0, 0, 0)
    this.shadow.opacity = 100
    this.shadom.parent = this.node
}
update(dt) {
    let sp : cc.Sprite = this.shadow.getComponent(cc.Sprite)
    let fishSp : cc.Sprite = this.node.getComponent(cc.Sprite)
    sp.spriteFrame = fishSp.spriteFrame
       
    // 动态调整位置,这里比较简单,好一点的可以做成沿一个方向下的投影
    this.shadom.x = this.node.x + 10
    this.shadom.y = this.node.y - 10 
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值