|
|
发表于 2006-6-19 11:49:00
|
显示全部楼层
Re:2d滚屏游戏的精灵绘制???
你引擎中的Blit需要支持裁减功能
这是我引擎中的代码,写得烂,只说明可以这样做
//********根据源位图的长宽裁减一个矩形*******
//Width,Height:源位图的长宽
//pRect:源位图的矩形区域的指针,数据将会被修整
//返回值:如果矩形不存在了,说明不用绘制,返回false
//*******************************************
inline bool CheckSrcRect(int Width,int Height,RECT *pRect)
{
//超过下限
if( Height < pRect->bottom )
pRect->bottom = Height;
if( Height < pRect->top )
pRect->top = Height;
//超过右限
if( Width < pRect->right )
pRect->right = Width;
if( Width < pRect->left )
pRect->left = Width;
//超过上限
if( pRect->top < 0 )
pRect->top = 0;
if( pRect->bottom < 0 )
pRect->bottom = 0;
//超过左限
if( pRect->left < 0 )
pRect->left = 0;
if( pRect->right < 0 )
pRect->right = 0;
//如果矩形的面积为0了
if (pRect->left==pRect->right ||
pRect->top ==pRect->bottom)
return false;
return true;
}
//*****根据目标位图的长宽,以及起始位置和源位图的矩形区域来对矩形区域进行裁减*******
//x,y:目标位图中的起始位置的引用,可能会被此函数修改
//destW,destH:目标位图的长,宽
//pRect:源位图的矩形区域的指针,数据会被修整
//返回值:如果矩形不存在了,说明不用绘制,返回false
//**********************************************************************************
inline bool CheckDestRect(int &x,int &y,int destW,int destH,RECT *pRect)
{
if(x<0)
{//超出目标位图的左边
if((-x)>(pRect->right-pRect->left))
return false;//完全超出目标位图的左边
pRect->left=pRect->left-x;
x=0;
}
if(x>(destW-(pRect->right-pRect->left)) )
{
//超出目标位图的右边
if(x>destW)
return false;//完全超出目标位图的右边
else
pRect->right=destW+pRect->left-x-1;
}
if(y<0)
{//超出目标位图的上边
if((-y)>(pRect->bottom-pRect->top))
return false;//完全超出目标位图的上边
pRect->top=pRect->top-y;
y=0;
}
if(y>(destH-(pRect->bottom-pRect->top)) )
{//超出目标位图的底边
if(y>destH)
return false;//完全超出目标位图的底边
else
pRect->bottom=destH+pRect->top-y-1;
}
return true;
} |
|