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