方法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 
}

Logo

苏州本地的技术开发者社区,在这里可以交流本地的好吃好玩的,可以交流技术,可以交流招聘等等,没啥限制。

更多推荐