Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ cocos2d-xv3c++;放置阴影cocos2d::Sprite_C++_Cocos2d X_Shadow - Fatal编程技术网

C++ cocos2d-xv3c++;放置阴影cocos2d::Sprite

C++ cocos2d-xv3c++;放置阴影cocos2d::Sprite,c++,cocos2d-x,shadow,C++,Cocos2d X,Shadow,据我所知,cocos并不像AS3那样提供简单的过滤器处理 我的情况: 我想给cocos2d::Sprite添加一个实时阴影 例如,我想这样做(类似于AS3): 这将为我的精灵添加阴影,以实现如下效果: 您能帮帮我吗?Cocos2D-X中的精灵上没有任何内置的阴影支持 最好的选择是,在性能方面,将阴影放置在sprite图像中,而不是在代码中计算和绘制阴影 另一个选项是子类Sprite并覆盖draw方法,以便复制Sprite并应用效果并将其绘制到原始效果下方 实现这一点的一种可能方法是使用中的这个

据我所知,cocos并不像AS3那样提供简单的过滤器处理

我的情况: 我想给cocos2d::Sprite添加一个实时阴影

例如,我想这样做(类似于AS3):

这将为我的精灵添加阴影,以实现如下效果:


您能帮帮我吗?

Cocos2D-X中的
精灵上没有任何内置的阴影支持

最好的选择是,在性能方面,将阴影放置在sprite图像中,而不是在代码中计算和绘制阴影

另一个选项是子类
Sprite
并覆盖
draw
方法,以便复制Sprite并应用效果并将其绘制到原始效果下方

实现这一点的一种可能方法是使用中的这个片段。我不能说我完全遵循了这段代码对GL变换所做的操作,但您可以将其作为实验的起点

void CMySprite::draw()
{
  // is_shadow is true if this sprite is to be considered like a shadow sprite, false otherwise.@
  if (is_shadow)
  {
    ccBlendFunc blend;
    // Change the default blending factors to this one.
    blend.src = GL_SRC_ALPHA;
    blend.dst = GL_ONE;
    setBlendFunc( blend );
    // Change the blending equation to thi in order to subtract from the values already written in the frame buffer
    // the ones of the sprite.
    glBlendEquationOES(GL_FUNC_REVERSE_SUBTRACT_OES);
  }

  CCSprite::draw();

  if (is_shadow)
  {
     // The default blending function of cocos2d-x is GL_FUNC_ADD.
    glBlendEquationOES(GL_FUNC_ADD_OES);        
  }
}

谢谢你。我去看看。
void CMySprite::draw()
{
  // is_shadow is true if this sprite is to be considered like a shadow sprite, false otherwise.@
  if (is_shadow)
  {
    ccBlendFunc blend;
    // Change the default blending factors to this one.
    blend.src = GL_SRC_ALPHA;
    blend.dst = GL_ONE;
    setBlendFunc( blend );
    // Change the blending equation to thi in order to subtract from the values already written in the frame buffer
    // the ones of the sprite.
    glBlendEquationOES(GL_FUNC_REVERSE_SUBTRACT_OES);
  }

  CCSprite::draw();

  if (is_shadow)
  {
     // The default blending function of cocos2d-x is GL_FUNC_ADD.
    glBlendEquationOES(GL_FUNC_ADD_OES);        
  }
}