Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (654)
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  
  Make simple 2D block world - LibGDX  (Read 1781 times)
0 Members and 1 Guest are viewing this topic.
Offline israelg99
« Posted 2013-12-12 18:59:31 »

Hello everybody, whats up?
So.. I am learning LibGDX right now, and its really really good, I love all the camera stuff and such..
But here I went into a little trouble, I CAN'T, CAN'T manage to make a simple 2D Block world..

First of all this is how I created the `world` variable -
Block[] map = new Block[100 * 100];

So this is my world Cheesy
Now the block class is really simple, it just have some variables, size = 100 and texture image = some image.

Simple enough right? NOW HOW THE f**kK CAN I RENDER IT?!?!!?!?!

I tried.. for a week, I am telling you bros it looks impossible for me right now.
I can post what I've tried.. but its too not working to post haha

So how can I render a map like this, so when i move the player it moves too or something?
at least give me a way or a hint please.. i am tired for trying this for a whole week.

Online Opiop
« Reply #1 - Posted 2013-12-12 21:04:59 »

Start small. If you cant get this to work, set up a new project and just try to figure out how to render individual shapes. You'll need a SpriteBatch.

Seriously though, no one is just going to give you that much code. Its not beneficial for you.

Offline HeroesGraveDev

JGO Kernel

Medals: 360
Projects: 11
Exp: 3 years

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

« Reply #2 - Posted 2013-12-12 21:25:04 »

Your computer will only do what you tell it to do.

There isn't some easy 'render' method you can use just with what you've got.

You have to tell it how to render.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline israelg99
« Reply #3 - Posted 2013-12-12 21:49:16 »

...Uhhh I didn't mention I am programming for more than 2 years now? I just starting out with game development, which was my dream for long.
Now let me explain the problem..

The idea of rendering a world is just to loop through an array of blocks, like this:
for(int y = 0; y < chunk; y++) {
     for(int x = 0; x < chunk; x++) {
          batch.draw(map[y * width + x].TEXTURE, (x * Block.WIDTH), (y * Block.HEIGHT), Block.WIDTH, Block.HEIGHT);

That's how it should be done, of course not exactly like this, but this is the prototype, the core of map rendering.
As I am starting out, I can't get this to work, mostly because the camera is moving and the map is rendering always at the same position, am i right?

I hope you get what is my problem and what I need is a way of thinking about it, maybe my prototype is wrong? maybe there is another way of doing this..

Thanks for helping! I am kinda of confused myself so yeah..  Roll Eyes

Offline HeroesGraveDev

JGO Kernel

Medals: 360
Projects: 11
Exp: 3 years

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

« Reply #4 - Posted 2013-12-12 22:04:21 »

Wait, so what exactly is the problem here?

Does is draw?
If so, is what it draws correct?
If it isn't correct, what is wrong with it?

Offline israelg99
« Reply #5 - Posted 2013-12-12 22:12:02 »

What it does actually, it draws the map on some location ( chunk = 20 and blocksize is = 100, so the location is = 0 - 2000) in the game space (?),
Now when i move my character and my camera moves as well, i can get off that map, because it draws it always at the same location.
you understand? it doesnt expand the map as i move.. kinda..

ohhh i am soo aweful at this, am i?

I saw your projects and as I see you use tiled for the map right? well I don't i make the tile class myself with id and images hahah.

Offline israelg99
« Reply #6 - Posted 2013-12-12 22:38:44 »

Holy Shit, I am starting to realize it... So LibGDX have already a build-in game space?!?!
I figured this out as i move my camera (ortho camera), I couldn't figure out how the heck i can move in game space without creating one.
So LibGDX have a build-in game space its the answer!

Am I right? any ideas? help? something to feed me will be very appreciated!

Thank you @HeroesGraveDev, for helping.  Smiley
Do you have any upvotes here so you get points or shiit like that maybe?

Offline HeroesGraveDev

JGO Kernel

Medals: 360
Projects: 11
Exp: 3 years

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

« Reply #7 - Posted 2013-12-13 00:15:33 »

So... this is solved?

Sorry, it's hard to tell from your post whether you're asking whether a solution works or saying that it already has worked.

Either way, I haven't used LibGDX, but the orthographic camera is what you are/were looking for if you need the screen to follow the player around the map.

Online Opiop
« Reply #8 - Posted 2013-12-13 03:32:57 »

...Uhhh I didn't mention I am programming for more than 2 years now?
I just want to point out that this means nothing. Do you know how to use LibGDX? No, so your two years of programming are not going to help learn the API, besides knowing how the code should logically fit together. If your problem isn't fixed, I stand by my answer. Start small with new libraries and work on it until you finally have what you originally set out to have. Experience in Java is not going to help you that much, besides the obvious.

Offline trollwarrior1
« Reply #9 - Posted 2013-12-13 05:49:23 »

Take a look at my collision example. It is written in LWJGL, but it might be kinda similar.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline israelg99
« Reply #10 - Posted 2013-12-13 08:33:39 »

Allright.. I will start to work slow and easy, I am starting to realize how this stuff works so.. I think i am in a good path.

Thanks anyways folks.

Offline israelg99
« Reply #11 - Posted 2013-12-13 15:19:06 »

Ok, I did it, I figured out and learnt how it works and now i can render the world awesomely great!!

I mean look at this piece of code :DDD
public void RenderMap() {
      for(int y = 0; y < chunk / 2; y++) {
         for(int x = 0; x < chunk / 2; x++) {
            int mapPosY = (y + PosHandle.getBlockY(player.posy));
            int mapPosX = (x + PosHandle.getBlockX(player.posx));
            int mapPos = (mapPosY) * + (mapPosX);
            if([mapPos].TEXTURE != null && mapPosX < && mapPosY < && mapPosX > 0 && mapPosY > 0) {
               batch.draw([mapPos].TEXTURE, (mapPosX * Block.WIDTH), (mapPosY * Block.HEIGHT), Block.WIDTH, Block.HEIGHT);
            int mapPosXA = (PosHandle.getBlockX(player.posx) - x);
            int mapPosA = (mapPosY) * + (mapPosXA);
            if([mapPosA].TEXTURE != null && mapPosXA < && mapPosY < && mapPosXA > 0 && mapPosY > 0) {
               batch.draw([mapPosA].TEXTURE, (mapPosXA * Block.WIDTH), (mapPosY * Block.HEIGHT), Block.WIDTH, Block.HEIGHT);

Any improvements? I assume you don't want to read it, but maybe you will learn something, or help me if i did something wrong.

* Actually the code will be too hard to understand so leave it, just wanted to share
Thanks for help folks!

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

bilznatch (24 views)
2015-08-04 11:03:17

SHC (39 views)
2015-08-01 03:58:20

Jesse (24 views)
2015-07-29 04:35:27

Riven (45 views)
2015-07-27 16:38:00

Riven (25 views)
2015-07-27 15:35:20

Riven (27 views)
2015-07-27 12:26:13

Riven (18 views)
2015-07-27 12:23:39

BurntPizza (41 views)
2015-07-25 00:14:37

BurntPizza (53 views)
2015-07-24 22:06:39

BurntPizza (33 views)
2015-07-24 06:06:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!