Why is my create() Method Not Recognizing a Global Variable? - Java LibGDX - java

I have global variables called:
private int currentLevel;
private int mapHeight;
I have a constructor for my game, where currentLevel = level entered when setScreen() method is called:
public ElevatorLevel(Game g, int level)
{
super(g, level);
currentLevel = level;
}
In my create() method, I set mapHeight to 750 * currentLevel (which starts as one), however when I try to spawn in the blades as seen below, they spawn between -200 and 300. This is because the program is not recognizing currentLevel (I am assuming), so it is multiplying it by nothing, resulting with -200.
public void create()
{
world = new World(new Vector2(0, -9.8f), true);
timeElapsed = 0;
mapHeight = 750 * currentLevel;
blade = new PhysicsActor();
blade.storeAnimation( "", exTex );
blade.setOriginCenter();
blade.circularBoundary();
blade.setMaxSpeed(50);
blade.setDeceleration(50);
bladesList = new ArrayList<PhysicsActor>();
for (int i = 0; i < 3 ; i++)
{
blades = blade.clone();
float xCoord = randomFloatGenerator(440, 20);
float yCoord = randomFloatGenerator(mapHeight - 200, 300);
blades.setPosition(xCoord, yCoord);
mainStage.addActor(blades);
bladesList.add(blades);
}
I also have a Label in my update(float dt) method that is set to:
timeLabel.setText("Level: " + currentLevel);
As seen in the image above, currentLevel is recognized by the label, but not by mapHeight in create().
How do I get currentLevel to be recognized by the create() method?

Below is the standart portrait app code that i use almost in every libgdx project. I never use create method. Instead I use constructor, this code is the most bugfree one that i could have found.
GAME OR MENU SCREEN:
public class TutorialScreen implements Screen {
private OrthographicCamera camera;
public static final float WORLD_HEIGHT = 240;
public static final float WORLD_WIDTH = 135;
private Viewport viewport;
private Stage stage;
private EntryPoint game;
private AdsController adsController;
public TutorialScreen(final EntryPoint game, final AdsController adsController){
this.adsController = adsController;
this.game = game;
adsController.hideBannerAd();
float aspectRatio = (float) (Gdx.graphics.getHeight() / Gdx.graphics.getWidth());
camera = new OrthographicCamera(aspectRatio * WORLD_WIDTH, WORLD_HEIGHT);
camera.setToOrtho(false);
viewport = new FitViewport(WORLD_WIDTH , WORLD_HEIGHT,camera );
stage = new Stage(viewport, game.batch);
}
#Override
public void show() {
}
#Override
public void render(float delta) {
stage.draw();
stage.act();
}
#Override
public void resize(int width, int height) {
}
#Override
public void pause() {
}
#Override
public void resume() {
}
#Override
public void hide() {
}
#Override
public void dispose() {
}
}
ENTRY POINT THAT YOUR APP WILL OPEN FIRST:
package some.package;
public class EntryPoint extends Game {
SpriteBatch batch;
final AdsController adsController;
public EntryPoint(final AdsController adsController ){
this.adsController = adsController; //Interface for admob
}
#Override
public void create () {
batch = new SpriteBatch();
this.setScreen(new YourScreenClass(this,adsController)); //Above is tutorial so this would be new TutorialScreen(this,adsController)
}
#Override
public void render () {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.end();
super.render();
}
#Override
public void dispose () {
batch.dispose();
}
}
Might have missed some curly brackets or ";" but you get the idea. This way you would not encounter any reference issues.

Related

LibGDX Button does not recognize clicks (Stage + ChangeListener)

EDIT: First Cemmentator "Second" was right. I forgot to set Gdx.input.setInputProcessor(stage); - Now everything is working as it should. Thanks!
My Libgdx Buttons "Back", "Menu" and "TryAgain" (which bring you back to another Screen) are not working.
I worked through every solution that I could find but they still not work properly. I also use Buttons and stages in my other Screens and they all work like a charm.
Do you guys see any mistakes in the code? CreateStage() creates the stage and they get displayed through the render Method.
Any Help is greatly appreciated!
public class HighscoreScreen extends ScreenAdapter {
private final GameClass game;
private int score;
private String name;
private boolean menuView;
private SpriteBatch batch;
private BitmapFont scoreFont;
private String[] players;
private int[] scores;
private int counter = 0;
private OrthographicCamera camera;
private Stage stage;
private ScreenViewport v;
public HighscoreScreen (GameClass game, OrthographicCamera camera, int score, String name) {
this.camera = camera;
this.game = game;
this.score = score;
this.name = name;
this.batch = new SpriteBatch();
menuView = false;
batch = new SpriteBatch();
scoreFont = new BitmapFont(Gdx.files.internal("Fonts/score.fnt"),
Gdx.files.internal("Fonts/score.png"),false);
createStage();
}
public HighscoreScreen (GameClass game, OrthographicCamera camera){
this.game = game;
this.camera = camera;
this.batch = new SpriteBatch();
menuView = true;
scoreFont = new BitmapFont(Gdx.files.internal("Fonts/score.fnt"),
Gdx.files.internal("Fonts/score.png"),false);
}
public void createStage(){
v = new ScreenViewport();
v.setCamera(camera);
stage = new Stage(v, batch);
if (menuView) {
Buttons back = new Buttons("Back");
stage.addActor(back.createButton(GameInfo.WIDTH / 2 - 100,
GameInfo.HEIGHT / 2 - 200));
back.addListener(new ChangeListener() {
#Override
public void changed(ChangeEvent event, Actor actor) {
game.setScreen(new MenuScreen(game));
}
});
} else {
Buttons tryAgain = new Buttons("Try Again");
stage.addActor(tryAgain.createButton(GameInfo.WIDTH / 2 - 200,
GameInfo.HEIGHT / 2 - 200));
tryAgain.addListener(new ChangeListener() {
#Override
public void changed(ChangeEvent event, Actor actor) {
game.setScreen(new SurvivalScreen(game, name));
}
});
Buttons menu = new Buttons("Menu");
stage.addActor(menu.createButton(GameInfo.WIDTH / 2,
GameInfo.HEIGHT / 2 - 200));
menu.addListener(new ChangeListener() {
#Override
public void changed(ChangeEvent event, Actor actor) {
game.setScreen(new MenuScreen(game));
}
});
}
}
#Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if (menuView) {
if (counter == 0) {
createStage();
writeScoresToFile();
readHighscore();
counter++;
}
batch.begin();
highscoreToFont();
batch.end();
stage.act();
stage.draw();
} else {
if (counter == 0) {
createStage();
writeScoresToFile();
readHighscore();
compareHighscore();
writeHighscore();
counter++;
}
batch.begin();
highscoreToFont();
batch.end();
stage.act();
stage.draw();
}
}
public void dispose(){
batch.dispose();
stage.dispose();
}
You are probably missing the settings of the input processor to your stage (at least it's not in the code you have posted).
Gdx.input.setInputProcessor(stage);
Note:
Assuming the the Buttons class returns a proper actor.
(see my comment above)

LibGdx: Shaperenderer Rect not being drawn on Screen

Trying to create a simple loading Screen. The below code prints the correct progress, so I know that part works. But the rectangle is not being drawn. Not sure what is wrong.
Full LoadingScreen:
public class LoadingScreen implements Screen {
private static final float PROGRESS_BAR_WIDTH = MyGdxGame.WIDTH / 2f;
private static final float PROGRESS_BAR_HEIGHT = 50f;
GdxAssetManager assetManager;
Stage stage;
//Table mainTable;
private ShapeRenderer shapeRenderer;
private MyGdxGame game;
public LoadingScreen(MyGdxGame game){
this.game = game;
assetManager = game.getAssetManager();
shapeRenderer = new ShapeRenderer();
stage = new Stage(new StretchViewport(MyGdxGame.WIDTH, MyGdxGame.HEIGHT));
}
#Override
public void show() {
assetManager.loadGeneral();
}
#Override
public void render(float delta) {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
renderProgressBar();
if (assetManager.getManager().update()) {
game.setScreen(new LoginScreen(game));
}
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
}
private void renderProgressBar() {
float progress = assetManager.getManager().getProgress();
System.out.println(PROGRESS_BAR_WIDTH * progress);
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.setColor(Color.RED);
shapeRenderer.rect(
(MyGdxGame.WIDTH - PROGRESS_BAR_WIDTH) / 2f,
(MyGdxGame.HEIGHT - PROGRESS_BAR_HEIGHT) / 2f,
PROGRESS_BAR_WIDTH * progress,
PROGRESS_BAR_HEIGHT
);
shapeRenderer.end();
}
#Override
public void resize(int width, int height) {
stage.getViewport().update(width, height);
}
#Override
public void pause() {
}
#Override
public void resume() {
}
#Override
public void hide() {
dispose();
}
#Override
public void dispose() {
stage.dispose();
shapeRenderer.dispose();
}
}
I guess methods of interest are render and renderProgressBar. Like I said, all I get is a white background until the loading is finished, but the print inside renderProgressBar prints the correct values.
Set projectionMatrix of ShapeRenderer using stage camera.
shapeRenderer.setProjectionMatrix(stage.getCamera().combined);

Centering an animation [libGDX]

I have the following class:
public class AnimationDemo implements ApplicationListener {
private SpriteBatch batch;
private TextureAtlas textureAtlas;
private Animation animation;
private float elapsedTime = 0;
private OrthographicCamera camera;
private int width;
private int height;
private int texturewidth;
private int textureheight;
#Override
public void create() {
width = Gdx.graphics.getWidth();
height = Gdx.graphics.getHeight();
camera = new OrthographicCamera(width, height);
camera.position.set(width / 2, height / 2, 0);
camera.update();
batch = new SpriteBatch();
textureAtlas = new TextureAtlas(Gdx.files.internal("data/packone.atlas"));
textureAtlas.getRegions().sort(new Comparator<TextureAtlas.AtlasRegion>() {
#Override
public int compare(TextureAtlas.AtlasRegion o1, TextureAtlas.AtlasRegion o2) {
return Integer.parseInt(o1.name) > Integer.parseInt(o2.name) ? 1 : -1;
}
});
animation = new Animation(1 / 15f, textureAtlas.getRegions());
}
#Override
public void dispose() {
batch.dispose();
textureAtlas.dispose();
}
#Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
batch.begin();
elapsedTime += Gdx.graphics.getDeltaTime();
batch.draw(animation.getKeyFrame(elapsedTime, true), 0, 0);
batch.end();
}
#Override
public void resize(int width, int height) {
}
#Override
public void pause() {
}
#Override
public void resume() {
}
}
In the above I am using the Animation class to simply draw from a texture atlas. I am following an example from another SO question which is here but the co-ordinates don't fit my equation. How should I set these:
private int texturewidth;
private int textureheight;
Any help would be great :)
you need to care about proper offset - the origin is always at the left bottom corner and that is why you need to subtract half of width and height when drawing.
In a nutshell it should be like:
TextureRegion region = animation.getKeyFrame(elapsedTime, true);
batch.draw(region, 0 - (region.getRegionWidth()/2f), 0 - (region.getRegionHeight()/2f));

