Help error tutorial 75

+1 Frone Bortels · August 22, 2015
Does anybody know why TextBounds, getBounds, width and heigth become red in Android Studio

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class MyGdxGame extends ApplicationAdapter implements InputProcessor {

private SpriteBatch batch;

//Screen dimensions will be used to center text
private BitmapFont font;
private int screenWidth, screenHeight;
private String message = "Touch me";

//Set screen dimensions, font, and use this class for input processing
@Override
public void create () {
batch = new SpriteBatch();

screenWidth = Gdx.graphics.getWidth();
screenHeight = Gdx.graphics.getHeight();

font = new BitmapFont();
font.setColor(Color.BLUE);
font.getData().scale(5);

Gdx.input.setInputProcessor(this);
}

//Don't forget to free font
@Override
public void dispose() {
batch.dispose();
font.dispose();
}

//Get middle of screen and adjust for message size
@Override
public void render () {
Gdx.gl.glClearColor(1,1,1,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

BitmapFont.TextBounds textSize = font.getBounds(message);
float x = screenWidth/2 - textSize.width/2;
float y = screenHeight/2 + textSize.heigth/2;

batch.begin();
font.draw(batch, message, x, y);
batch.end();
}

//Return true to indicate that the event was handled
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
message = "Touched down at " + screenX + ", " + screenY;
return true;
}

//When finger is lifted up
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
message = "Touch up at " + screenX + ", " + screenY;
return true;
}

//While dragging finger across screen
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
message = "Dragging at " + screenX + ", " + screenY;
return true;
}

@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 mouseMoved(int screenX, int screenY) {
return false;
}

@Override
public boolean scrolled(int amount) {
return false;
}

Post a Reply

Replies

Oldest  Newest  Rating
0 Palak Kapoor · December 10, 2015
I am also facing the same problem. Please help!
  • 1

Java / Android Development

107,263 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator