layer.cpp

来自「一个symbian上成熟的小游戏源码」· C++ 代码 · 共 96 行

CPP
96
字号

#include "Layer.h"


namespace gamespace
{

CLayer::CLayer()
{
	Init();
}

CLayer::~CLayer()
{
}

void CLayer::Init()
{
	iRows=0;
	iCols=0;
	iBmWidth=0;
	iBmHeight=0;
	iX=0;
	iY=0;
}

void CLayer::SetSource(CFbsBitmap* aBmp,CFbsBitmap* aBmpMask,TInt aCellWidth,TInt aCellHeight)
{
	iBmpMask=aBmpMask;
	iBmp=aBmp;

	iCellHeight=aCellHeight;
	iCellWidth=aCellWidth;
	
	TSize bmpSize = aBmp->SizeInPixels();

	iBmWidth = bmpSize.iWidth;
	iBmHeight = bmpSize.iHeight;

	if (iCellHeight==0)
	{
		iCellHeight=iBmHeight;
	}
	if (iCellWidth==0)
	{
		iCellWidth=iBmWidth;
	}

	
	iRows=iBmHeight / iCellHeight;
	iCols=iBmWidth / iCellWidth;
}
	
void CLayer::SetPosition(TInt aX,TInt aY)
{
	iX=aX;
	iY=aY;
}

void CLayer::SetPosition( const TPoint& aPoint )
{
	iX=aPoint.iX;
	iY=aPoint.iY;
}
void CLayer::Draw(TInt frameIndex,CBitmapContext& aGc) const
{
	//把Draw中需要的一些数据在SetSource中设置

	TInt row=(frameIndex) / iCols;//row行号,从0数
	TInt col=(frameIndex) % iCols;//从0数

	//cell在源图片中的坐标
	TInt srcX=col*iCellWidth;
	TInt srcY=row*iCellHeight;

	//iX,iY是cell在场景中的左上坐标,不是场景系

	CGraphicsTool::DrawImage(aGc,iBmp,iBmpMask,iX,iY,iCellWidth,iCellHeight,srcX,srcY);
}

TInt CLayer::CellWidth()
{
	return iCellWidth;
}

TInt CLayer::CellHeight()
{
	return iCellHeight;
}

TRect CLayer::CellRect()
{
	return TRect(iX,iY,iX+iCellWidth,iY+iCellHeight);
}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?