Results 1 to 2 of 2

Thread: collision detection code written(help needed)

  1. #1
    Join Date
    Nov 2010
    Posts
    30
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default collision detection code written(help needed)

    Hi friends...I have applied some logic and written code for collision detction using qml...
    But Its not yet complete and im stuck and cant move further..so i need your help with this respect..below i m pasting my code..



    import Qt 4.7

    Rectangle {
    id: rect
    width: 650; height: 400
    color: "#d7d1d1"

    Image {
    id: image1
    property variant direction : "right"
    x: 51
    y: 30
    width: 100
    height: 100
    transformOrigin: "Center"
    z: 26
    rotation: -360
    scale: 1
    source: "qrc:/new/prefix1/2-Pound-Medicine-Ball.jpg"

    SequentialAnimation on x {
    loops: Animation.Infinite
    NumberAnimation { to: rect.width - 10; duration: 2000 }
    PropertyAction { target: image1; property: "direction"; value: "left" }
    NumberAnimation { to: 10; duration: 2000 }
    PropertyAction { target: image1; property: "direction"; value: "right" }

    }
    }
    Image {
    id: image2
    property variant direction : "right"

    x: 364
    y: 30
    width: 100
    height: 100
    source: "qrc:/new/prefix1/948709.jpg"

    }

    function collisiondetection(x1,x2,y1,y2)
    {
    if(image1.x1>image2.x1 && image1.y1>image2.y1)
    return
    }



    }


    so please help me out friends..


    regards
    Ranjit.Kadam

  2. #2
    Join Date
    Oct 2010
    Location
    Hyderabad, India
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: collision detection code written(help needed)

    Hi Ranjit,

    You are not calling your collision detection function anywhere in your code. you may perhaps use a timer to call this function at regular intervals.

    your collision detection function could be modified to:

    function bCollision(x1, y1, width1, height1,x2, y2, width2, height2) {
    return (x1 < x2 + width2) && (y1 < y2 + height2) && (x1 + width1 > x2) && (y1 + height1 > y2);
    }

    thanks,
    Sarvesh Saran

Similar Threads

  1. QGraphicsPixmapItem collision detection
    By sophister in forum Qt Programming
    Replies: 7
    Last Post: 4th July 2010, 19:36
  2. collision detection...
    By Muffin in forum Newbie
    Replies: 1
    Last Post: 8th January 2010, 10:28
  3. 2D Race Car collision detection
    By neonnds in forum Qt Programming
    Replies: 0
    Last Post: 6th July 2008, 08:10
  4. Painting and collision detection
    By aamer4yu in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2006, 08:57

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.