Commit c72ca288 authored by Ian Wadham's avatar Ian Wadham

Ensure that all sprites have a size and a start frame before they are added to...

Ensure that all sprites have a size and a start frame before they are added to the scene: also that the lowest start frame is 1, not zero.

svn path=/branches/work/kgoldrunner-qgv/; revision=1312302
parent 1f91c7f4
......@@ -169,7 +169,7 @@ KGrSprite * KGrRenderer::getSpriteItem (const char picType, const int tickTime)
KGrSprite * sprite = new KGrSprite ((keyTable[index].picSource == Set) ?
m_setRenderer : m_actorsRenderer,
key, picType, tickTime);
m_scene->addItem (sprite);
// We cannot add the sprite to the scene yet: it needs a frame and size.
return sprite;
}
......
......@@ -30,8 +30,8 @@
const StartFrame animationStartFrames [nAnimationTypes] = {
RIGHTWALK1, LEFTWALK1, RIGHTCLIMB1, LEFTCLIMB1,
CLIMB1, CLIMB1, FALL1, FALL2,
(StartFrame) 0, // Calculate OPEN_BRICK frame later.
(StartFrame) 0}; // Calculate CLOSE_BRICK frame later.
DIGBRICK1, // Start frame for OPEN_BRICK.
DIGBRICK6}; // Start frame for CLOSE_BRICK.
KGrScene::KGrScene (KGrView * view)
:
......@@ -225,12 +225,7 @@ int KGrScene::makeSprite (const char type, int i, int j)
sprite->setZ (2);
break;
case BRICK:
/*
* TODO: Create a better way to set the starting frame for dug bricks,
* perhaps creating constants in kgrscene.h or improving the StarFrame
* enum and the animationStartFrames array.
*/
frame1 = 1;
frame1 = animationStartFrames [OPEN_BRICK];
// The hero and enemies must be painted in front of dug bricks.
sprite->setZ (0);
......@@ -242,9 +237,10 @@ int KGrScene::makeSprite (const char type, int i, int j)
break;
}
sprite->setFrame (frame1);
setTileSize (sprite, m_tileSize);
addItem (sprite); // The sprite can be correctly rendered now.
sprite->move (i, j, frame1);
return spriteId;
}
......@@ -292,17 +288,13 @@ void KGrScene::startAnimation (const int id, const bool repeating,
switch (type) {
case OPEN_BRICK:
nFrames = 5;
// See TODO defined in line 226.
frame = 1;
break;
case CLOSE_BRICK:
nFrames = 4;
// See TODO defined in line 226.
frame = 6;
break;
default:
// Show a standing hero or enemy, using the previous StartFrame.
nFrames = 0;
nFrames = 0;
break;
}
break;
......
......@@ -61,7 +61,7 @@ class KGrSprite;
class KGrRenderer;
class KGameRenderer;
enum StartFrame {RIGHTWALK1, RIGHTWALK2, RIGHTWALK3, RIGHTWALK4,
enum StartFrame {RIGHTWALK1 = 1, RIGHTWALK2, RIGHTWALK3, RIGHTWALK4,
RIGHTWALK5, RIGHTWALK6, RIGHTWALK7, RIGHTWALK8,
LEFTWALK1, LEFTWALK2, LEFTWALK3, LEFTWALK4,
LEFTWALK5, LEFTWALK6, LEFTWALK7, LEFTWALK8,
......@@ -70,7 +70,10 @@ enum StartFrame {RIGHTWALK1, RIGHTWALK2, RIGHTWALK3, RIGHTWALK4,
LEFTCLIMB1, LEFTCLIMB2, LEFTCLIMB3, LEFTCLIMB4,
LEFTCLIMB5, LEFTCLIMB6, LEFTCLIMB7, LEFTCLIMB8,
CLIMB1, CLIMB2,
FALL1, FALL2};
FALL1, FALL2,
DIGBRICK1 = 1, DIGBRICK2, DIGBRICK3, DIGBRICK4,
DIGBRICK5,
DIGBRICK6, DIGBRICK7, DIGBRICK8, DIGBRICK9};
class KGrScene : public QGraphicsScene
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment