Results 1 to 2 of 2

Thread: Collosion detection for QGraphicsPixmapItem objects. how?

  1. #1
    Join Date
    Jun 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Post Collosion detection for QGraphicsPixmapItem objects. how?

    hello eveyone

    I'm making a time trial platformer game in qt5.
    I'm trying to detect collosions between the instances of the Background class but it's not working.
    [through qDebug(), I found out that it's not even entering the for loop.]

    Background class is a subclass of the QGraphicsPixmapItem.
    all of the platforms that the player jumps on, are instances of the Background class.

    myscene is an instance of the Myscene class which is a subclass of the QGraphicsScene.
    m_player is an instance of the Player class which is a subclass of the QGraphicsPixmapItem.

    checkcollosion() is called every time scene gets updated.

    Qt Code:
    1. void Myscene::checkcollosion()
    2. {
    3. QList<QGraphicsItem*> items = collidingItems(m_player);
    4.  
    5. for (int i=0, number = items.count(); i<number; ++i)
    6. {
    7. if (Background *back = qgraphicsitem_cast<Background*>(items.at(i)))
    8. {
    9. }
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    I guess because Background is a subclass of QGraphicsPixmapItem, the collidingItems() doesn't work for it.
    and can qgraphicsitem_cast be used for casting QGraphicPixmapItem or is it only for QGraphicsItem ?

    so how can I fix this?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Collosion detection for QGraphicsPixmapItem objects. how?

    Quote Originally Posted by curiouscoding View Post
    I guess because Background is a subclass of QGraphicsPixmapItem, the collidingItems() doesn't work for it.
    Not sure why you mean it wouldn't work for pixmap items, they do have a shape.

    Quote Originally Posted by curiouscoding View Post
    and can qgraphicsitem_cast be used for casting QGraphicPixmapItem or is it only for QGraphicsItem ?
    A QGraphicsPixmapItem is a QGraphicsItem. So yes.

    Cheers,
    _

Similar Threads

  1. QGraphicsPixmapItem
    By erfan in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2012, 22:54
  2. QGraphicsPixmapItem collision detection
    By sophister in forum Qt Programming
    Replies: 7
    Last Post: 4th July 2010, 20:36
  3. Replies: 3
    Last Post: 9th January 2010, 16:47
  4. Mouse detection
    By eu.x in forum Newbie
    Replies: 3
    Last Post: 26th April 2007, 00:06
  5. Replies: 7
    Last Post: 18th July 2006, 22:33

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.