Latest

Archive

Community news

C++

Communities and Content

Databases

Editorials

Emacs

General

HTML

Java

Notices

PHP

XML

Apache

C++

Database

General

HTML

Java

Javascript

Linux

Object oriented programming

Open source

Perl

PHP

Python

Ruby

SOAP

XML

Suggest a link

Advertise on zez

Contribute

Contact us

About zez


Creating games with QCanvas



The Qt class QCanvas features optimized 2D graphics with game related functions, such as sprites and collision detection. This article describes how to use this in a small game.

Russian translation


You've got the whole world in your hands...

QCanvas background


The QCanvas class fits well for 2D games development, as it is optimized for speed and has some very useful features, like sprites (animated images), collision detection (essential in most 2D games), various built in shape classes and built in animation features.
To use it, you add a QCanvas to your application, and add a QCanvasView (a QWidget) to view the canvas. Then you can add QCanvasItems to the canvas. (The QCanvasView must be subclassed in order to interact with the canvas items.) We are going to demonstrate this in a small game.

The game


The game used in the demonstration is very simple, but strangely amusing: It consists of a 2D box and a ball. The ball can be picked up and tossed using the mouse, and will bounce back and forth against the walls of the box until air resistance, friction and gravity stops it, or you pick it up again. In order to make it all a bit more interesting, we use the box as an analogue of the universe, and the ball is, yup, that's correct: the Earth. (Some people might argue that there is no air resistance in space because there is no air, and that the force of gravity being directed downwards doesn't make any sense in space. These are usually the same kind of people that, when you comment on the birds happy singing on a nice spring day, will tell you that the song actually is an aggressive marking of territory. It's technically correct, but where's the fun in that?)

Attached files:


| < 1 > | 2 | 3 | 4 | 5 | 6 | Next page >> | Printer-friendly page |

Comment List


Topic: Author:
Time:
Very much Informative Riphat satti 29.08.2007 10:47

I think this is very useful exapme to learn about qcanvas..

each and every thing describe in full detail.
a layman can easily understand this example.


Bounce Canvas Demo Dr M 15.05.2005 05:57

Bounce is a very nicely written demo.
I wish QT would also distribute it
on their CD as an example on how to
write a QCanvas Application.

The example given in the QT book is
way too much for a newcomer.


Very usefull Arun Sivakumar 01.12.2001 17:18

The article featuring the QCanvas was really usefull and simple to understand. Hope you release more article covering various other features of Qt.

Please do inform if there are any other site with equally good articles on Qt.

Thank you
s_arunn@yahoo.com




Forgot your password?

Register a new user

Results

Polls