[Qt-interest] Howto Do `hit Test' with QGraphicsItems ?
Sean Harmer
sean.harmer at maps-technology.com
Thu May 6 10:17:34 CEST 2010
Hi,
On Thursday 06 May 2010 08:55:14 Andre Somers wrote:
> On 6-5-2010 3:37, Aaron Lewis wrote:
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > On 05/05/2010 07:06 PM, Mihail Naydenov wrote:
> >> If you read the docs you will find you way around.
> >>
> >> Hints:
> >> QGraphicsItem::contains()
> >
> > So far it's not a easy way for me to check the Position of player
> > against other items , i'd do some research first.
> >
> >> QGraphicsItem::collidesWithItem()
> >
> > Cuz in my game , i've got lots of GraphicsItem , i don't need to check a
> > player Item with all of the rest , so i just play around with
> >
> > collidingItems() function , see if it hits any other item.
> >
> > e,g I've got walls around at the bound of map , buildings inside the map
> > , any NPC whatever , i don't want my player 'hit' them , so only tried
> > with collidingItems() , just check if it's higher than zero.
> >
> > Is that a good way for doing this ?
>
> Sounds ok to me. Do you run into issues if you check the
> collidingItems() method of the graphicsItem that represents your sprite?
>
> > It's not good to list all of the Item on a QGraphicsScene , and check
> > the player with it right ?
>
> No, it sounds silly to do that if the item provides a method to do it
> directly. Though it would not suprise me if collidingItems was
> implemented this way internally.
I think it is implemented using a BSP tree to reduce the number of comparisons
needed.
Sean
More information about the Qt-interest-old
mailing list