V
V
Vitaly2014-06-29 19:06:18
Qt
Vitaly, 2014-06-29 19:06:18

How to render an animated QGraphicsPixmapItem from a single shared picture placed outside the QGraphicsPixmapItem?

There is a QGraphicsPixmapItem. I made it animated by storing the original sprite inside it, and with each frame, QTimer switches the visible picture via setPixmap(), copying the part of the original sprite corresponding to the current frame there.
I had this question because, when the number of objects is more than 7000 and even 5000, the process of placing from the array to the stage becomes much longer, and while the animation of all objects is turned on, the overall performance slows down a lot, and why, it is already clear that every quarter of a second there is a recopying 10000 frames at the same time, which is extremely not optimal.
Is it possible, for example, through paint() to draw only one instance of an animated picture from an independent animator that animates one picture to all objects of its type on the stage?
(i.e. store in memory animation for each type of object (For example, cats, mice, rabbits ...) and the current frame is an element of the external array. All objects of the same type placed on the stage display exactly this picture, but inside it does not stored, and if it changes, it updates the rendering).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DancingOnWater, 2014-06-30
@Wohlstand

Going through paint is the right decision: the logic of the scene is such that any change causes a call to paint.
But I would go like this: standard containers store data in a separated way, and any calls to the copy operator or copy constructor only change the reference count.
I would inherit from QGraphicsObject (namely object), well, or QGraphicsitem And QGraphicsObject would create a method ala setAnimation ( const QList & value)
And in the overridden paint, make the painter draw the next picture through drawPixmap or drawPixmapFragments

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question