Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QtGraphicsView collision problem
andzero last edited by
Hello all! I'm glad to be in this forum.
Sorry if i posted in the wrong section. :S
I am still newbie to Qt ( just started learning few days ago. )
I have read the tutorials and docs, now i am currently trying to make a simple sidescrolling game using QGraphicsView,
for learning purposes.
What I have in mind is, I create a class derived from QGraphicsItem for the track. ( Track consists of QGraphicsItem objects )
@class Block: public QGraphicsItem
and I create another class, derived from QGraphicsItem too for the character that runs on top of the Block objects.
@class Character: public QGraphicsItem
This way, lets say the track consists of 50 Block class instances and they are constantly moving to the left ( x- - )
and destroyed once they are out of the QGraphicsView.
My question is about the physics. I want to add some obstacle to the track, for example add a gap between the Block instances
so the Character have to jump to avoid it. But i just can't understand how to, for example, make the Character 'freefall' down if it's not standing on top of a Block instances, or the Character gets pushed if there's a Block instances in front of him.
I thought I'd just make a collision detection function on Block class definition, using:
@virtual bool collidesWithItem ( const QGraphicsItem * other, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape ) const@
but the function needs QGraphicsItem * other parameter. So somehow i need to pass a pointer-to-Character object.
Am i in the right direction?
sorry for the newbie question,
thank you for your help! :)