java - inputprocessor touch down gives late response? -
so busy kind of pong game android. have paddle , ball. controls player (the paddle) followed:
- if player touches on left side of screen, paddle goes left
- if player touches on right side of screen, paddle goes right
actually above 2 points work fine, bothers me, when im holding right right finger, , after release , fast holding left left finger, paddle executes 1 time "going left", , stops, while still holding left. (and vice versa)
i discovered happens if use 2 fingers. if im holding down right finger, , try go fast press other side, doesnt stop , keeps going left.
but important use 2 fingers, since way how game should played.
this may explained unclear, can ask in comments more specific questions.
player.java: http://pastebin.com/pdfzjtrb
myinputprocessor.java: http://pastebin.com/xpzi8jpb
i think problem resides in fact have touchdown boolean being shared between left , right sides. if press left side fast enough, touchdown left finger gets set true before touchdown right finger set false, making them false. try instead:
package com.nahrot.teleportball; import com.badlogic.gdx.gdx; import com.badlogic.gdx.inputprocessor; import com.badlogic.gdx.math.vector2; public class myinputprocessor implements inputprocessor { public vector2 lefttouchpos = new vector2(); public vector2 righttouchpos = new vector2(); public boolean touchleft = false; public boolean touchright = false; @override public boolean keydown(int keycode) { return false; } @override public boolean keyup(int keycode) { return false; } @override public boolean keytyped(char character) { return false; } @override public boolean touchdown(int screenx, int screeny, int pointer, int button) { if(sidetouched(screenx, true)) { touchleft = true; lefttouchpos.set(screenx, screeny); } if(sidetouched(screenx, false)) { touchright = true; righttouchpos.set(screenx, screeny); } return false; } @override public boolean touchup(int screenx, int screeny, int pointer, int button) { if(sidetouched(screenx, true)) { touchleft = false; } if(sidetouched(screenx, false)) { touchright = false; } return false; } @override public boolean touchdragged(int screenx, int screeny, int pointer) { return false; } @override public boolean mousemoved(int screenx, int screeny) { return false; } @override public boolean scrolled(int amount) { return false; } private boolean sidetouched(int x, boolean checkleft) { if(checkleft) { if(x <= gdx.graphics.getwidth() / 2) return true; } else { if(x > gdx.graphics.getwidth() /2) return true; } return false; } }
here, separated booleans , vectors left side , right side, , made convenience function checking whether touchdown or touchup on right or left side of screen, , adjusted corresponding booleans , vectors accordingly. assume vector needed check side pressed anyway, suspect work need 2 booleans sides touched. code untested, way, should idea if doesn't work.
Comments
Post a Comment