在做卡牌游戏的项目中,遇到了动画裁剪的问题。假如动画是一个圆形动画,在page1的页面中位置靠右,在page2中很可能会看到这个动画的另一半此时,就需要做动画做裁剪,在工程中有一个setScissorRect函数,可以对动画进行裁剪。

void play::PCBaseNode::setScissorRect(const CCRect & val )

{

scissorRect = val;

haveScissorRect = true;

scissorBoxRect = freshScissorBoxRect();

}

CCRect play::PCBaseNode::freshScissorBoxRect()

{

CCRect tempRect;

tempRect.origin = this->convertToWorldSpace(scissorRect.origin);

CCPoint sizeP = this->convertToWorldSpace(ccp(scissorRect.origin.x+scissorRect.size.width,scissorRect.origin.y+scissorRect.size.height));

tempRect.origin.x *= CC_CONTENT_SCALE_FACTOR();

tempRect.origin.y *= CC_CONTENT_SCALE_FACTOR();

tempRect.size.width = sizeP.x * CC_CONTENT_SCALE_FACTOR() – tempRect.origin.x;

tempRect.size.height = sizeP.y * CC_CONTENT_SCALE_FACTOR() – tempRect.origin.y;

/*

char buf[256];

sprintf(buf, “$$$node scissor: %.2f,%.2f;%.2f;%.2f”,tempRect.origin.x,tempRect.origin.y ,tempRect.size.width ,tempRect.size.height);

PCFileLogger* logger= AppInformation::getInstance()->getFileLogger(“debug”);

logger->emit(PC_LOG_DEBUG,buf);

CCLOG(buf);

*/

return tempRect;

}