Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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 708 times)
0 Members and 1 Guest are viewing this topic.
Offline israelg99

Junior Member





« Posted 2013-12-12 19: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 -
1  
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.
Offline opiop65

JGO Kernel


Medals: 153
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #1 - Posted 2013-12-12 22: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: 238
Projects: 11
Exp: 2 years


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


« Reply #2 - Posted 2013-12-12 22: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

Junior Member





« Reply #3 - Posted 2013-12-12 22: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:
1  
2  
3  
4  
5  
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: 238
Projects: 11
Exp: 2 years


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


« Reply #4 - Posted 2013-12-12 23: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

Junior Member





« Reply #5 - Posted 2013-12-12 23: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

Junior Member





« Reply #6 - Posted 2013-12-12 23: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: 238
Projects: 11
Exp: 2 years


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


« Reply #7 - Posted 2013-12-13 01: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.

Offline opiop65

JGO Kernel


Medals: 153
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #8 - Posted 2013-12-13 04:32:57 »

Quote
...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 06:49:23 »

Take a look at my collision example. It is written in LWJGL, but it might be kinda similar.
http://www.java-gaming.org/topics/2d-collision-detection/31488/view.html
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline israelg99

Junior Member





« Reply #10 - Posted 2013-12-13 09: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.
Smiley
Offline israelg99

Junior Member





« Reply #11 - Posted 2013-12-13 16: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
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
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) * Assets.map.width + (mapPosX);
            if(Assets.map.map[mapPos].TEXTURE != null && mapPosX < Assets.map.width && mapPosY < Assets.map.height && mapPosX > 0 && mapPosY > 0) {
               batch.draw(Assets.map.map[mapPos].TEXTURE, (mapPosX * Block.WIDTH), (mapPosY * Block.HEIGHT), Block.WIDTH, Block.HEIGHT);
            }
           
            int mapPosXA = (PosHandle.getBlockX(player.posx) - x);
            int mapPosA = (mapPosY) * Assets.map.width + (mapPosXA);
            if(Assets.map.map[mapPosA].TEXTURE != null && mapPosXA < Assets.map.width && mapPosY < Assets.map.height && mapPosXA > 0 && mapPosY > 0) {
               batch.draw(Assets.map.map[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.

 

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

The first screenshot will be displayed as a thumbnail.

ctomni231 (34 views)
2014-07-18 06:55:21

Zero Volt (30 views)
2014-07-17 23:47:54

danieldean (25 views)
2014-07-17 23:41:23

MustardPeter (27 views)
2014-07-16 23:30:00

Cero (42 views)
2014-07-16 00:42:17

Riven (44 views)
2014-07-14 18:02:53

OpenGLShaders (32 views)
2014-07-14 16:23:47

Riven (33 views)
2014-07-14 11:51:35

quew8 (30 views)
2014-07-13 13:57:52

SHC (66 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!