Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (778)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
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  
  LibGDX sprite not rendering  (Read 2051 times)
0 Members and 1 Guest are viewing this topic.
Offline SuperMario
« Posted 2015-05-08 13:16:15 »

I've never had this problem before, it's probably something small i'm looking over.
Setting up :
1  
2  
3  
4  
5  
6  
7  
batch = new SpriteBatch();
      UIBatch = new SpriteBatch();
      cam = new OrthographicCamera(Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());
      mapManager = new MapManager("test", cam);//loads "maps/test.tmx"
      player = new Player(50, 50);
      cam.position.set(cam.viewportWidth / 2f, cam.viewportHeight / 2f, 0);

This is how I render.
1  
2  
3  
4  
5  
6  
batch.setProjectionMatrix(cam.combined);
      batch.begin();
      mapManager.render();
      player.update(delta);
      player.render(batch);
      batch.end();

Inside player.render(), i've tested the sprite with UIBatch which works fine.
1  
2  
3  
test.draw(batch);
test.setPosition(getX(), getY());
     

Inside mapManager.render()
1  
2  
renderer.setView(cam);
      renderer.render();
Offline gzuzboey
« Reply #1 - Posted 2015-05-08 13:22:53 »

have u tried
1  
camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

or in your render method:
1  
camera.update();


EDIT:
Why are u doing:
1  
cam.position.set(cam.viewportWidth / 2f, cam.viewportHeight / 2f, 0);
?

YA BOI
Offline SuperMario
« Reply #2 - Posted 2015-05-08 13:25:29 »

Yes, I do update the camera. Forgot to mention that.
I did try setToOrtho.

EDIT: to center the camera. the viewportwidth/height is set to screen width/height
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SauronWatchesYou

JGO Ninja


Medals: 33
Projects: 4
Exp: 2 years


Hi there! :)


« Reply #3 - Posted 2015-05-08 13:39:16 »

Just a few extra questions here.

Is your map rendering?
Have you tried rendering the player sprite using the map's spritebatch?
I noticed you're using 2 cameras? Have you tried just the one?

Hey, you! Back to work
Offline SuperMario
« Reply #4 - Posted 2015-05-08 13:42:13 »

The map is rendering.
The map has no spritebatch?
1  
2  
3  
4  
5  
6  
7  
public MapManager(String mapName, OrthographicCamera cam) {
      this.cam = cam;
      map = new TmxMapLoader().load("maps/" + mapName + ".tmx");
      renderer = new OrthogonalTiledMapRenderer(map);
   }

then in render I use that cam, not sure if that is a problem

I don't use 2 camera's. I think MapManager's cam variable is just a reference.
Offline SauronWatchesYou

JGO Ninja


Medals: 33
Projects: 4
Exp: 2 years


Hi there! :)


« Reply #5 - Posted 2015-05-08 13:46:52 »

The map does have a spritebatch Grin if you do
1  
renderer.getBatch()


Ah, I didn't noticed you passed in the camera through the map constructor. I personally render all my characters using the map spritebatch. Not sure if this is the issue though, seems strange O.o

1  
2  
3  
renderer.getBatch().begin();
renderer.getBatch().draw(sprite here etc);
renderer.getBatch().end();

Hey, you! Back to work
Offline SuperMario
« Reply #6 - Posted 2015-05-08 13:48:22 »

My renderer doesn't seem to have a spritebatch. I'm using 1.5.4 I believe
Offline SuperMario
« Reply #7 - Posted 2015-05-08 13:54:12 »

Figured it out, some sketchy error.
I call mapManager.render(batch);
inside mapManager.render();
batch.end();
renderer.setview(cam);
renderer.render();
batch.begin();

That fixed it. No idea what it should be like this though.
Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (354 views)
2018-11-16 13:46:03

hadezbladez (188 views)
2018-11-16 13:41:33

hadezbladez (358 views)
2018-11-16 13:35:35

hadezbladez (88 views)
2018-11-16 13:32:03

EgonOlsen (2181 views)
2018-06-10 19:43:48

EgonOlsen (2223 views)
2018-06-10 19:43:44

EgonOlsen (1380 views)
2018-06-10 19:43:20

DesertCoockie (2013 views)
2018-05-13 18:23:11

nelsongames (1672 views)
2018-04-24 18:15:36

nelsongames (2312 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!