java - Android Studio with Libgdx : Sound effect is not working properly on touch and touchdrag event -
i creating game has 2 specific methods control actor. method 1- jump, , method 2- jump_higher. , same sound play on action. handling input, using inputhandler class makes use of import com.badlogic.gdx.inputprocessor; , code follows:
import com.badlogic.gdx.inputprocessor; /*some other imports*/ public class inputhandler implements inputprocessor { /* variable declaration , constructor*/ @override public boolean touchdown(int screenx, int screeny, int pointer, int button){ actor.jump(); return true; } @override public boolean touchdragged(int screenx, int screeny, int pointer) { if (gdx.input.getdeltay() < -20) { actor.jump_higher(); } return true; }} and in actor class:
public class bird { /* variable declaration , constructor*/ public void jump() { if (isalive){ assetloader.jump.play(); velocity.y = -700; } } public void jump_higher() { if (isalive){ assetloader.jump.play(); velocity.y = -1050; } }} as touchdown action makes actor jump, , jump method playing sound. game running except sound on jump_higher event. on touchdragged event, sound isn't playing properly, sounds burrrrrrps (sorry not proper word). taking drag way input touchdown. want play sound once on each event. need regarding proper way implement touch event.
thank you.
you can use flag requirement :
boolean ishigherjump; and use flag inside jump_higher() method
public void jump_higher() { if (isalive){ if(!ishigherjump){ assetloader.jump.play(); ishigherjump=true; } velocity.y = -1050; } }} reset flag in touchup(..) method of inputprocessor
@override public boolean touchup(int screenx, int screeny, int pointer, int button) { actor.ishigherjump=false; return false; }
Comments
Post a Comment