PDA

View Full Version : Had a Conceptual doubts on QGraphicsItemAnimation ?



punitk
21st September 2010, 08:13
Hi,

I am implementing a small game. I am using QGraphicsItemAnimation class for this. I had a background for the game as a qgraphicsitem and a plane which is also a qgraphicsitem is moving slowly on it.
My requirement is that :

If i mouse press on the plane its speed should increase for example double of previous speed and i do something on this. And I had to repeat this for 10 times. So I am keeping my loop count as 10.

On Start of the every loop the plane should move slowly from left to right. It will move fast only when mouse is pressed on it else it moves with a normal speed.

I am able to move the plane with a normal speed for 10 times. But when I change the speed it on mouse pressed it moves fast for first mouse press ... Its behavior is non recognizable.

I am changing the speed by changing the time duration of the QTimeLine on the mouse pressed event to 2 secs.
Time duration for normal speed is 8 sec.

I have connected the framechange(int ) signal to slotFrameChanged(int) of object of the QTimeLine. There I am checking The end of the frame for each Loop. I had kept 72 frames for each loop. I always compare frame count in this slot to 72. If it is 72 I change the Time Duration back to 8 secs.

But This is not working...

If anyone can help ...
Please help.

Thanks & Regards
PunitK :(

wysota
21st September 2010, 08:44
I would rather use QTimer and QGraphicsScene::advance() than QGraphicsItemAnimation for this particular purpose. You will need some kind of a game loop anyway.

punitk
7th October 2010, 08:40
As I mention that My Background for the game is QGraphicsItem that is game is designed on QGraphicsItem , so that it can move on the scene and there is no any alternation on the game running on it. Is it Possible to use QTimer and QGraphicsScene::advance.

wysota
7th October 2010, 11:23
As I mention that My Background for the game is QGraphicsItem that is game is designed on QGraphicsItem , so that it can move on the scene and there is no any alternation on the game running on it.
I have no idea what this sentence means.

Is it Possible to use QTimer and QGraphicsScene::advance.
If the method is there then obviously you can use it.