Libgdx - create multiple balls

So I have this simple pong game but I'm trying to change it up a bit, the thing is I'm currently struggling with having to duplicate or create various balls in the game for it to work the way I want to. I'm uncertain if I should use an arraylist and if so how should I do it? any suggestions would really be appreciated.
public class ColorPong implements ApplicationListener {
private Rectangle field = new Rectangle();
private Ball ball = new Ball();
private float fieldTop, fieldBottom, fieldLeft, fieldRight;
#Override
public void create() {
field.set(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
fieldLeft = field.x;
fieldRight = field.x + field.width;
fieldBottom = field.y;
fieldTop = field.y + field.height;
ball.BallCreation();
reset();
}
#Override
public void resize(int width, int height) {
}
#Override
public void render() {
float dt = Gdx.graphics.getRawDeltaTime();
update(dt);
draw(dt);
}
private void draw(float dt) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
ball.DrawingBall(dt);
}
private void update(float dt) {
updateBall(dt);
}
private void updateBall(float dt) {
ball.Intergrate(dt);
ball.updateBounds();
//------------------
if(ball.Left() < fieldLeft){
ball.move(fieldLeft, ball.getY());
ball.Reflect(true, false);
}
if(ball.Right() > fieldRight){
ball.move(fieldRight - ball.getWidth(), ball.getY());
ball.Reflect(true, false);
}
if(ball.Bottom() < fieldBottom){
ball.move(ball.getX(), fieldBottom);
ball.Reflect(false, true);
}
if(ball.Top() > fieldTop){
ball.move(ball.getX(), fieldTop - ball.getHeight());
ball.Reflect(false, true);
}
}
public void reset(){
ball.move(field.x + (field.width - ball.getWidth()) / 2, (field.y + field.height) / 2);
Vector2 velocity = ball.getVelocity();
velocity.set(300, 150);
velocity.setAngle(360f - 45f);
ball.setVelocity(velocity);
}
#Override
public void pause() {
}
#Override
public void resume() {
}
#Override
public void dispose() {
}
}
and here is the Ball class
private ShapeRenderer ballRenderer;
private Color ballColor = new Color();
public Ball() {
super(32, 32);
}
public void Reflect(boolean x, boolean y){
Vector2 velocity = getVelocity();
if(x) velocity.x *= -1;
if(y) velocity.y *= -1;
setVelocity(velocity);
}
public void BallCreation(){
ballRenderer = new ShapeRenderer();
}
public void DrawingBall(float dt){
ballRenderer.begin(ShapeType.Filled);
drawBall(dt);
ballColorSwap();
ballRenderer.end();
}
int THRESHOLD = 900; // 4 seconds
long lastChanged = 0; // timestamp
public void ballColorSwap(){
// maybe call it here?
if(System.currentTimeMillis() - lastChanged < THRESHOLD)
return;
int rnd = (int)(Math.random() * 4);
switch(rnd){
case 0: ballColor.set(Color.GREEN);break;
case 1: ballColor.set(Color.BLUE);break;
case 2: ballColor.set(Color.RED);break;
case 3: ballColor.set(Color.YELLOW);break;
}
lastChanged = System.currentTimeMillis();
}
private void drawBall(float dt) {
ballRenderer.circle(this.getX(), this.getY(), 20);
ballRenderer.setColor(ballColor);
}
}
In Java, whenever I want to keep track of an arbitrary number of objects I typically use an ArrayList; they are quite handy once you learn how to use them effectively.
Here's an example of how you might use an ArrayList with your update and updateBall methods:
//initialize in create()
ArrayList<Ball> balls;
private void update(float dt) {
//Pretty much saying 'For every ball in Balls, assign it to 'b' and do something with it
for(Ball b : balls) {
updateBall(b, dt);
}
}
private void updateBall(Ball b, float dt) {
b.Intergrate(dt);
b.updateBounds();
//------------------
if(b.Left() < fieldLeft){
b.move(fieldLeft, ball.getY());
b.Reflect(true, false);
}
if(b.Right() > fieldRight){
b.move(fieldRight - b.getWidth(), b.getY());
b.Reflect(true, false);
}
if(b.Bottom() < fieldBottom){
b.move(b.getX(), fieldBottom);
b.Reflect(false, true);
}
if(b.Top() > fieldTop){
b.move(b.getX(), fieldTop - b.getHeight());
b.Reflect(false, true);
}
}
And of course to draw the ball, just do the for(Ball.... thing again and call b.DrawingBall()

how to manage a minimap when using the Stage class?

I'm fairly new to Game development and to Libgdx as well. I'have looked around other similar topics in the forum but often I'm confused trying to understanding their content, therefore I decided to write down my problem here.
My problem is all about creating a minimap in the left bottom corner of the game screen showing the entire world with actors. I'd like to use the scene2d concept as much as possible.
For now I'm concentrating on the desktop version of the game.
I have a windows screen ... saying width = 800, height = 600
The top class of the game, MyOp0Game, is like this:
public class MyOp0Game extends Game {
MyScreen0 my_screen_0;
#Override
public void create() {
// allocate screen
my_screen_0 = new MyScreen0(this);
// set current screen
setScreen(my_screen_0);
}
#Override
public void render() {
super.render();
}
}
The MyScreen0 class is like this:
public class MyScreen0 implements Screen{
protected final Stage stage0;
protected final MyOp0Game game;
protected final MyActor0 actor0;
protected final MyActor0 actor1;
public MyScreen0(MyOp0Game game) {
// link screen to game
this.game = game;
// allocate stage; viewport size maps screen size
this.stage0 = new Stage( Gdx.graphics.getWidth(),Gdx.graphics.getHeight(), true );
// allocate actor0 and add to stage
this.actor0 = new MyActor0();
this.actor0.setPosition(0, 0);
this.stage0.addActor(this.actor0);
// allocate actor1 and add to stage, actor1 is placed next to actor0
this.actor1 = new MyActor0();
this.actor1.setPosition(1000, 0);
this.stage0.addActor(this.actor1);
}
#Override
public void render(float delta) {
// the following code clears the screen with the given RGB color (green)
Gdx.gl.glClearColor( 0f, 1f, 0f, 1f );
Gdx.gl.glClear( GL20.GL_COLOR_BUFFER_BIT );
// translate stage camera to go from actor0 to actor1
//this.stage0.getCamera().translate(1, 0, 0);
// draw stage -> draw actors
this.stage0.draw();
}
#Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
#Override
public void show() {
// not required as no abstract screen for now
//super.show();
}
#Override
public void hide() {
// TODO Auto-generated method stub
}
#Override
public void pause() {
// TODO Auto-generated method stub
}
#Override
public void resume() {
// TODO Auto-generated method stub
}
#Override
public void dispose() {
this.stage0.dispose();
}
}
Finally the MyActor0 class is like this :
public class MyActor0 extends Actor {
SpriteBatch batch;
Texture texture;
public MyActor0() {
batch = new SpriteBatch();
texture = new Texture(Gdx.files.internal("data/libgdx.png"));
}
public void draw(SpriteBatch batch, float alpha){
batch.draw(texture,this.getX(),this.getY());
}
}
The stage viewport is of the same size as the window screen.
The actor texture is smaller than the viewport and therefore the first actor is visible and the second actor is not visible as it is next to the viewport.
I would like to insert in the bottom left a minimap showing the two actors (or equivalent markers).
I've tried several options but it never works, using two cameras and switching between them, two stages?
I think one fundamental question I have is : does the viewport always fills the windows screen?
I have seen your comment but i could not find a Minimap Actor in the libgdx documentations. But i found this link, which may help you out: Minimap. Tell me if this works (:
here is the first prototype of the minimap, it will be enough for the first step of the game dev.
public class Main {
public static void main(String[] args) {
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "my-op0-game";
cfg.useGL20 = false;
cfg.width = MyOp0Game.MY_APP_WINDOW_WIDTH;
cfg.height = MyOp0Game.MY_APP_WINDOW_HEIGHT;
new LwjglApplication(new MyOp0Game(), cfg);
}
}
public class MyOp0Game extends Game {
public static int MY_APP_WINDOW_WIDTH = 512;
public static int MY_APP_WINDOW_HEIGHT = 512;
public static int MY_WORLD_WIDTH = 2048;
public static int MY_WORLD_HEIGHT = 2048;
public static int MY_MINIMAP_WIDTH = 256;
public static int MY_MINIMAP_HEIGHT = 256;
public static int MY_MINIMAP_SCALE_FACTOR = MY_WORLD_WIDTH / MY_MINIMAP_WIDTH;
public static int MY_ORIGINAL_CAMERA_POSITION_X = MY_APP_WINDOW_WIDTH/2;
public static int MY_ORIGINAL_CAMERA_POSITION_Y = MY_APP_WINDOW_HEIGHT/2;
public static final String LOG = "MyOp0Game";
MyScreen0 my_screen_0;
#Override
public void create() {
// allocate screen
my_screen_0 = new MyScreen0(this);
// set current screen
setScreen(my_screen_0);
}
#Override
public void render() {
super.render();
}
}
public class MyScreen0 implements Screen{
protected final Stage stage0;
protected final MyOp0Game game;
protected final MyActor0 actor0_0;
protected final MyActor0 actor0_1;
protected final MyActor1 actor1_0;
public MyScreen0(MyOp0Game game) {
// link screen to game
this.game = game;
// allocate stage; viewport size maps game window size
this.stage0 = new Stage( Gdx.graphics.getWidth(),Gdx.graphics.getHeight(), true );
// allocate actor0_0 and add to stage
this.actor0_0 = new MyActor0();
this.actor0_0.setPosition(0, 0);
this.stage0.addActor(this.actor0_0);
// allocate actor0_1 and add to stage, actor1 is placed next to actor0
this.actor0_1 = new MyActor0();
this.actor0_1.setPosition(512, 256);
this.stage0.addActor(this.actor0_1);
// allocate actor1_0 and add to stage
this.actor1_0 = new MyActor1();
this.actor1_0.setPosition(0, MyOp0Game.MY_APP_WINDOW_HEIGHT - MyOp0Game.MY_MINIMAP_HEIGHT);
this.stage0.addActor(this.actor1_0);
}
#Override
public void render(float delta) {
int lvTranslateX = 0;
int lvTranslateY = 0;
// the following code clears the screen with the given RGB color (green)
Gdx.gl.glClearColor( 0f, 1f, 0f, 1f );
Gdx.gl.glClear( GL20.GL_COLOR_BUFFER_BIT );
/* check if mouse pressed */
if (Gdx.input.isTouched())
{
//Gdx.app.log( MyOp0Game.LOG, " mouse X = "+ Gdx.input.getX() +
// " Camera.x = " + this.stage0.getCamera().position.x +
// " mouse Y = "+ (MyOp0Game.MY_APP_WINDOW_HEIGHT - Gdx.input.getY()) +
// " Camera.y = " + this.stage0.getCamera().position.y);
if (Gdx.input.getX() >= MyOp0Game.MY_ORIGINAL_CAMERA_POSITION_X)
{
if (this.stage0.getCamera().position.x - MyOp0Game.MY_ORIGINAL_CAMERA_POSITION_X < MyOp0Game.MY_WORLD_WIDTH - MyOp0Game.MY_APP_WINDOW_WIDTH)
lvTranslateX = 3;
}
else if (Gdx.input.getX() < MyOp0Game.MY_ORIGINAL_CAMERA_POSITION_X)
{
if (this.stage0.getCamera().position.x - MyOp0Game.MY_ORIGINAL_CAMERA_POSITION_X > 0)
lvTranslateX = -3;
}
if (MyOp0Game.MY_APP_WINDOW_HEIGHT - Gdx.input.getY() >= MyOp0Game.MY_ORIGINAL_CAMERA_POSITION_Y)
{
if (this.stage0.getCamera().position.y - MyOp0Game.MY_ORIGINAL_CAMERA_POSITION_Y < MyOp0Game.MY_WORLD_HEIGHT - MyOp0Game.MY_APP_WINDOW_HEIGHT)
lvTranslateY = 3;
}
else if (MyOp0Game.MY_APP_WINDOW_HEIGHT - Gdx.input.getY() < MyOp0Game.MY_ORIGINAL_CAMERA_POSITION_Y)
{
if (this.stage0.getCamera().position.y - MyOp0Game.MY_ORIGINAL_CAMERA_POSITION_Y > 0)
lvTranslateY = -3;
}
if (lvTranslateX != 0 || lvTranslateY != 0)
{
// translate stage camera to go from actor0 to actor1
this.stage0.getCamera().translate(lvTranslateX, lvTranslateY, 0);
// update actor1_0 (minimap) location to move with camera
this.actor1_0.translate(lvTranslateX,lvTranslateY);
}
};
// draw stage -> draw actors
this.stage0.draw();
}
#Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
#Override
public void show() {
// not required as no abstract screen for now
//super.show();
}
#Override
public void hide() {
// TODO Auto-generated method stub
}
#Override
public void pause() {
// TODO Auto-generated method stub
}
#Override
public void resume() {
// TODO Auto-generated method stub
}
#Override
public void dispose() {
this.stage0.dispose();
}
}
public class MyActor0 extends Actor {
SpriteBatch batch;
public Texture texture;
public MyActor0() {
batch = new SpriteBatch();
texture = new Texture(Gdx.files.internal("data/libgdx_256_256.png"));
}
public void draw(SpriteBatch batch, float alpha){
batch.draw(texture,this.getX(),this.getY());
}
}
public class MyActor1 extends Actor {
SpriteBatch batch;
Texture texture;
Texture blackMarkerTexture;
Texture yelloCameraMinimapTexture;
public MyActor1() {
this.batch = new SpriteBatch();
this.texture = new Texture(Gdx.files.internal("data/blueBg_256_256.png"));
this.blackMarkerTexture = new Texture(Gdx.files.internal("data/blackMarker_32_32.png"));
this.yelloCameraMinimapTexture = new Texture(Gdx.files.internal("data/yelloCameraMinimap_64_64.png"));
this.setName("minimap");
}
public void draw(SpriteBatch batch, float alpha){
// draw actor
batch.draw(texture,this.getX(),this.getY());
// draw game window in minimap
batch.draw( this.yelloCameraMinimapTexture,
this.getX() + (this.getStage().getCamera().position.x - MyOp0Game.MY_ORIGINAL_CAMERA_POSITION_X)/MyOp0Game.MY_MINIMAP_SCALE_FACTOR,
this.getY() + (this.getStage().getCamera().position.y - MyOp0Game.MY_ORIGINAL_CAMERA_POSITION_Y)/MyOp0Game.MY_MINIMAP_SCALE_FACTOR);
// retrieve actors from stage
Array<Actor> lvActorArray = this.getStage().getActors();
for ( int lvIdx = 0; lvIdx < lvActorArray.size; lvIdx++ )
{
Actor lvActor = lvActorArray.get(lvIdx);
if (lvActor.getName() != "minimap")
{
batch.draw( this.blackMarkerTexture,
this.getX() + (lvActor.getX()/MyOp0Game.MY_MINIMAP_SCALE_FACTOR),
this.getY() + (lvActor.getY()/MyOp0Game.MY_MINIMAP_SCALE_FACTOR));
}
}
}
}

Categories