Collision detect in QGraphicsScene
Hello,
I am using QGraphicsScene , QGraphicsView and QGraphicsPixmapItem to write a game like Tank.
I have wrote a class Tank inherriting from QGraphicsPixmapItem, and when I press some key, like Space, it's function shoot() is called. And I want to new some bullet in this function, then let the bullet go straight along the current direction.
The class Bullet is inherriting from QGraphicsPixmapItem too.
The problem is, I do not know how to detect whether the bullet reaches the border or hit the enemy tank, if it hits some enemy tank, how to destroy that tank.
I am using Qt4.5
Thanks in advance!!
Re: Collision detect in QGraphicsScene
Re: Collision detect in QGraphicsScene
You can also have a look at colliding mice example in Qt Demos under Graphics View section
Re: Collision detect in QGraphicsScene
Quote:
But, it seems there is no such event as far as I can see.
Even if there was such event, it would internally need to monitor items movement at regular intervals...
By the way in 4.6 theres also sub attack example...but I gues thats done using animation framework..dont know how collision detection is used in it..
may be u can check and let us know :)
Re: Collision detect in QGraphicsScene
The easiest way is to reimplement QGraphicsScene::advance(). It's called periodically (if you make it to be called of course) and you can easily detect collisions there, provided you have pointers to appropriate items.