Important: Please read the Qt Code of Conduct -

How to write scrolling games with Qt Quick?

  • I want to write a Falldown clone that uses the accelerometer (as nicely done on iPhone, e.g. "": with Qt Quick (and maybe also Web Runtime) to learn about Qt Quick and Qt Mobility and see what the performance is like on my 5800 and N900 (when Qt 4.7 is available anyway).

    I've been looking at the docs and none of the animation stuff in Qt Quick seems to be what I want? Should I just be animating everything from JavaScript, or am I missing something?

    If I've got to do all the animation from JavaScript then what benefits do I get from Qt Quick over using the Web Runtime?

  • I would assume you would benefit from a physics library rather than simple animations with easing curves. E.g. Box2D should be really well suited to these kind of visuals. Check out Andreas' post at "labs": for a description of it. Further down in the comments you'll see thorbjørn's link to "qmlarcade(qmlarcade)":

    Hope this helps!

  • For a scrolling game, you'll probably need some C++. My initial thought is that you could write the main game canvas in C++, but use QML to style the falling ball. Then all the physics and calculations are done in code, but when you set the new coordinates on the ball you can use Behaviors and stuff to animate it nicely. And of course you can use QML for the menus and splash screen and stuff.

    You could do the whole thing in QML/JS, technically, by dynamically generating obstacles and doing the collision detection in JS. But that will probably be harder to write and slower to run.

    More generally, Qt Quick animations are for animating changes than for physics simulations, Henrik's post explains that well already.

  • For what it's worth, I'm working on a game for an N900 that uses QML for the visual aspects and C++ for the behind the scenes model. The game shows a map that the user can scroll (strategy game) and it's done using a Flickable that in turn contains one Item which contains up to thousands of hex items. Seems to run quite nicely on an N900, at least I was suprised. It takes some seconds to set up the QML scene, but once it's up and running all is perfectly playable.

    I use animations to provide some "life" to the UI, which mainly means sliding panels back and forth, not so much for explosions or similar animations (but I'll need that too later).

  • Thanks for all the replies.

    @Henrik - I saw qmlarcade, it's very much what I need only I'm not sure if I can live with the GPL if this is to go beyond my intial study. It seems Box2D is zlib licensed but Qt Tiled is the constraining factor. Might have to look at using one without the other. Also worth noting that Box2D is very much a floating point based physics library - not good for most of the devices currently out there (although N900 is fine).
    I understand Qt's graphics do quite a lot of floating point stuff in general though.

    @aalpert - I basically came to that conclusion but was posting here to check. The question is, does Nokia see a future for a physics engine in QML for simple 2D games, even if it isn't there now?

    @chakie - thanks for the real-life experience. I'm not surprised the N900 runs this OK, it's the contrast to the 5800 I'm interested in. When you factor in the graphics acceleration, the N900 has many multiples of the performance of the 5800.

  • [quote author="m_p_wilcox" date="1278942548"]

    @aalpert - I basically came to that conclusion but was posting here to check. The question is, does Nokia see a future for a physics engine in QML for simple 2D games, even if it isn't there now?


    I can't speak for Nokia, I just work here ;) . As for my tiny segment of Nokia, we don't have the resources to implement one ourselves.

    That said, I think a 2D physics and collisions engine for QML would be a veritable boon when creating 2D games. And it shouldn't be that hard to write either. You could just create a QDeclarativeExtensionPlugin with a QDeclarativeItem derived type. That type could do the physics calculations in C++ with other instances of the type, and presumably do them quite fast and efficiently. From there, you make your plugin module a QML module and use it to write your QML games with.

    It's a good thing that it's easy enough for anyone to do, because I don't have time to do it right now. But if you end up writing useful QML modules like that, I'm sure there's a place on the new DevNet for you to share them.

Log in to reply