How is it possible to make screen follow QGraphicsItem?
I am trying to make a game and I need that screen follows the player, is there any class I can call or something?
Printable View
How is it possible to make screen follow QGraphicsItem?
I am trying to make a game and I need that screen follows the player, is there any class I can call or something?
There are many QGraphicsView methods that control what part of the scene is displayed in the view:
QGraphicsView::centerOn()
QGraphicsView::ensureVisible()
QGraphicsView::fitInView()
QGraphicsView::setSceneRect(), etc.
One of these will probably do what you need.
I am trying to work with centerOn, but can't make it work :s..
My code looks like this and the centerOn is not doing anything.
Creating scene:
Code:
self.scene.setSceneRect(0, 0, 700, 700)
Creating rect, that player can control:
And in Players class init function I am trying to call:Code:
self.scene.addItem(self.item) self.newplayer = Player(color, self.starting, self.item, self.view)
Code:
self.view.centerOn(self.item)