是否可以在画布上分离对象?

时间:2019-12-11 10:53:06

标签: android canvas android-canvas

我在Android Canvas中绘制了多个对象。现在,我想在我的应用程序中向下移动一个对象。我该怎么办?

fun touchStart(x: Float, y: Float) {
     mPath = Path()
     val fp = FingerPath(currentColor, emboss, blur, strokeWidth, 
     mPath!!)
    paths.add(fp)

    mPath!!.reset()
    mPath!!.moveTo(x, y)
    mX = x
    mY = y
 }

 fun touchMove(x: Float, y: Float) {
    val dx = Math.abs(x - mX)
    val dy = Math.abs(y - mY)

    if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
        mPath!!.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2)
        mX = x
        mY = y
    }
}

 fun touchUp() {
    println("mx " + mX + " my " + mY)
    mPath!!.lineTo(mX, mY)
}

override fun onTouchEvent(event: MotionEvent): Boolean {
    val x = event.x
    val y = event.y

    when (event.action) {
        MotionEvent.ACTION_DOWN -> {
            touchStart(x, y)
            invalidate()
        }
        MotionEvent.ACTION_MOVE -> {
            touchMove(x, y)
            invalidate()
        }
        MotionEvent.ACTION_UP -> {
            touchUp()
            invalidate()
        }
    }

    return true
  }

MotionEventUp 中,我要将单个对象移到屏幕下方。

这是我想要实现的目标image

0 个答案:

没有答案