안녕하세요 저는 "가상 드럼 키트"를 만드는 앱에 문제가 있습니다. libgdx로 환상적이지는 않겠지 만 솔직하게 "무엇을 가르쳤습니까? 나는 더 이상 접촉하지 않는 누군가에 의해 "알 필요가있었습니다.libgdx 및 android를 통해 여러 프레스 추적
앱이 모두 실행되어 멋지지만 Android 기기에서 사용할 때 두 개의 드럼/심벌을 동시에 칠 수 없으며 동시에 드럼의 소리가 반복됩니다. 아마 언론을 추적하는 데 가장 좋은 방법을 사용하지는 않지만 libgdx에 익숙하지 않다고 말했듯이 내가 코드를 붙여 넣으면 사람들로부터 도움이나 조언을 얻는 것이 좋을 것입니다!
package gamebulk.drumkit;
import java.util.Random;
import gamebulk.drumkit.DrumKit.DialogListener;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GLCommon;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;
public class DrumScreen implements Screen, ApplicationListener {
Game game;
OrthographicCamera guiCam;
SpriteBatch batcher;
Rectangle snareBounds;
Rectangle hihatBounds;
Rectangle crashBounds;
Rectangle rideBounds;
Rectangle bassBounds;
Rectangle hitBounds;
Rectangle lowtBounds;
Rectangle floortBounds;
Rectangle exitBounds;
Vector3 touchPoint;
DialogListener callback;
float time = 0;
public final Random rand;
public DrumScreen (Game game, DialogListener callback) {
this.game = game;
guiCam = new OrthographicCamera(800, 480);
guiCam.position.set(800/2, 480/2, 0);
batcher = new SpriteBatch();
snareBounds = new Rectangle (180, 150, 147, 80);
hihatBounds = new Rectangle (28, 184, 160, 90);
crashBounds = new Rectangle(36, 310, 246, 160);
rideBounds = new Rectangle (550, 250, 222, 140);
bassBounds = new Rectangle (278, 38, 250, 211);
hitBounds = new Rectangle (256, 242, 132, 96);
lowtBounds = new Rectangle (410, 240, 130, 92);
floortBounds = new Rectangle (494, 128, 178, 118);
exitBounds = new Rectangle (704, 384, 64, 64);
touchPoint = new Vector3();
this.callback = callback;
Gdx.input.setCatchBackKey(true);
rand = new Random();
}
public void update (float deltaTime) {
handleInput(deltaTime);
if (Gdx.input.justTouched()) {
guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
if (OverlapTester.pointInRectangle(snareBounds, touchPoint.x, touchPoint.y)) {
if (rand.nextFloat() < 0.5){
Assets.playSound(Assets.snare1sound);}
else{
Assets.playSound(Assets.snare2sound);
}
}
if (OverlapTester.pointInRectangle(hihatBounds, touchPoint.x, touchPoint.y)) {
if (rand.nextFloat() < 0.5){
Assets.playSound(Assets.hihat1sound);}
else{
Assets.playSound(Assets.hihat2sound);
}
}
if (OverlapTester.pointInRectangle(crashBounds, touchPoint.x, touchPoint.y)) {
if (rand.nextFloat() < 0.5){
Assets.playSound(Assets.crash1sound);}
else{
Assets.playSound(Assets.crash1sound);
}
}
if (OverlapTester.pointInRectangle(rideBounds, touchPoint.x, touchPoint.y)) {
if (rand.nextFloat() < 0.5){
Assets.playSound(Assets.ride1sound);}
else{
Assets.playSound(Assets.ride2sound);
}
}
if (OverlapTester.pointInRectangle(bassBounds, touchPoint.x, touchPoint.y)) {
if (rand.nextFloat() < 0.5){
Assets.playSound(Assets.bass1sound);}
else{
Assets.playSound(Assets.bass2sound);
}
}
if (OverlapTester.pointInRectangle(hitBounds, touchPoint.x, touchPoint.y)) {
Assets.playSound(Assets.hitom1sound);
}
if (OverlapTester.pointInRectangle(lowtBounds, touchPoint.x, touchPoint.y)) {
Assets.playSound(Assets.lowtom1sound);
}
if (OverlapTester.pointInRectangle(floortBounds, touchPoint.x, touchPoint.y)) {
Assets.playSound(Assets.floortom1sound);
}
if (OverlapTester.pointInRectangle(exitBounds, touchPoint.x, touchPoint.y)) {
if (callback != null){
callback.showOfferwall2();}
Gdx.app.exit();
}
}
}
private void handleInput(float delta) {
time += delta;
if (time > 0.5) {
if(Gdx.input.isKeyPressed(Input.Keys.BACK)) {
callback.showOfferwall2();
Gdx.app.exit();}
}
}
public void draw (float delta) {
GLCommon gl = Gdx.gl;
time += delta;
gl.glClearColor(1, 1, 1, 1);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
guiCam.update();
batcher.setProjectionMatrix(guiCam.combined);
batcher.enableBlending();
batcher.begin();
batcher.draw(Assets.drumbackground, 0, 0);
batcher.draw(Assets.exitbutton, 704, 384);
batcher.end();
}
@Override
public void render (float delta) {
update(delta);
draw(delta);
}
@Override
public void resize (int width, int height) {
}
@Override
public void show() {
}
@Override
public void hide() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void create() {
// TODO Auto-generated method stub
}
@Override
public void render() {
// TODO Auto-generated method stub
}
}
이 관련된 어떤 도움이 사전에 환상적인 감사 것 : 여기
내 가상 드럼을 실행하는 클래스입니다.
첫 번째 결과 : 이 http://stackoverflow.com/questions/16876877/how-to-track-multiple-touch-events-in-libgdx – lxknvlk