Hi <everyone.Im> coding simple snake game with jet...
# compose
m
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
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
So what should I do?
c
@Mehmet Peker did you try breakpoints to see if they are getting hit?
m
I tried Log.d() for this.I can detect horizontal swipe everytime but i cant vertical swipe everytime.
s
Mehmet, it would be good for you to share the final code.
m
Not a complicated,just that.When i swipe on Y axis sometimes not called onDrag callback
r
@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
@Rafs thanks for your answer.It's definitely the code i wanted.