Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. QtGraphicsView collision problem
Forum Update on Monday, May 27th 2025

QtGraphicsView collision problem

Scheduled Pinned Locked Moved Game Development
1 Posts 1 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andzero
    wrote on 9 Oct 2011, 09:05 last edited by
    #1

    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! :)

    1 Reply Last reply
    0

    1/1

    9 Oct 2011, 09:05

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved