PDA

View Full Version : translate and qgraphicsitem



pb
8th June 2009, 22:12
Hello -
I am writing a simple asteroids game and have a question about qgraphicsitems and the translate function. The app uses QGraphicsItems and QGraphicsScene and a timer that calls advance several times a second.

I'd like the asteroid to have it's 0,0 coordinate in the center of the asteroid. I'm using QGraphicsRectItem to create a square asteroid and calling the constructor with setRect (-40, -40, 80, 80). This works and I get what I want.

However, I should be able to create a rect with setRect (0,0,80,80) and then call QGraphicsItem::translate(-40, -40) to achieve the same thing. And no matter what I do, I can't get anything right. I've tried 40, 40 and -40, -40 and other combinations. I can't seem to find out what it's doing. Is the center being put in terms of scene coordinates? I'm wondering if I should be playing with mapfromscene or something like that.

Thanks,
Pat

aamer4yu
9th June 2009, 06:25
I'd like the asteroid to have it's 0,0 coordinate in the center of the asteroid. I'm using QGraphicsRectItem to create a square asteroid and calling the constructor with setRect (-40, -40, 80, 80). This works and I get what I want.
And thats how it works I guess... read more about the cordinate system in Qt Assistant.
If you want to provide (0,0,80,80) and be able to translate (-40,-40), you will need to provide your own methods I guess.