Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED] LibGDX TextureAtlas, SpriteBatch combination - nothing displaying?  (Read 658 times)
0 Members and 1 Guest are viewing this topic.
Offline donnymayhem

Junior Newbie





« Posted 2013-11-15 03:20:13 »

Ok, I've done a lot of looking and can't really seem to find the answer I'm looking for.  My code is at home, but I'll explain what I've been trying to do.

Basically, I have balloons that are created dynamically based on the user's level, which determines the number of balloons to be launched.  In this case, however, I am seeing nothing being displayed on the screen.  I have log entries that are created whenever a balloon is assigned and supposed to be drawn, but nothing appears.

I have all the textures for the balloons in a single texturepack.

So ignoring all the features of the balloon class, this is the approach which I had thought was the way to do it:

- Load a textureatlas and assign it with the balloon.pack
- Assign a sprite to one of the regions in the file.

call sprite.draw(batch); to draw the sprite on screen (in between batch.begin and batch.end)


Again, I apologise that I don't have my code on hand but I was hoping that someone may have come across the same issue, but I guess what I'm probably more interested in is the best way to load a texture from a textureatlas, assign it to an entity (which has attributes regarding its position, etc.), and then draw it between spritebatch calls.

I have done a lot of looking but can't seem to find anything specific to this situation regarding TextureAtlas, which I'm very surprised about.  I'm sure I'm missing something obvious.  Once I'm home I will post the code example but I am hoping that in the meantime someone will be able to decipher what I'm trying to explain and why I'm an idiot Smiley
Offline opiop65

JGO Kernel


Medals: 161
Projects: 7
Exp: 4 years


JumpButton Studios


« Reply #1 - Posted 2013-11-15 03:29:34 »

Without code we can't debug your issue. There is no known bug in LibGDX that would cause this.

Offline donnymayhem

Junior Newbie





« Reply #2 - Posted 2013-11-15 03:50:19 »

Yeah, I'm certain it's something I've done or more likely that I've forgotten to do.

I will post the code as soon as I can.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline donnymayhem

Junior Newbie





« Reply #3 - Posted 2013-11-15 05:44:27 »

Ok, here is the condensed version (without irrelevant bits).  I'm simplifying the code to what I am doing without filling the arraylist, etc., as I have tested both ways and both produce the same lack of result.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
class WorldRenderer {

World world;
OrthographicCamera cam;
SpriteBatch batch;
Sprite blueBal;
TextureAtlas balAtlas;

Balloons balloon;
ArrayList<Balloons> balloons;

float width, height;

public WorldRenderer (World world) {
this.world = world;

width = Gdx.graphics.getWidth() / 40;
height = Gdx.graphics.getHeight() / 40;

cam = new OrthographicCamera();
cam.setToOrtho(false, width, height);
cam.update;

batch = new SpriteBatch();
batch.setProjectionMatrix(cam.combined);

balAtlas = new TextureAtlas(Gdx.files.internal("images/balloons.pack"));

blueBal = balAtlas.createSprite("blueballoon");
}

public void render(float delta) {
Gdx.gl.glClearColor(0,0,0,1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

balloons = world.getBalloons();
// Skipping arraylist bits, let's just assume that balloon is already defined.

sprite.setPosition(3, 3);
sprite.setColor(1, 1, 1, 1);
sprite.setRotation(balloon.getRotation());
sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2);
sprite.setScale(balloon.SIZE);

cam.update();
batch.setProjectionMatrix(cam.combined);

batch.begin();
sprite.draw(batch);
batch.end();

}


The render function in WorldRenderer is called from the render method in the GameScreen.class, there are no GL related functions called from GameScreen itself.  Could this perhaps have something to do with it?

I have noticed in my perusing of the web that people are using TextureRegions and things, but I can't seem to find any demonstrations of people loading images from a TextureAtlas directly into a Sprite.  There is no animation at this point (each balloon is a static image thus far).
Offline Lord Windy

Junior Newbie





« Reply #4 - Posted 2013-11-15 06:41:38 »

What happens if you remove the atlas and camera and just try putting the balloon on screen? I'd also recommend starting a separate project just to try to draw something onto the screen as easily as humanly possible.
Offline donnymayhem

Junior Newbie





« Reply #5 - Posted 2013-11-15 07:09:05 »

Excellent, thank you!  It appears as though I'm doing something wrong with the camera.  I'll have another look, I'm sure it'll be an obvious solution now... hopefully Smiley.

On the other hand, with the fact that I actually intend on using a static screen, is there even a need to use a camera?  Ultimately I'll want to add lighting and shadows to the game but for my first game I'd rather have something a bit more simple Smiley.


I'm not particularly new to java or programming in general, but this is my first ever project with LibGDX.  I've been following Dustin Riley's tutorials somewhat loosely to get the gist of how things work.
Offline Lord Windy

Junior Newbie





« Reply #6 - Posted 2013-11-15 07:11:33 »

I didn't bother with a camera for my project, you'll be fine if you don't actually want the screen to move.
Offline donnymayhem

Junior Newbie





« Reply #7 - Posted 2013-11-15 07:14:02 »

Excellent, thank you.

I will still have a look into working with the camera just purely for education's sake, but at least now I can at least start playing with the logic Smiley.
Offline donnymayhem

Junior Newbie





« Reply #8 - Posted 2013-11-15 07:23:11 »

Just solved it by process of reverse-elimination - I uncommented the cam related lines in the constructor, and left them commented in render(), and now it works with the cam Smiley.

I guess there is no need to do anything with the cam in the render thread anyway, since I make no changes at that point.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (22 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (49 views)
2014-11-29 21:32:03

toopeicgaming1999 (115 views)
2014-11-26 15:22:04

toopeicgaming1999 (105 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!