Nat Strangerweather
05/08/2021, 9:29 AMNat Strangerweather
05/08/2021, 9:30 AM@Composable
fun GameBoard() {
val coroutineScope = rememberCoroutineScope()
val offsetX = remember { Animatable(0f) }
val offsetY = remember { Animatable(0f) }
val tileModifier = Modifier
.offset {
IntOffset(
offsetX.value.roundToInt(),
offsetY.value.roundToInt()
)
}
.draggable(
state = rememberDraggableState { delta ->
coroutineScope.launch {
offsetX.snapTo(offsetX.value + delta)
}
},
orientation = Orientation.Horizontal,
onDragStarted = {},
onDragStopped = {
coroutineScope.launch {
offsetX.animateTo(
targetValue = 0f,
animationSpec = tween(
durationMillis = 1000,
delayMillis = 0
)
)
}
}
)
Box(
modifier = Modifier
.fillMaxWidth()
.aspectRatio(0.75f)
.padding(20.dp)
.background(Color.DarkGray)
.clipToBounds()
) {
CustomLayout {
for (i in 0..6) {
Tile(color = Color.Magenta, tileModifier)
}
for (i in 7..13) {
Tile(color = Color.Yellow, Modifier)
}
}
println(offsetX.value)
if (offsetX.value >= maxWidth of parent Box){
}
}
}
Erlan Amanatov
05/08/2021, 11:53 AMNat Strangerweather
05/08/2021, 12:06 PMAdam Powell
05/08/2021, 2:05 PMNat Strangerweather
05/08/2021, 2:11 PMAdam Powell
05/08/2021, 2:23 PM