Android Games: SimpleSound

De Aulas

Afluentes: Jogos Digitais

Assets

Classe Principal

 1package com.mygdx.game;
 2
 3import com.badlogic.gdx.ApplicationAdapter;
 4import com.badlogic.gdx.Gdx;
 5import com.badlogic.gdx.Input;
 6import com.badlogic.gdx.audio.Sound;
 7import com.badlogic.gdx.graphics.GL20;
 8import com.badlogic.gdx.graphics.Texture;
 9import com.badlogic.gdx.graphics.g2d.SpriteBatch;
10
11public class MyGdxGame extends ApplicationAdapter {
12	SpriteBatch batch;
13	Sound direita, esquerda;
14
15	@Override
16	public void create () {
17		batch = new SpriteBatch();
18		direita = Gdx.audio.newSound(Gdx.files.internal("direita.wav"));
19		esquerda = Gdx.audio.newSound(Gdx.files.internal("esquerda.wav"));
20	}
21
22	@Override
23	public void render () {
24		if (Gdx.input.isKeyJustPressed(Input.Keys.RIGHT)) {
25			esquerda.stop();
26			direita.stop();
27			direita.play();
28		} else if (Gdx.input.isKeyJustPressed(Input.Keys.LEFT)) {
29			esquerda.stop();
30			direita.stop();
31			esquerda.play();
32		}
33		Gdx.gl.glClearColor(1, 0, 0, 1);
34		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
35		batch.begin();
36		batch.end();
37	}
38
39	@Override
40	public void dispose () {
41		batch.dispose();
42	}
43}