[Kde-games-devel] KGameRenderer v. KGoldrunner: some problems
Stefan Majewsky
stefan.majewsky at googlemail.com
Wed May 23 18:51:47 UTC 2012
On Sun, May 20, 2012 at 7:25 AM, Ian Wadham <iandw.au at gmail.com> wrote:
> Re point 1, would it work to change "Set" to "FileName" in the .desktop
> files and have Actors as a custom attribute, then have a *second*
> (artificially constructed) KgTheme and a *second* KGameRenderer to
> provide the pixmaps for hero and enemies? Or would that mess up the
> cacheing?
I'd say, create two KgThemeProviders and map the theme selection of
the one provider to the other one by a signal-slot connection.
The theme files you can leave like they are now. Instead create two
KgTheme subclasses, with a reimplementation of readFromDesktopFile,
e.g.
bool KgrActorTheme::readFromDesktopFile(const QString& path) {
//base class call
if (!KgTheme::readFromDesktopFile(path))
return false;
//custom behavior: interpret "Actor" key as "FileName"
setGraphicsPath(customData("Actor"));
return true;
}
Remember to include Q_OBJECT in the definition of the KgTheme
subclasses, then give the optional QMetaObject parameter to
KgThemeProvider::discoverThemes to make sure that it picks up your
KgTheme subclasses (see documentation):
actorProvider->discoverThemes(..., ..., ...,
KgrActorTheme::staticMetaObject());
All this from the top of my head, but it should work. That's one of
the various customization hooks that KgTheme provides.
Re frameSuffix() and friends, they're indeed designed as unique per
KGameRenderer instance. If adjusting the theme is not an option for
you, you'll have to roll your own frame management. Frame management
in KGameRenderer is mostly syntactic sugar, because
setFrame(frame);
looks nicer than
setSpriteKey(QString("foobar-%1").arg(frame));
You can do the frame management on your own without problems. For
example, have a look at how frameCount() is implemented with
QSvgRenderer::elementExists()., Now QSvgRenderer::elementExists() is
equivalent to KGameRenderer::spriteExists() if you set the
frameBaseSuffix to a string that is never a valid suffix, e.g.
QString("FOOBARQUX").
(Fun fact: I remember a third-party user of KGameRenderer who had two
levels of frame counts, one for animation, and one to select multiple
equivalent sprites, e.g. eight sorts of grass texture).
Having said that, you can of course extend setFrameBaseSuffix() into
setFrameBaseSuffixes(), and then e.g. try all suffixes in frameCount()
when trying to find the next frame. (Okay, this could turn out quite
complicated, esp. given that KGameRenderer has no unit tests at the
moment.)
Greetings
Stefan
More information about the kde-games-devel
mailing list