⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 layer.cpp

📁 一个symbian上成熟的小游戏源码
💻 CPP
字号:

#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -