Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (523)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
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] Loading screen  (Read 3958 times)
0 Members and 1 Guest are viewing this topic.
Offline seismic

Senior Devvie


Medals: 4
Projects: 1



« Posted 2013-04-09 08:25:47 »

Hey,

how do I render something during create() in libGdx?

I have a rather long map generation process and all I want to show (for now) is basically a BitmapFont that says "loading", so in create() I

1  
2  
3  
4  
5  
6  
7  
bmf = new BitmapFont();
sb = new SpriteBatch();
sb.begin();
bmf.draw(sb, "Loading", 100, 100);
sb.end();

// map.init();


but this gets never shown. Is there a way to force this to be rendered? I'm probably missing a function here or something Smiley

Thanks in advance
Offline HeroesGraveDev

JGO Kernel


Medals: 294
Projects: 11
Exp: 3 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #1 - Posted 2013-04-09 08:35:17 »

I'm not entirely sure of how libGDX works, but I think there is a function you have to call to update the display. (Like Display.update() in pure LWJGL)

Offline seismic

Senior Devvie


Medals: 4
Projects: 1



« Reply #2 - Posted 2013-04-09 08:36:58 »

I think so too, I just don't know the function Sad
Gdx.graphics.requestRendering()
sounded good, but doesn't do anything Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2013-04-09 08:42:59 »

1  
 Gdx.graphics.requestRendering() 

It is asking for render if you're on passive mode. Really has nothing to do with your question.

What you need:
http://code.google.com/p/libgdx/wiki/AssetManager

If you want show something rather than plain text on loading screen, separate it from main bloated atlas and load it first before anything else. Make sure it is light so you can load it from loading screen's constructor. After the manager done, process to your game.

Offline seismic

Senior Devvie


Medals: 4
Projects: 1



« Reply #4 - Posted 2013-04-09 08:50:54 »

Thank you, but I don't really want to use the AssetManager, as I do not care about asynchronous loading or reference counting. I have my own class for texture keeping, which probably wasn't very smart but whatever.

Is there no other way to update the display in libGdx during create()?

Offline seismic

Senior Devvie


Medals: 4
Projects: 1



« Reply #5 - Posted 2013-04-09 09:48:21 »

Stupid workaround is to render 1 frame that says "loading" in render() *then* load the rest of the stuff from create(), but it feels and looks so bad. sigh
Offline Stranger

Senior Devvie


Medals: 8



« Reply #6 - Posted 2013-04-09 10:55:01 »

Maybe this will help.

Anton
Offline seismic

Senior Devvie


Medals: 4
Projects: 1



« Reply #7 - Posted 2013-04-09 11:03:58 »

Thanks but no Smiley
I can render a bitmap font just fine. I just can't render it (or anything for that matter) during create() Sad
Offline Regenuluz
« Reply #8 - Posted 2013-04-09 11:06:47 »

I've not used libGDX, so I might be (very) wrong, but seems like create() is some sort of construct? So why not perform your map generation outside of that function?

Something like:

1  
2  
3  
create();
showLoadingScreen();
generateMap();

Offline seismic

Senior Devvie


Medals: 4
Projects: 1



« Reply #9 - Posted 2013-04-09 11:08:31 »

I could do that, but then I'd have to have that code in the render() function of libGdx, which does work, sure, but it looks a bit strange in my opinion to have a "load-something" function as part of the render()-function of libgdx.

I might just be picky here tho, and this is the way to go about it seeing as libGdx doesn't provide a function to just present the screen or update the display (as lwjgl does)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Regenuluz
« Reply #10 - Posted 2013-04-09 11:18:01 »

Sounds like what you want/need is to have multiple states/screens/whatever-you-want-to-call it.

so something like:
1  
activeScreen.render();


Where activeScreen is, in this case, an instance of Screen which handles how it'll be drawn. Then you can generate the map while that screen is active? (Horrible explanation, right here! Tongue)
Offline seismic

Senior Devvie


Medals: 4
Projects: 1



« Reply #11 - Posted 2013-04-09 11:20:11 »

I get it and you're right, that is probably the best solution Cheesy
Although I still feel libGdx should implement a function like display.update(); Sad
Offline Regenuluz
« Reply #12 - Posted 2013-04-09 11:26:55 »

That's at least how I do it myself. Smiley
Offline dime26

Senior Devvie


Medals: 2
Projects: 3
Exp: 5 years


Should traffic wardens be armed?


« Reply #13 - Posted 2013-04-09 12:11:51 »

Maybe you should consider asset manager and use something like this:

https://github.com/Matsemann/libgdx-loading-screen
Offline Nate

« JGO Bitwise Duke »


Medals: 158
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #14 - Posted 2013-04-09 22:30:58 »

Thank you, but I don't really want to use the AssetManager, as I do not care about asynchronous loading or reference counting. I have my own class for texture keeping, which probably wasn't very smart but whatever.

Is there no other way to update the display in libGdx during create()?
AssetManager is how you do it. This allows you to render while your resources are loaded on a separate thread. Otherwise I guess you could load minimal stuff in create, render a frame, then load the rest.

Offline ReBirth
« Reply #15 - Posted 2013-04-10 01:56:25 »

I guess he don't want to do the load/unload part, or already have his own manager.

Offline seismic

Senior Devvie


Medals: 4
Projects: 1



« Reply #16 - Posted 2013-04-10 10:57:24 »

Yeah the problem is, that it isn't just textures or sounds or other resources that I need to load. I have a rather long (and bad) map-creation code and I just wanted to display a text like "loading" before creating the map.
Offline ReBirth
« Reply #17 - Posted 2013-04-10 11:38:39 »

However FYI AssetManager supports custom class too. You just need to register it Cheesy

Offline Grunnt

JGO Kernel


Medals: 94
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #18 - Posted 2013-04-11 11:31:36 »

Using the AssetManager does not solve OP's problem. It's even completely unrelated to a 'map generation process', so I'm not sure why it's being brought up here repeatedly.

Basically you need to call the render loop at least twice to do this: once to render the loading screen, once to also do the map generating and other time-intensive stuff. For example:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
private boolean rendered = false;

public void render() {
   if (!rendered){
      // Do nothing for one update to make sure something has been rendered
      rendered = true;
   } else {
      // Now that we had at least one render finished, do some time-intensive stuff
      map.init();
   }
   sb.begin();
   bmf.draw(sb, "Loading", 100, 100);
   sb.end();
}


Edit: in other words, you cannot do this in create().

This is the price you pay for getting multiplatform compatibility I think.

Offline seismic

Senior Devvie


Medals: 4
Projects: 1



« Reply #19 - Posted 2013-04-12 05:35:28 »

Thank you, that is how I solved it too currently. I just think it's not very sexy to have a function that loads(/generates) stuff inside the render() function.
Offline Grunnt

JGO Kernel


Medals: 94
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #20 - Posted 2013-04-12 07:20:01 »

Thank you, that is how I solved it too currently. I just think it's not very sexy to have a function that loads(/generates) stuff inside the render() function.

I think it just depends on how you look at it: it's not terribly sexy either to render stuff inside the create() function Grin I treat the LibGDX render() function as an updateAndRender() function, which it basically is. Anyway, glad you solved it!

Offline kutucuk

Senior Devvie


Medals: 5
Exp: 3 years



« Reply #21 - Posted 2013-04-17 09:36:08 »

Could this be what you are looking for? http://bitowl.de/en/day11/
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.

SHC (23 views)
2014-11-25 12:00:59

SHC (21 views)
2014-11-25 11:53:45

Norakomi (19 views)
2014-11-25 11:26:43

Gibbo3771 (22 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (74 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (41 views)
2014-11-12 21:09:33

kovacsa (67 views)
2014-11-07 19:57: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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!