Read-only archive of the All About Symbian forum (2001–2013) · About this archive

Sprite animation (graphics example)

5 replies · 5,390 views · Started 27 January 2004

Hi All!

I have a problem.
I want to make a game just for fun.
I started with the graphics example from the Series60Ex directory.

I did not copypasted the whole code so it's possible I missed something but I don't thik so.

I made a small bitmap (17x17 (32bit)) and a same size BW mask for it.
If I use five sprites bouncing on the display with different speeds it runs OK.
However eight sprites just hangs the keyboard and over 10 sprites the system closes the App with an error message after about 20 sec.

If I remove the BitBltMasked row it works fine (with a static background. 😡 )

I tried to tune up the original example with 15 sprites. It works fine.
I tried to reduce the sprite size to 16x16 the same error occured.

What's wrong?
Any ideas?

Thanks,
Falco
www.snp.hu

Can you post your init code? You might not be allocating for enough objects and are just overwriting information for other varibles.

I don't think so.

I create objects in the ConstructL and after that I don't create more. I think if I won't allocate enough memory it will fail at the first cycle. But it runs about 20 seconds.

If I remove the BitBltMasked row it runs smoothly.
And this is only one line.

I think there's something stack overflow but I don't know why.

I thought the sprite technique works like on PC. In a PC assembly I put the sprite to the screen with a direct memory write. Nothing special just byte copy to a specified address. How is this on Symbian? Even I cannot access to the address so it can't be wrong.
Maybe the animation is too fast? 😃 I'll try to slow down.

However I'll upload the code tomorrow. Maybe you can find the bug.

Hi,

There is the code from my app.
This is in the Application's View.

Yesterday I tested to refresh at every second tick. And it's worked!
I think this is a memory management bug. After 5 minutes I closed the app manually.
Nothing else changed just the period delay in the MoveSprites method.

If anyone can find out something please tell me.

Thanks,
Falco


void AppView::ConstructL( const TRect& aRect )
{
CreateWindowL();
SetRect( aRect );

// Load in the bitmap images from the multi bitmap file
this->iBackgroundImage = CommonGraph::CreateBitmapL( KMultiBitmapFilename, 0 );
this->iSpriteImage = CommonGraph::CreateBitmapL( KMultiBitmapFilename, 1 );
this->iSpriteMask = CommonGraph::CreateBitmapL( KMultiBitmapFilename, 2 );

// Create the off screen bitmap and device / gc
this->iOffScreenBitmap = CommonGraph::CreateBitmapL( Rect().Size(),KColourDepth );
this->iOffScreenBitmapDevice = CommonGraph::CreateBitmapDeviceL( *this->iOffScreenBitmap );
this->iOffScreenBitmapGc = CommonGraph::CreateGraphicsContextL( *this->iOffScreenBitmapDevice );

this->iLines = new (ELeave) CArrayPtrFlat<CLine> ( LINE_COUNT );

this->iSprites = new (ELeave) CArrayPtrFlat<CSprite> ( SPRITE_COUNT );
for(TInt i = 0; i < SPRITE_COUNT; ++i)
{
CSprite* _sprite = CSprite::NewLC();
//Just dummy values
_sprite->SetXSpeed(2 + i);
_sprite->SetYSpeed(2 + i);
TInt xPos = i * 17;
//Check screen boundaries (176-17=159)
if(i >= 159)
xPos -= 159;
_sprite->Move( TPoint(xPos, i) );
this->iSprites->AppendL( _sprite );
CleanupStack::Pop( _sprite );
}

// Create a periodic timer but don't start it yet
this->iTimer = CPeriodic::NewL( CActive::EPriorityStandard );

ActivateL();
}

void AppView::StartAnim(void)
{
if( !this->iTimer->IsActive() )
this->iTimer->Start( 1, 1, TCallBack(AppView::TimerCallBack, this) );
}

TInt AppView::TimerCallBack( TAny *aPtr )
{
((AppView*)aPtr)->MoveSprites();

return TRUE;
}

void AppView::MoveSprites(void)
{
--(this->iPeriod);

if(this->iPeriod < 0)
{
//Filter ticks
//If you set this to 1, it works.
this->iPeriod = 0;

for(TInt i = 0; i < SPRITE_COUNT; ++i)
{
CSprite* _sprite = this->iSprites->At(i);
//Move sprite
TPoint iPos = _sprite->Position();

iPos.iY += _sprite->YSpeed();
if(iPos.iY <= 0)
_sprite->SetYSpeed( Abs(_sprite->YSpeed()) );
if(iPos.iY >= 191)
_sprite->SetYSpeed( -1 * Abs(_sprite->YSpeed()) );

iPos.iX += _sprite->XSpeed();
if(iPos.iX <= 0)
_sprite->SetXSpeed( Abs(_sprite->XSpeed()) );
if(iPos.iX >= 159)
_sprite->SetXSpeed( -1 * Abs(_sprite->XSpeed()) );

_sprite->Move( iPos );
}

//Update display
CWindowGc& gc = SystemGc();
gc.Activate(*DrawableWindow());
this->UpdateDisplay();
gc.Deactivate();
}
}

void AppView::UpdateDisplay() const
{
CWindowGc& gc = SystemGc();

// Blit the background image onto the off screen bitmap at the top left position
iOffScreenBitmapGc->BitBlt( TPoint(0,0), this->iBackgroundImage );

// Blit the sprites on top of it using its mask to retain the background where necessary
for(TInt i = 0; i < SPRITE_COUNT; ++i)
{
//I forgot to copy the CommonGraph.h 😞
//Just replace with the BitBltMasked command. It's the same
CommonGraph::BitBltMaskedEntireBitmap( *this->iOffScreenBitmapGc, this->iSprites->At(i)->Position(), *this->iSpriteImage, *this->iSpriteMask );
}

// Blit the offscreen image onto the screen at the top left position
gc.BitBlt( Rect().iTl, this->iOffScreenBitmap );
}


I hope I didn't forgot anything.

Hey guys!

I found the answer on Nokia Forum!

http://www.forum.nokia.com/main/1,,040,00.html?fsrParam=3-3-/main.html&fileID=3660

It's really interesting.
If I don't miss any tick the timer locks out some lower priority processes and that's why the app crashes. 😃 😃

citation:
3.2
Performance-Related Issues And The �ViewSrv 11� Problem
... Because the CGameTimer object tries to trigger game frames at a fixed rate (every 1/64 of a second on a target device), this slowness could cause a game to �lock out� lower-priority
background processes, starving them of execution time to the point where the operating system regards them as nonresponsive and shuts them down. RetroBlaster avoids this problem by dropping 1 render
frame in every 128, effectively freeing up a chunk of execution time for any such ultra-low-priority
process.

Funny thing. 😃 😃

Hello,
I am from Barcelona, Spain ...

When I try compile example RetroBlaster using CodeWarrior and SDK 2.0, I find that file AIF_xip.MBM not doesn�t exist and it�s necessary for compilation.

Can anybody help me, please?