佚名通过本文主要向大家介绍了clippingnode,cc.clippingnode,cocos clippingnode,遮罩,遮罩动画等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: 请教,ClippingNode遮罩在windows下运行正确,手机上没有遮挡效果
描述:
描述:
本帖最后由 cocos_01 于 2016-03-04 21:24:29 编辑
源代码如下,使用cocos3.2版本。哪位大神知道原因说下,多谢。。总的效果是一个圆球,水涨上升。采用圆缺逐渐减少遮住圆上半部分来达到效果。有两个动画里面一个是水面动画,一个是水下动画。水下动画覆盖整个圆。水面以上部分用自画圆缺遮住
if (fPercent >= 0)
{
Widget* pWidget = GetRootWidget();
Widget* pWidgetPetProg = Helper::seekWidgetByName(pWidget,"Image_PetProgress");
ui::ImageView* pLayoutPetProg = dynamic_cast<ui::ImageView*>(pWidgetPetProg);
if (NULL != pLayoutPetProg)
{
Vec2 ptCentre = pWidgetPetProg->getPosition();
float fRadio = 31;
float fHeight = fRadio * 2.0f * (1.0-fPercent);
if (NULL != m_pPetEnergyStencil)
{
m_pPetEnergyStencil->removeFromParent();
m_pPetEnergyStencil = NULL;
}
m_pPetEnergyStencil = ClippingNode::create();
if (NULL == m_pPetEnergyStencil)
{
ASSERT_DEBUG;
return;
}
m_pPetEnergyStencil->setInverted(true);
m_pPetEnergyStencil->setAlphaThreshold(0.05f);
addChild(m_pPetEnergyStencil,98);
spSkeletonData* pSkillSkeletonData = GetBattleScene()->getPreloadSkeletonByFilename(PET_ENERGY_FILE);
if (NULL == pSkillSkeletonData)
{
ASSERT_DEBUG;
return;
}
SkeletonAnimation* pPetEnergyCtrlBottom = SkeletonAnimation::createWithData(pSkillSkeletonData);
if (NULL == pPetEnergyCtrlBottom)
{
ASSERT_DEBUG;
return;
}
pPetEnergyCtrlBottom->setPosition(ptCentre);
m_pPetEnergyStencil->addChild(pPetEnergyCtrlBottom);
pPetEnergyCtrlBottom->setAnimation(0, PET_ENERGY_ANI_BOTTOM, true);
CircleSegment* pPetEnergyStencilSharp = CircleSegment::create();
if (NULL == pPetEnergyStencilSharp)
{
ASSERT_DEBUG;
return;
}
pPetEnergyStencilSharp->drawCircleSegment(ptCentre, fRadio, fHeight, 100, 1, Color4F(1,0,0,1), Color4F(1,0,0,1), CircleSegment::CSD_TOP);
m_pPetEnergyStencil->setStencil(pPetEnergyStencilSharp);
Vec2 ptCtrlTop = Vec2(ptCentre.x, ptCentre.y - fRadio + fRadio*2.0f * fPercent);
if (fPercent > 0.5)
fPercent = 1.0f - fPercent;
if (fPercent > 0)
{
if (NULL != m_pPetEnergyCtrlTop)
{
m_pPetEnergyCtrlTop->removeFromParent();
m_pPetEnergyCtrlTop = NULL;
}
m_pPetEnergyCtrlTop = SkeletonAnimation::createWithData(pSkillSkeletonData);
if (NULL == m_pPetEnergyCtrlTop)
{
ASSERT_DEBUG;
return;
}
addChild(m_pPetEnergyCtrlTop, 99);
m_pPetEnergyCtrlTop->setPosition(ptCtrlTop);
float fTopWidth = sqrt(pow(fRadio, 2.0f) - pow(fHeight-fRadio, 2.0f));
float fScale = fTopWidth/fRadio;
m_pPetEnergyCtrlTop->setScale(fScale);
m_pPetEnergyCtrlTop->setAnimation(0, PET_ENERGY_ANI_TOP, true);
}
}
}
else
{
ASSERT_DEBUG;
}
ClippingNode* m_pPetEnergyStencil;
SkeletonAnimation* m_pPetEnergyCtrlTop;
SkeletonAnimation* m_pPetEnergyFullEffect;
/** 画圆缺
@ ptCentre: 圆心
@ fRadio:半径
@ fCircleSegmentHeight: 圆缺高度
@ nSegmentCout:片段个数
@ fBorderWidth: 边框粗细
@ clrBorder: 边框颜色
@ clrFill: 圆缺填充色
@ csdDirection:圆缺起始位置点
*/
void CircleSegment::drawCircleSegment(Vec2 ptCentre, float fRadio, float fCircleSegmentHeight, int nSegmentCout, float fBorderWidth, Color4F clrBorder, Color4F clrFill, CSDirection csdDirection)
{
if (fRadio <= 0 || fCircleSegmentHeight > 2.0f*fRadio || nSegmentCout < 1)
{
ASSERT_DEBUG;
return;
}
float fPiece = fCircleSegmentHeight/(float)nSegmentCout;
Vec2* ptPoints = new Vec2[2*nSegmentCout+1];
Vec2* ptPointsPopy = ptPoints;
int j = 0;
for (int i = nSegmentCout; i > 0; i--)
{
float fDistanceX = sqrt(pow(fRadio, 2.0f) - pow(fRadio - fPiece*i, 2.0f));
if (CSD_BOTTOM == csdDirection)
{
ptPoints[j] = Vec2(ptCentre.x - fDistanceX, ptCentre.y - fRadio + fPiece*i);
ptPoints[2*nSegmentCout-j] = Vec2(ptCentre.x + fDistanceX, ptCentre.y - fRadio + fPiece*i);
}
else if (CSD_TOP == csdDirection)
{
ptPoints[j] = Vec2(ptCentre.x - fDistanceX, ptCentre.y + fRadio - fPiece*i);
ptPoints[2*nSegmentCout-j] = Vec2(ptCentre.x + fDistanceX, ptCentre.y + fRadio - fPiece*i);
}
j++;
}
if (CSD_BOTTOM == csdDirection)
{
ptPoints[nSegmentCout] = Vec2(ptCentre.x, ptCentre.y - fRadio);
}
else if (CSD_TOP == csdDirection)
{
ptPoints[nSegmentCout] = Vec2(ptCentre.x, ptCentre.y + fRadio);
}
// drawPolygon(ptPointsPopy, 2*nSegmentCout+1, clrFill, fBorderWidth, clrBorder);
drawSolidPoly(ptPointsPopy, 2*nSegmentCout+1, clrFill);
CC_SAFE_DELETE_ARRAY(ptPoints);
}