I create two SolirRect
in random position and drag them on each other, but hitTestView()
always return null
val list = mutableListOf<View>()
fun box() = solidRect(width / 10, height / 10, randColor()) {
anchor(0.0, 0.0)
scale(1.0)
position(randPos())
var dragOffsetX = 0.0
var dragOffsetY = 0.0
addUpdater {
list.forEach {
if (this != it) {
println(
"Collision of ${list.indexOf(this)} " +
"with ${list.indexOf(it)} " +
"==> ${this.hitTestView(it, HitTestDirection.ANY) != null}")
}
}
}
onDown {
dragOffsetX = this.x
dragOffsetY = this.y
}
onMouseDrag {
this@solidRect.x = it.dx + dragOffsetX
this@solidRect.y = it.dy + dragOffsetY
}
}
repeat(2) {
box().let{
list.add(it)
if (list.indexOf(it) == 0) it.color = Colors.WHITE
}
}
Output:
Collision of 1 with 0 ==> false
Collision of 0 with 1 ==> false
Collision of 1 with 0 ==> false
Collision of 0 with 1 ==> false
Collision of 1 with 0 ==> false
Collision of 0 with 1 ==> false
Collision of 1 with 0 ==> false
And output is like this independent of rectangels intesect with each other or not.