Hi,
I made a simple little game where you have to guess a card, and the problem i have is that after i press the button to chose the card, it takes about 2 seconds or even more to update the card and show if i was wrong or right. I am using LibGDX and here is my code:
package gameScreens;
import main.mainGame;
import mainUtils.loadAssets;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.MathUtils;
public class playScreen implements Screen {
private OrthographicCamera cam;
private SpriteBatch batch;
private BitmapFont font;
private ShapeRenderer shape;
private int choosenNumber = 0;
private int mod = 0;
private int computerNumber = 0;
private int lastCompNumber = 0;
private String currentMod;
public playScreen(){
cam = new OrthographicCamera();
cam.setToOrtho(false, mainGame.getWidth(), mainGame.getHeight());
batch = new SpriteBatch();
font = new BitmapFont();
shape = new ShapeRenderer();
loadAssets.load();
}
@Override
public void show() {
}
public void modPast(){
if(computerNumber == 0 ){
computerNumber = MathUtils.random(1,5);
while(lastCompNumber == computerNumber)computerNumber = MathUtils.random(1,5);
System.out.println(computerNumber);
}
if(choosenNumber == 0 && Gdx.input.isKeyJustPressed(Input.Keys.NUM_1)){
choosenNumber = 1;
}
if(choosenNumber == 0 && Gdx.input.isKeyJustPressed(Input.Keys.NUM_2)){
choosenNumber = 2;
}
if(choosenNumber == 0 && Gdx.input.isKeyJustPressed(Input.Keys.NUM_3)){
choosenNumber = 3;
}
if(choosenNumber == 0 && Gdx.input.isKeyJustPressed(Input.Keys.NUM_4)){
choosenNumber = 4;
}
if(choosenNumber == 0 && Gdx.input.isKeyJustPressed(Input.Keys.NUM_5)){
choosenNumber = 5;
}
if(mod == 1){
if(choosenNumber > 0){
if(computerNumber == choosenNumber){
System.out.println("Win!");
lastCompNumber = computerNumber;
computerNumber = 0;
choosenNumber = 0;
}
else if(computerNumber != choosenNumber){
System.out.println("Lost!");
lastCompNumber = computerNumber;
computerNumber = 0;
choosenNumber = 0;
}
}
}
}
public void modFuture(){
if(choosenNumber == 0 && Gdx.input.isKeyJustPressed(Input.Keys.NUM_1)){
choosenNumber = 1;
}
if(choosenNumber == 0 && Gdx.input.isKeyJustPressed(Input.Keys.NUM_2)){
choosenNumber = 2;
}
if(choosenNumber == 0 && Gdx.input.isKeyJustPressed(Input.Keys.NUM_3)){
choosenNumber = 3;
}
if(choosenNumber == 0 && Gdx.input.isKeyJustPressed(Input.Keys.NUM_4)){
choosenNumber = 4;
}
if(choosenNumber == 0 && Gdx.input.isKeyJustPressed(Input.Keys.NUM_5)){
choosenNumber = 5;
}
if(choosenNumber > 0){
computerNumber = MathUtils.random(1,5);
while(lastCompNumber == computerNumber)computerNumber = MathUtils.random(1,5);
System.out.println(computerNumber);
}
if(mod == 0){
if(choosenNumber > 0){
if(computerNumber == choosenNumber){
System.out.println("Win!");
lastCompNumber = computerNumber;
computerNumber = 0;
choosenNumber = 0;
}
else if(computerNumber != choosenNumber){
System.out.println("Lost!");
lastCompNumber = computerNumber;
computerNumber = 0;
choosenNumber = 0;
}
}
}
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
cam.update();
batch.setProjectionMatrix(cam.combined);
shape.begin(ShapeType.Filled);
// shape.setColor(Color.RED);
// shape.rect(200, 10, 600, 200);
// shape.rect(200 - 70, 50, 140, 250);
// shape.rect(350 - 70, 50, 140, 250);
// shape.rect(500 - 70, 50, 140, 250);
// shape.rect(650 - 70, 50, 140, 250);
// shape.rect(800 - 70, 50, 140, 250);
// shape.rect(200 - 70, 50, 140, 250);
// shape.setColor(Color.BLUE);
// shape.rect(mainGame.getWidth()/2 - (170/2), mainGame.getHeight()/2 + 20, 170, 270);
shape.end();
batch.begin();
font.setColor(Color.BLACK);
font.draw(batch, "1", 200, 50);
font.draw(batch, "2", 350, 50);
font.draw(batch, "3", 500, 50);
font.draw(batch, "4", 650, 50);
font.draw(batch, "5", 800, 50);
font.draw(batch, "6", mainGame.getWidth()/2, mainGame.getHeight()/2);
font.draw(batch, "Mod: " + currentMod, 10, mainGame.getHeight() - 10);
batch.draw(loadAssets.sign1, 200 - 70, 50, loadAssets.sign1.getOriginX(), loadAssets.sign1.getOriginY(), loadAssets.sign1.getWidth(), loadAssets.sign1.getHeight(), loadAssets.sign1.getScaleX(), loadAssets.sign1.getScaleY(), loadAssets.sign1.getRotation());
batch.draw(loadAssets.sign2, 350 - 70, 50, loadAssets.sign2.getOriginX(), loadAssets.sign2.getOriginY(), loadAssets.sign2.getWidth(), loadAssets.sign2.getHeight(), loadAssets.sign2.getScaleX(), loadAssets.sign2.getScaleY(), loadAssets.sign2.getRotation());
batch.draw(loadAssets.sign3, 500 - 70, 50, loadAssets.sign3.getOriginX(), loadAssets.sign3.getOriginY(), loadAssets.sign3.getWidth(), loadAssets.sign3.getHeight(), loadAssets.sign3.getScaleX(), loadAssets.sign3.getScaleY(), loadAssets.sign3.getRotation());
batch.draw(loadAssets.sign4, 650 - 70, 50, loadAssets.sign4.getOriginX(), loadAssets.sign4.getOriginY(), loadAssets.sign4.getWidth(), loadAssets.sign4.getHeight(), loadAssets.sign4.getScaleX(), loadAssets.sign4.getScaleY(), loadAssets.sign4.getRotation());
batch.draw(loadAssets.sign5, 800 - 70, 50, loadAssets.sign5.getOriginX(), loadAssets.sign5.getOriginY(), loadAssets.sign5.getWidth(), loadAssets.sign5.getHeight(), loadAssets.sign5.getScaleX(), loadAssets.sign5.getScaleY(), loadAssets.sign5.getRotation());
switch(lastCompNumber){
case 1:
batch.draw(loadAssets.bigSign1, mainGame.getWidth()/2, mainGame.getHeight()/2, loadAssets.bigSign1.getOriginX(), loadAssets.bigSign1.getOriginY(), loadAssets.bigSign1.getWidth(), loadAssets.bigSign1.getHeight(), loadAssets.bigSign1.getScaleX(), loadAssets.bigSign1.getScaleY(), loadAssets.bigSign1.getRotation());
break;
case 2:
batch.draw(loadAssets.bigSign2, mainGame.getWidth()/2, mainGame.getHeight()/2, loadAssets.bigSign2.getOriginX(), loadAssets.bigSign2.getOriginY(), loadAssets.bigSign2.getWidth(), loadAssets.bigSign2.getHeight(), loadAssets.bigSign2.getScaleX(), loadAssets.bigSign2.getScaleY(), loadAssets.bigSign2.getRotation());
break;
case 3:
batch.draw(loadAssets.bigSign3, mainGame.getWidth()/2, mainGame.getHeight()/2, loadAssets.bigSign3.getOriginX(), loadAssets.bigSign3.getOriginY(), loadAssets.bigSign3.getWidth(), loadAssets.bigSign3.getHeight(), loadAssets.bigSign3.getScaleX(), loadAssets.bigSign3.getScaleY(), loadAssets.bigSign3.getRotation());
break;
case 4:
batch.draw(loadAssets.bigSign4, mainGame.getWidth()/2, mainGame.getHeight()/2, loadAssets.bigSign4.getOriginX(), loadAssets.bigSign4.getOriginY(), loadAssets.bigSign4.getWidth(), loadAssets.bigSign4.getHeight(), loadAssets.bigSign4.getScaleX(), loadAssets.bigSign4.getScaleY(), loadAssets.bigSign4.getRotation());
break;
case 5:
batch.draw(loadAssets.bigSign5, mainGame.getWidth()/2, mainGame.getHeight()/2, loadAssets.bigSign5.getOriginX(), loadAssets.bigSign5.getOriginY(), loadAssets.bigSign5.getWidth(), loadAssets.bigSign5.getHeight(), loadAssets.bigSign5.getScaleX(), loadAssets.bigSign5.getScaleY(), loadAssets.bigSign5.getRotation());
break;
}
/* font.draw(batch, "Use SPACEBAR to change mods.", mainGame.getWidth()/2, 60, 0, Align.center, false);
font.draw(batch, show, mainGame.getWidth()/2, 100, 0, Align.center, false);
if(mod == 0){
font.draw(batch, "Mod: Future", mainGame.getWidth()/2, 40, 0, Align.center, false);
font.draw(batch, "The computer will let you pick an image from the 5 that are available, then \n the computer will pick a random one and compare it to yours.", mainGame.getWidth()/2, 150, 0, Align.center, false);
}
if(mod == 1){
font.draw(batch, "Mod: Past", mainGame.getWidth()/2, 40, 0, Align.center, false);
font.draw(batch, "The computer will first chose a random image from 5 \n available, then its your turn to pick one of them.", mainGame.getWidth()/2, 150, 0, Align.center, false);
}*/
batch.end();
if(mod == 0){
currentMod = "Future";
modFuture();
}else if(mod == 1){
currentMod = "Past";
modPast();
}
if(mod == 0 && Gdx.input.isKeyJustPressed(Input.Keys.SPACE)){
mod = 1;
}else if(mod == 1 && Gdx.input.isKeyJustPressed(Input.Keys.SPACE)){
mod = 0;
}
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
}
}
I also wanna point out that it might be the computer that i use atm, but i cannot test it with my personal computer because its summer and i spend the summer at my grandparents. I am using a pretty crappy computer i can say. I suppose game development can wait until i get back home, but i wished i could practice while away too. :/
Also, can i avoid getting crappy fps by using just textures instead of sprites?