https://kotlinlang.org logo
#compose
Title
# compose
m

Mehmet Peker

01/19/2021, 2:33 AM
Hi everyone.Im coding simple snake game with jetpack compose.Im trying this code to detect swipe direction.But i cant detect Y axis everytime.What could be the problem?Anyone have any solutions or suggestions?Thank you
s

Siyamed

01/19/2021, 2:55 AM
I wonder if you return in those when statements
If so the code would be wrong
Also i wonder if you return the consumed (or was it remained?) gesture correctly
m

Mehmet Peker

01/19/2021, 3:49 AM
So what should I do?
c

Colton Idle

01/19/2021, 1:36 PM
@Mehmet Peker did you try breakpoints to see if they are getting hit?
m

Mehmet Peker

01/19/2021, 3:23 PM
I tried Log.d() for this.I can detect horizontal swipe everytime but i cant vertical swipe everytime.
s

Siyamed

01/19/2021, 3:50 PM
Mehmet, it would be good for you to share the final code.
m

Mehmet Peker

01/19/2021, 4:44 PM
Not a complicated,just that.When i swipe on Y axis sometimes not called onDrag callback
r

Rafs

01/19/2021, 4:50 PM
@Alexjlockwood did something similar in his 2048 game over here https://github.com/alexjlockwood/android-2048-compose/blob/master/app/src/main/java/com/alexjlockwood/twentyfortyeight/ui/SwipeDragObserver.kt It's about calculating the angle between the start and end points and mapping it to a direction
1
m

Mehmet Peker

01/19/2021, 5:18 PM
@Rafs thanks for your answer.It's definitely the code i wanted.
2 Views