PDA

View Full Version : collision detection code written(help needed)



ranjit.kadam
5th January 2011, 07:36
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

sarveshsaran
10th January 2011, 07:25
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