📄 tiledlayer.cpp
字号:
#include "TiledLayer.h"
#include <libc\string.h>
namespace gamespace
{
CTiledLayer::CTiledLayer()
{
Init();
}
CTiledLayer::~CTiledLayer(void)
{
delete[] iPSequence;
}
void CTiledLayer::SetRange( TInt aSceneRows,TInt aSceneCols,TInt frameIndex)
{
iSceneCols=aSceneCols;
iSceneRows=aSceneRows;
//考虑保留旧的场景
delete[] iPSequence;
iPSequence=new TInt[iSceneCols*iSceneRows];
memset(iPSequence,0,iSceneCols*iSceneRows);
if (frameIndex>0)
{
FillCells(0,0,iSceneRows-1,iSceneCols-1,frameIndex);
}
}
void CTiledLayer::SetCell( TInt row,TInt col,TInt frameIndex )
{
TInt squenceIndex=row*iSceneCols+col;
iPSequence[squenceIndex]=frameIndex;
}
void CTiledLayer::FillCells( TInt beginrow,TInt begincol,TInt endrow,TInt endcol,TInt frameIndex )
{
/*
TInt squenceIndex1=beginrow*iSceneCols+begincol;
TInt squenceIndex2=endrow*iSceneCols+endcol;
while (squenceIndex1<=squenceIndex2)
{
iPSequence[squenceIndex1]=frameIndex;
squenceIndex1++;
}
*/
for (TInt r=beginrow;r<=endrow;r++)
{
for (TInt c=begincol;c<=endcol;c++)
{
SetCell(r,c,frameIndex);
}
}
}
void CTiledLayer::Draw(CBitmapContext& aGc)
{
TInt oldX=iX;
TInt oldY=iY;
for (TInt r=0;r<iSceneRows;r++)
{
for (TInt c=0;c<iSceneCols;c++)
{
TInt sequenceIndex=r*iSceneCols + c;
CLayer::Draw(iPSequence[sequenceIndex]-1,aGc);
iX += iCellWidth;//改变当前cell的坐标
}
iY += iCellHeight;//改变当前cell的坐标
iX = oldX;//改变当前cell的坐标
}
iX=oldX;//还原当前cell的坐标为场景左顶点坐标
iY=oldY;
}
void CTiledLayer::SetScence( TInt* aPSequence,TInt aSceneRows,TInt aSceneCols )
{
delete[] iPSequence;
iPSequence=new TInt[aSceneCols*aSceneRows];
memcpy(iPSequence,aPSequence,aSceneCols*aSceneRows*sizeof(TInt));
iSceneCols=aSceneCols;
iSceneRows=aSceneRows;
}
void CTiledLayer::Init()
{
iSceneCols=0;
iSceneRows=0;
iPSequence=new TInt[iSceneCols*iSceneRows];
//Sets buffers to a specified character.
memset(iPSequence,0,iSceneCols*iSceneRows);
}
TInt CTiledLayer::Cell( TInt aRow,TInt aCol )
{
TInt squenceIndex=aRow*iSceneCols+aCol;
return iPSequence[squenceIndex];
}
CTiledLayer* CTiledLayer::NewL( CFbsBitmap* aBmp,CFbsBitmap* aBmpMask,int aCellWidth/*=0*/,int aCellHeight/*=0*/ )
{
CTiledLayer* self=CTiledLayer::NewLC(aBmp,aBmpMask,aCellWidth,aCellHeight);
CleanupStack::Pop();
return self;
}
CTiledLayer* CTiledLayer::NewLC( CFbsBitmap* aBmp,CFbsBitmap* aBmpMask,int aCellWidth/*=0*/,int aCellHeight/*=0*/ )
{
CTiledLayer* self=new(ELeave)CTiledLayer;
CleanupStack::PushL(self);
self->ConstructL(aBmp,aBmpMask,aCellWidth,aCellHeight);
return self;
}
void CTiledLayer::ConstructL( CFbsBitmap* aBmp,CFbsBitmap* aBmpMask,int aCellWidth,int aCellHeight )
{
//设置父类
CLayer::SetSource(aBmp,aBmpMask,aCellWidth,aCellHeight);
}
TInt CTiledLayer::SceneRows()
{
return iSceneRows;
}
TInt CTiledLayer::SceneCols()
{
return iSceneCols;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -