Last active
December 12, 2017 06:48
-
-
Save Krishan14sharma/8c583adb40acac7fc009c221317d07ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val path = Path() | |
.. | |
override fun onDraw(canvas: Canvas) { | |
super.onDraw(canvas) | |
drawVerticalLines(canvas) | |
drawHorizontalLines(canvas) | |
drawSquareStates(canvas) | |
if (shouldAnimate) { <--------Check Here | |
canvas.drawPath(path, paint) // path is storing our line | |
} | |
if (touching) { | |
drawHighlightRectangle(canvas) | |
} | |
} | |
fun animateWin(x1: Int, y1: Int, x3: Int, y3: Int) { // will be called from activity or fragment | |
winCoordinates = arrayOf(x1, y1, x3, y3) // first and last coordinate of winning line | |
if (winCoordinates[0] < 0) return | |
val centerX = squares[winCoordinates[0]][winCoordinates[1]].exactCenterX() | |
val centerY = squares[winCoordinates[0]][winCoordinates[1]].exactCenterY() | |
val centerX2 = squares[winCoordinates[2]][winCoordinates[3]].exactCenterX() | |
val centerY2 = squares[winCoordinates[2]][winCoordinates[3]].exactCenterY() | |
path.reset() | |
path.moveTo(centerX, centerY) // moving to centre of first square | |
path.lineTo(centerX2, centerY2) // creating a line till centre of last square | |
shouldAnimate = true | |
invalidate(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment