Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
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   
  Show Posts
Pages: [1] 2 3
1  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Play audio upon button press more than once. on: 2014-01-23 06:48:17
DOH!, thanks for reminding me!
I actually did dispose of the object in a different class, but had forgotten to dispose of this particular sound....le sigh!

Anyway, yay for progress. Now I don't get an error, but if I try to play the sound again, nothing happens....I have a bit of an idea why, because once the audio is disposed of...ITS GONE, therefore, I am trying to play nothing, so I'm going to tinker a bit to try and get it working properly.

UPDATE:
Got it sorted now, however I believe I should be using the AssetManager in the long term, but for now, this is good for prototyping.

I have a class called MenuMusic which has a few methods inside of it. One of which is to play the button clicking noise. My problem was it wasn't creating a newSound, when a new MenuMusic object was created, the new sound was created, but once disposed of, if I tried to play it, nothing would happen as it's not there.
So the method to play the sound is what creates the newSound.

I'm too tired for this to even make sense, but I hope it does make sense.

Anyway Mz103, thankyou for reminding me of something so simple, yet so easily overlooked, I feel so stupid now haha.
2  Game Development / Newbie & Debugging Questions / [LibGDX] Play audio upon button press more than once. on: 2014-01-23 05:44:09
This problem might seem a bit trivial, but I seem to be pulling my brain out along with my hairs trying to work this one out.

Basically, I have a "New Game" button, which once clicked, takes me to another screen which lets me choose story or custom game.
When I click the New Game button, it also plays an audio file, no problemo, however once in the other screen, I click "Back" to go back to the main menu and click the "New Game" button again, the game crashes with a nullPointerException.

I've been doing some digging online (as we do), and haven't really found any solution other than other people's custom audio loading classes, which I can learn off if I actually NEED to.
I have also looked at the LibGDX documentation about using an AssetManager (https://github.com/libgdx/libgdx/wiki/Managing-your-assets), which I believe is probably going to solve a few problems for me, more so than just this one.

What I am wondering is WHY I would be getting a nullpointerException when the audio plays fine the first time, but not the second.
What I am also wondering, is if I am heading in the right direction here?
Should I be using the AssetManager, or writing my own audio loading class and asset caching class? Because honestly without using someone elses code as reference, I would have no idea where to start with doing the latter.

As always, I am looking for direction, not a direct answer as I need to learn to problem solve and learn these things myself, not have it handed to me on a silver platter.

Any help would be greatly appreciated, I will continue to search for a solution or some insight as to WHY I would be getting a null pointer in this scenario.

EDIT: I have found this tutorial here which I think may be helpfuly.
I am thinking that once I play the audio, I need to store the ID into a Long variable type, and refer to that ID when I want to do something with it again, am I correct or no idea? Tongue
3  Game Development / Newbie & Debugging Questions / Re: Multiple knob/range Slider on: 2014-01-22 10:54:58
HOORAY, IT'S DONE (For what I need at least)

The slider is actually setting 3 values that I can use as percentages to determine which parts of my game map will have plains, forest and mountain terrain types.

You can't see the mouse cursor in the video as I forgot to turn mouse cursor on...although it's not all that necessary anyway.

<a href="http://www.youtube.com/v/u8n7HkDpAYc?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/u8n7HkDpAYc?version=3&amp;hl=en_US&amp;start=</a>

The code is not 100% complete, as I still need to fix up the vertical code I think. It needs a real good clean up and it is also far from being neat, or efficient in the way it is written, since I was originally doubting myself and thinking that I'd just dabble with the idea, not caring much about how well it was written.
The main thing is, it works, that is all that matters to me Tongue

Here is the class so far for anybody interested Wink

http://pastebin.java-gaming.org/b99f72d0482
4  Game Development / Newbie & Debugging Questions / Re: Multiple knob/range Slider on: 2014-01-21 10:34:54
PROGRESS:

I have now made it so that you can independently move one knob or the other.
I have also made it so that if you move the first knob into the 2nd knob, it will push the 2nd knob across, and vice versa.

There are still a few issues such as it being difficult to grab hold of the sliders, as it only lets you move a slider if your mouse clicks directly within the size restraints of the knob itself. The problem is that the mouse moves faster than the knob can update, so it ends up being that the knob gets left behind. I have thought of a few ways to fix this and will try them out.

After the knobs are easy to move around, I will then work out the maths to record the ranges in between the knobs...gotta leave the easy stuff for last Tongue

Once it is all working, I will share the code here with you all, so you can use it in your own projects, I am sure you will find it handy.
5  Game Development / Newbie & Debugging Questions / Re: Multiple knob/range Slider on: 2014-01-19 10:51:44
PROGRESS:

I have made slight progress.

I now have 2 knobs showing on the bar, both of them move, but not independently just yet.

Now I need them to move independently, which shouldn't be too hard. Then I need to do all the fun maths stuff to calculate the individual slider ranges so that they can't overlap one another.
6  Game Development / Newbie & Debugging Questions / Multiple knob/range Slider on: 2014-01-19 07:37:18
I will make this short and sweet. Smiley

I have a custom map menu, with a bunch of sliders that the player can adjust so that a procedural world generator can use those values to create a world based on what the user wants.

While I am familiar with creating Slider objects (in libGDX), I wonder if there are any slider bars that allow me to have 2 adjustment knobs on it.

Much like what you see here, minus the range stuff:
http://jqueryui.com/demos/slider/#range

I have done a bit of browsing to try and find answers, and there is nothing significant that I have found so far.
I think the only way I will be able to make it work is to make my own MultiRangeSlider class which would extend the Slider class.
The code inside of the Slider class looks awfully scary at first glimpse to me because I am far from being a great programmer, but I think it would be worth tinkering around to see if I can create some magic.

The purpose of the multi-knob slider would be for division of land into different terrain types.
For example:
plainsSlider = 10
forestSlider = 55
mountainsSlider = 35

If the map size was set to 500, then:
plainsSlider = 10% of 500 is 50
forestSlider = 55% of 500 is 275
mountainsSlider = 35% of 500 is 175

The resulting values would determine the terrain tile threshold values in the world generator. So in this case, there would be a heavily forested mountainous map with few open plains.

Any help on the matter would be greatly appreciated. I do not ask for a copy/paste of code, but merely some direction to help me solve the problem.
It is not 100% necessary that I work out this problem, as I am happy to just use 3 seperate Slider's, but I just think that one bar would take up less space, would make more sense to the user, and it would look better.

NOTE: I should note that I am using LibGDX too Wink
7  Game Development / Newbie & Debugging Questions / Re: Save/Load multi-dimensional byte array on: 2014-01-12 02:33:08
So after a bit of fiddling around over the past 2 days (I haven't had much time to program despite 2 days off work Sad ). I ended up getting saving and loading working on a base level.

I figured I would just share the code for other newbies like myself who may come across this thread.

Bare in mind, there is still a hell of a lot more complexity to what I need to do, but this is one little tiny step forward, and gives me a basis to work from.



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  
// THIS METHOD IS USED FOR SAVING THE MAP DATA TO A FILE.
// (Note: If there is an existing file of the same name of the file we want to write to, we must delete it first, otherwise the data will be appended, which is not a good thing :P)  

public void saveMapData(){

      FileHandle file = Gdx.files.local("savetesting/myMap.txt");
     
      boolean isFileAvailable = Gdx.files.local("savetesting/myMap.txt").exists();
      if(isFileAvailable){
         System.out.println("DELETING FILE");
         file.delete();
      }
   
      try{
         for(int x = 0; x < map.length; x++){
            for(int y = 0; y < map[0].length; y++){
               
               byte[] temp = {map[x][y]}; //I feel as though these 2 lines could be done differently, would it be better if 'temp' was just a byte? If so, I'm not sure how to write a byte value to the file without it being a byte[].
              file.writeBytes(temp, true);

            }
         }
      }catch(Exception e){
         System.out.println("Cannot write to file");
      }
   }

// THIS METHOD IS USED TO LOAD THE MAP DATA
// Note: Right now, it's just reading the data and displaying the byte data as integers within the console, we aren't storing the data into a new map[][] yet, nor are we controlling how the data is to be read into the map[][].
 
   public void loadMapData(){
      FileHandle file = Gdx.files.local("savetesting/myMap.txt");
      byte[] stuff = file.readBytes();
           
      try{
      for (int x = 0; x < stuff.length; x++){
         System.out.println(stuff[x]);
      }
     
      }catch(Exception e){
         System.out.println("There was a problem reading the file");
      }
   }
8  Game Development / Newbie & Debugging Questions / Re: Saving and Loading on: 2014-01-11 01:10:57
Off topic:
I don't think he is trolling. I saw the name and chuckled to myself, but lighten up guys, he's just like every other person on this forum, a programmer, who happens to be asking for suggestions/help.
I don't think his name warrants the amount of abuse he has copped from certain members here.
So I say let's stay on topic, stop the flaming, and try and help out, without being condescending.

On topic:
I, myself am no expert on loading/saving...in fact, I've just popped back onto the forums are a while of no programming, and first thing I have asked about is saving/loading Tongue

While I am not great with the syntax of saving and loading, the concept behind it is pretty straight forward. Just like storing food in the fridge so you can eat it later.

Just like everyone else has said so bluntly here, you haven't posted the core rendering code that may present the problem, and I understand it may be a problem for you if you wish to sell your game. But remember, most of the people who are able to provide you with help, are people who actually have made games themselves, or are more experienced programmers who have been programming for years on end, refining and expanding their own programming knowledge...one way to help learn programming is to share your existing knowledge with others, hence why forums like this exist. So my point is, you probably shouldn't worry too much about people stealing your code....generally people who have to steal your code, have no idea how to use it anyway Wink
You don't have to post the entire source, but in this case, your methods for rendering.

It sounds like you are loading the data into the game, object positioning and names etc are showing when called from within a List (I'm guessing that is what you are using to keep track of your entities?), but the objects themselves are not visually being rendered.
This tells me that the objects obviously exist in your world, but the information loaded, is not being used to determine what textures to load in the location of your objects.
You say that they work before saving, but not after loading.
So it's a matter of follow the yellow brick road and see where the bump is that takes things off course. I would say that your object information is being loaded into a List or ArrayList, but the code that normally determines what textures to load where those objects are, is not using that information at runtime.
It really is hard to tell without some sort of code snippet to show what is going wrong, and where. It sounds like something ridiculously simple, but it could also be ridiculously complicated and difficult if your code is poorly structured.

9  Game Development / Newbie & Debugging Questions / Re: Save/Load multi-dimensional byte array on: 2014-01-09 11:46:47
Hmmm...yeah...but it's the "//write tile to file stream" part that I'm trying to work out...the rest is pretty much common sense.

Reading through the File Handling documentation on the libGdx wiki and actually READING it, seems to be helping clear things up, not exactly scary.

But I still wonder what other people use to store their 2d terrain data, game object data and so on, so forth.

10  Game Development / Newbie & Debugging Questions / Save/Load multi-dimensional byte array on: 2014-01-09 07:33:40
So it has been a while since I have programmed... job,stress, depression, messy code etc tend to get in the way of my development process a hell of a lot.
But that aside, I'm back at it again.

I've spent the last week or so re-writing the code for my existing game project so as to make things easier for me to work on.
I've also taken a bit more time out to do some more organised documentation and logging of progress which has really helped.

Currently, my goal is to learn how to save game data to a protected file, or save encoded data to a file so that it cannot be altered by other's without loading the file in the game editor or the game itself.

To begin with, I have a procedurally generated game world using diamond-square algorithm, these procedural worlds will be created when a player creates a custom game with a randomized map generated based on a seed value that is determined by a bunch of slider values and check boxes. I want the procedural world generation to be very extensive, but not right now, I have to get the basics down first.

So at the moment, once I click my little world generation button, it stores a set of numbers (that represent terrain tile types), into a multi-dimensional byte array.

Currently, I have managed to get the engine to create a multi-dimensional array with 530,887,671 tiles in it, and the game runs the same as if there were 500,000 tiles, as the renderer culls out what it can't see on the immediate viewing area.

In my head, I know what needs to be done, but I just don't know HOW to do it, what techniques to use.

Without being too specific on map data, I have just been looking at how to save and load data using libGDX and java.

I checked out the libgdx documentation on file handling:
https://github.com/libgdx/libgdx/wiki/File-handling

I have come across things such as preferences for things like player stat saving.
http://www.badlogicgames.com/wordpress/?p=1585
http://www.java-gaming.org/topics/how-to-load-player-save-data/30618/msg/282944/view.html#msg282944

I have come across file and data output streams for storing and loading map data.
http://developer.nokia.com/Community/Wiki/How_to_create_2d_tiled_array_binary_file_and_load_it_in_Java_ME

And I have also come across dermetfan's video where he saves data using JSON and base64.

So basically I know what to do, but just don't know how to do it, and am looking for direction, or something I can learn from, rather than a direct answer (although I tend to learn from those pretty well too Tongue).
Either I have been searching the wrong things on youtube and google, or I'm just having a durpey moment (I am not all that intelligent...or at least it feels that way).

Any help would be greatly appreciated. While I wait, I am going to keep exploring the interwebz for information Smiley

Also, for those who don't know or remember what I was/am working on, here is a youtube video:
<a href="http://www.youtube.com/v/nYEB2TrtViE?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/nYEB2TrtViE?version=3&amp;hl=en_US&amp;start=</a>
11  Game Development / Game Play & Game Design / Re: [LibGDX] 2D (top down) procedurally generated terrain. on: 2013-09-10 14:06:18
I'm not as advanced as others here, but I guess any time I have a null pointer exception, I immediately think "what ISN'T initialized properly".

So I guess I would ask how is "tile" initialized?
12  Game Development / Game Play & Game Design / Re: Auto-Tiling on 2D map. on: 2013-08-25 11:41:01
Here is a video showing off progress so far, it is mainly about the auto-tiling, but i've put some zoom functionality in there and fixed up mouse coordinates (needed to do a bit of research to convert them to world coordinates, rather than screen coordinates).
Note that the zoom functionality most likely won't be used in the final game, it's just used to show off the terrain. Manual zooming plays no part in actual gameplay, therefore will only be used for testing. Automatic zooming based on height may play a part however. Either that, or the higher the player is, the further he will be able to move his mouse away from his player.
I also decided to see how it'd perform on my Galaxy S3 phone, so had to work out gesture controls etc for it to work properly, and it works fine just to show off.

I have quite a lot of Auto-tile textures to do, so at the moment, my main goal was to get auto-tiling working, and to understand the process of getting it to work.
Later on, I will work on the 250+ 32x32 textures and animations Tongue
Thanks to the input some of you guys have given me, it gave me a bit more of an insight. I ended up doing my auto-tiling differently to what was suggested, and i'll see if I can somehow post the code on here to show you guys what i've done.


For the time being though, here is a video! Smiley
<a href="http://www.youtube.com/v/nYEB2TrtViE?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/nYEB2TrtViE?version=3&amp;hl=en_US&amp;start=</a>

On a side note, I have discovered that having an alcoholic drink when you can't focus actually helps you focus, I guess it cuts out all the annoying crap from your mind and lets you focus on one thing at a time. I guess this is why Russians are some of the best programmers in the world, they don't drink Coffee, they drink Vodka at work, them clever cookies! Cheesy
13  Game Development / Game Play & Game Design / Re: Auto-Tiling on 2D map. on: 2013-08-17 13:23:28
When I have a more finished working version, I will show the code, just in case anybody has any suggestions for improvement Smiley

For now, I will describe the steps the program takes:

1. Inside of the Render() method, I call on a method called drawBaseTiles(); which does an x and y FOR loop through the tiles in the viewport (and a little just outside the viewport to prevent "popping" tiles), rendering tiles based on the byte value at the current array index using a switch statement to decide what tile to render.
2. After the base method runs, I run yet another method to draw the transition tiles called drawTransitionTile();
3. drawTransitionTile() performs the same loops through the tiles currently on the viewport that the drawBaseTiles(); method does, only does not use a switch statement, it just calls upon another method within the loop called selectSprite(x, y);
4. selectSprite(x, y); initializes a "result" variable with the result of another method called getTileType(x,y);
4. getTileType(x, y); first calls upon another method, which is called checkNeighbours(x, y); which serves to turn some boolean values to true depending on if the neighbouring tiles equal the current tile or not.
5. After setting up, up_right, right, down_right, down, down_left, left, up_left to true/false (default value is false) the method finishes and the checkNeighbours(x,y); method continues with some conditional statements which basically say "if true, result += .... (1, 2, 4, 8, 16, 32, 64 or 128)". The method then returns that value back to selectSprite(x,y);
6. selectSprite(x,y); then uses the returned value to choose from a list of sprites with the use of a switch statement with a whole bunch of cases (if I used if statements, I imagine it could be painful to read).
7. Once a case matches, it does a batch.draw() of a specific sprite.

I haven't yet incorporated precedence rendering just yet, but it's in my head, and I don't think it will be very hard to do, but like everything, it always seems easy until you go to do it Tongue

Now it may not be the most effective way of doing things, but I did a big clean up of my code today to make it more organised, putting pieces of code into methods, separating code, leaving large title-like comments in the code such as:
1  
2  
3  
//////////////////////////////////////////////////////////////////////////////////////
//////////////================WORLDRENDERER METHODS=================//////////////////
//////////////////////////////////////////////////////////////////////////////////////


...to help break up the code and make it FAR easier to read.

UPDATE:
At the moment, I have 2 textureAtlas's now, and I think it is causing some stutter. The framerate remains steady 61-60, but the time for each frame itself is sporatically slow.
Because of this, I've quickly looked at using spriteCache in my code too. I'm not sure if I have to use it in combination with spritebatch just yet, but that is research for another day.
But, progress was made today, I knew it would happen, just had to be patient with myself. I'll make a new post with source code link and maybe a video when I get it sorted Smiley
14  Game Development / Game Play & Game Design / Re: Auto-Tiling on 2D map. on: 2013-08-17 12:08:41
Huzzah! It is a miracle!

I tried to do auto-tiling my own way, to see if my brain actually works, and despite going bald as a result of tearing hairs out, I have the very very very earliest version of auto-tiling working!

Right now the way I have done it is very clunky, it was a prototype of prototypes. The more efficient stuff starts now, and when it's working, images will soon follow Smiley
15  Discussions / General Discussions / Re: What You Do When You are Burnt Out on: 2013-08-17 01:20:09
Embrace the flames! MUAHAHAHAHAHAH!

I try to just re-focus more than go do something else. I know if I play a game, I won't stop playing it.

If I do play a game however, I want to play something similar to what i'm creating, but unfortunately, there isn't anything similar to what i'm creating, and the games that are close, I will want to invest hours and hours in, and become a little addicted Tongue
16  Game Development / Game Play & Game Design / Re: Auto-Tiling on 2D map. on: 2013-08-15 13:55:14
In the example that I gave you, I used bitwise operations. The '&' operator is a bitwise operator that takes the bits and does this:
1  
2  
dec: 2 & 3 = 2
binary: 10 & 11 = 10

So, you can store multiple values in a number, up to 8 booleans in a byte.

However, in Java, it isn't quite so simple. Bytes in Java range from -127 to 128 (inclusive), so it is more difficult* to store 8 booleans in a byte, but possible by writing the numbers in hexadecimal instead of decimal.

So, instead of this:
1  
byte aByte = (byte) 255;


You would have to use this:
1  
byte aByte = (byte) 0xff; 


But thats only if you want to use only a single byte. Otherwise, you can just use the code in my example.


I would love to learn how to do it just using a single byte, the more optimization techniques I know, the better! Especially if I plan to have this working on Android and IOS devices too Smiley

So I have modified the code you provided before, just so I can understand what you mean here:
http://pastebin.java-gaming.org/e8aa1028e63

I am not really sure that is correct (in fact, I don't think it is, which shows I don't fully understand where I would use the hexidecimal value in the code you provided.

Also, next few days i'm back at work again, busy busy busy. So we shall see how much progress I actually make. I will try not to post again until I have gotten some example of auto-tiling working.
17  Game Development / Game Play & Game Design / Re: Auto-Tiling on 2D map. on: 2013-08-15 05:55:03
You guys are awesome!

I haven't yet implemented anything just yet, but I can see how it all should work (I guess I don't just want to copy/paste your code without really fully understanding what is happening first).

I like your method LongArmX as it's nice and short and sweet, that is what I am aiming for.
It's simplified and makes perfect sense. I don't think it takes into account any tile precendence like Geemili has in his code, but still a great simple example Smiley
The result would refer to a specific tile ID which could then be used to determine what sprite to draw when I do the batch.draw method.

Now that I understand bitwise operators, I can now see where you have used them Geemili, for example:
1  
if(transitionTile[x][y] & 1==1)


So in this case if the transitionTile[ x ][ y ] was equal to 8 the following would occur because of the & bitwise operator

1000 (8 )
0001 (1 )
---- == //If the 2 numbers match
0000 (0 )
=
false (0 )

Huh

Where as if transitionTile[ x ][ y ] was equal to 8, it would stop at this line of code:
1  
if(transitionTile[x][y] & 8==8)


1000 (8 )
1000 (8 )
---- == (if the 2 numbers match)
1000 (8 )
=
true (1 )

So it's saying if 1000 and 1000 match one another, then the result is 8.

Am I correct? Or am I way off? Sad
18  Game Development / Game Play & Game Design / Re: Auto-Tiling on 2D map. on: 2013-08-15 04:10:50
I guess this part is where i'm stuck at:
Quote
The transition information for a single terrain type need only use 8-bits of data (4 bits for the edges and 4 bits for the corners) which fits conveniently into a single byte

While I understand the concept, and it's an excellent one, I just don't know how to store the information in a single byte.
I think it's just because I don't understand how to use/create bitwise operations.
Now I know how to use bitwise operations, the operators are straight forward...
If I did 01000001 | 00011000 it would equal 01011001
If I did 01000001 & 01011000 it would equal 01000000
If I did 01010101 ^ 10101010 it would equal 11111111
The ~ operator I haven't looked into too much, seemed a bit more complicated and not applicable.

...However I still don't know how to store the information Sad

There is a post here which goes through the technique vaguely, but due to my lack of knowledge of bitwise operations, i'm scratching my head.

I am writing down how I think it should be done now, and trying to put the process into play. Hopefully I end up with a good result by the end of the day! Smiley

http://forums.tigsource.com/index.php?topic=21237.0
19  Game Development / Newbie & Debugging Questions / Re: [LibGdx] Can't render tiled map on: 2013-08-15 02:35:34
This guy has made some great simple tutorials on how to do it from scratch Wink
http://www.youtube.com/playlist?list=PLXY8okVWvwZ0qmqSBhOtqYRjzWtUCWylb
20  Game Development / Game Play & Game Design / Re: Auto-Tiling on 2D map. on: 2013-08-15 01:20:09
Can you show your terrain assignment code then?
It would be much easyer to help.

Certainly. This is my current code to render through the portion of the map that is within the viewport:
x0 = bottom left of viewport
x1 = bottom right of viewport
y0 = top left of viewport
y1 = top right of viewport

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  
for(int x = x0; x < x1; x++){ 
          xpos = x - 4;
         
         for(int y = y0; y < y1; y++){
            ypos = y - 4;
           
               switch(map[x][y]){
                  case 0:      
                  batch.draw(deepwater, xpos, ypos, scalex, scaley);
                  break;
                 
                  case 1:
                  batch.draw(water, xpos, ypos, scalex, scaley);
                  break;            
   
                  case 2:
                  batch.draw(shallowwater, xpos, ypos, scalex, scaley);
                  break;
   
                  case 3:
                  batch.draw(wetsand, xpos, ypos, scalex, scaley);
                  break;
   
                  case 4:
                  batch.draw(sand, xpos, ypos, scalex, scaley);
                  break;
   
                  case 5:
                  batch.draw(grass, xpos, ypos, scalex, scaley);
                  break;
   
                  case 6:
                  batch.draw(darkgrass, xpos, ypos, scalex, scaley);              
                  break;
   
                  case 7:
                  batch.draw(lowmountain, xpos, ypos, scalex, scaley);
                  break;
   
                  case 8:
                  batch.draw(highmountain, xpos, ypos, scalex, scaley);
                  break;
               
                  case 9:
                  batch.draw(mountainpeak, xpos, ypos, scalex, scaley);
                  break;
            }
         }
      }


As for where I am up to. Based on what I had read in those links, I wanted to work out a method which does as those links say, so it adds up values of surrounding tiles to create a tile ID of sorts which would be then used to reference a specific sprite, then use that sprite ID when I do a batch.draw in the render() method.

I have a bit more clarity this morning, I think yesterday my mind was off with the fairies and getting slammed with an internal hammer at the same time, so i'll get cracking soon enough and see what I can come up with.

Also Geemili, I will thoroughly check out your code a bit more later.
I read through this morning and I was impressed by the amount of effort you have gone through to help me, I appreciate that, because that is exactly the help I was after Smiley
21  Game Development / Game Play & Game Design / Re: Auto-Tiling on 2D map. on: 2013-08-14 15:23:58
These are currently the ways I am thinking of doing it:

- After I generate my byte[][] (0 - deep water, 1 - midwater, 2, shallowater, 3 wetsand etc) I do yet another iteration through the byte array within the terrain generation class, and do the neighbour checking before re-assigning values to the byte[][] (I would probably have to change the byte[][] back to int[][] to compensate for number of tiles, and that would limit the size of map generation, however it is capable of doing 540,000,000 tiles, so I don't think that will be an issue Tongue)
If a player digs a tile out of the map later, then the WorldRenderer will change the number at that array cell to cator for the tile change.

- In my WorldRenderer class (where I actually draw the tiles based on the byte at the current iteration through the byte[][]), I could call upon the auto-tile generation for every tile within the viewport, realtime. However I am worried this will cause performance issues, I won't know until I try.


My problem is that I don't know how to actually write the auto-tile method, I don't know if I should write a whole new class with it's own methods or create a method within my WorldRenderer class, or within my terraingeneration class. I just seem to be brain dead lol.

I attempted to do some kind of for loop earlier within the WorldRenderer, but it would make a horrible mess of my code, as there would be if, if else, statements everywhere.

Perhaps I just need to sleep on it, try and come back to it when I am not feeling crappy Tongue
22  Game Development / Game Play & Game Design / Auto-Tiling on 2D map. on: 2013-08-14 14:30:41
So as some of you know, I have been working on a top down 2D game, and finally (with the help of some great resources!) managed to get some procedural terrain generation happening.
For those who don't know, I will just sum it up, by showing you a video of where the game is up to right now.
<a href="http://www.youtube.com/v/8k8oLnWopMw?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/8k8oLnWopMw?version=3&amp;hl=en_US&amp;start=</a>

As you can see, there is no auto-tiling/tile transitions. And despite spending hours upon hours googling for resources on how to go about creating an auto-tile system, I still find myself sitting in my chair, scratching my head as to how I can implement an auto-tiling system efficiently.

These are the best resources based on what other people have said, and from what I have seen myself:
http://www.gamedev.net/page/resources/_/technical/game-programming/tilemap-based-game-techniques-handling-terrai-r934
http://www.saltgames.com/2010/a-bitwise-method-for-applying-tilemaps/
http://www.codeproject.com/Articles/106884/Implementing-Auto-tiling-Functionality-in-a-Tile-M

Now I don't know if it's because I have the flu, have had very bad sleep, haven't been eating properly, am stressed from work, am sore from the gym and have been dedicating just about every moment of my minimal free time to programming research and work...but I read those links, and for some reason I can't seem to fully understand them, I kind of understand, but without some kind of source code example, I find myself thinking "huh?"

I just feel stupid that I can't seem to understand how to implement this when so many other people eagerly point out that link and the other links as being the best resources, then saying they've implemented the system within 2 hours.
I've been trying to understand it for 2 days and haven't gotten anywhere, it's frustrating and disheartening that I can't even understand something that is apparently so simple Sad

I really don't even know what to ask, the only way I could understand it is to see source code, or pseudocode.

Could anybody please explain the implementation side of thigns better than those articles, or post example code or pseudocode?

Your help will be greatly appreciated, and I think when I understand it, I will be writing a tutorial for others to understand it too.
23  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Artefact visualizzation Tiled level on: 2013-08-14 09:20:27
The issue he is referring to is the same as the very beginning of this video, and 7 seconds in:
<a href="http://www.youtube.com/v/XoAxThXeN8I?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/XoAxThXeN8I?version=3&amp;hl=en_US&amp;start=</a>

It's difficult to see in the video, but when running the game, it can often flicker up with the lines in between tiles.

From what I've read here and there, it is called texture bleeding, I haven't yet applied any fixes, but if, like me, you packed your textures with the texturePacker gui and didn't pad your textures, then bleeding can occur easily. For some people, this doesn't fix things up though, and this article seems to explain why:

http://jfix.by/category/gamedev/libgdx/
24  Game Development / Newbie & Debugging Questions / Re: [LibGdx]Doesn´t understand Camera + Noob Questions on: 2013-08-14 08:50:53

@Otreum
I really don´t understand your code, because its the same as mine?

Read the code carefully, it is not the same. Wink

I said to create a "getter" method which you can call on to return the position.

And then when you want the position, you call on the getter method.

So instead of using:
1  
player.position.x

to get the players position, use:
1  
player.getPosition().getX //Calling on a method which returns the value of the variable "x"


And obviously the same with the y value too.
25  Game Development / Newbie & Debugging Questions / Re: LibGDX TextureAtlas on: 2013-08-11 07:02:23
TextureAtlas is ONE texture, that is made up of 1 or more smaller textures.

For example, if you have 4 textures that are 32x32, don't create 4 different texture objects, but instead, pack them into a TextureAtlas using this handy tool here:
https://code.google.com/p/libgdx-texturepacker-gui/

It will create a single texture file, and also create a .pack file which holds data such as the texture location, and name (along with other settings such as padding etc).

If you wanted to create a textureAtlas, first download that GUI tool from above and create a TextureAtlas and pack file from it (there are videos showing how, use your google-fu).
Lets just say you have four 32x32 image that you put into the texturePacker, called grasstile, sandtile, watertile, mountaintile, it would pack them all in one texture that is then 64x64 in size, or 128x32, or 96x64, or whatever depending on how you want to pack them.
It also uses the file names of the 32x32 images to use as reference inside your code

Then create a TextureAtlas object, followed by a sprite that you can easily recognize, like so:
1  
2  
3  
4  
public class WorldRenderer implements Screen{

TextureAtlas atlas;
Sprite grass; //do the same thing with other textures


Then under your constructor, you want to do the following:
1  
2  
3  
4  
5  
public WorldRenderer(World world){
      this.world = world;

atlas = new TextureAtlas(Gdx.files.internal("data/terraintiles.pack")); //point this towards your .pack file
grass = atlas.createSprite("grasstile"); //this is the name of the file you put into your textureAtlas, the texturepacker names that texture region with the filename so it's easy to refer to.


Then inside of your render() method, and inside of your batch.draw(); do the following:
1  
2  
3  
4  
public void render(){

batch.begin();
batch.draw(grass, posX, posY, scaleX, scaleY); //draw the grass sprite, set it's x and y positions, and the scale of the sprite in X and Y
26  Game Development / Game Play & Game Design / Re: [LibGDX] 2D (top down) procedurally generated terrain. on: 2013-08-11 02:51:43
Thanks Smiley

I was considering using switch statements, but wasn't too sure if they would be as efficient with this sort of things. I actually really like switch statements, having used them in a procedural story generator I created, I just wasn't sure if people really used them for map rendering.

As for iterating only what is inside of the viewport, I don't know why I couldn't quite figure out what to do, but then before bed last night, after a few american honey bourbons and coke, it occured to me that I was checking through every single tile on the map to determine what I should and shouldn't render, so therefore the larger the map, the slower the performance, so proceeded to do exactly what you have here (literally the same), and it works a treat.
Seeing your post this morning with the added suggestion of using Switch statements helps clean up my code and hopefully run better too.

Since last night, I am able to render massive worlds (which is obviously a longer load time) with the same realtime rendering performance as a smaller world as i'm only checking tiles within the viewport.
For those who like numbers, previously, it struggled to render after generating 6,296,577 tiles, now it is able to render after generating 235,960,321 tiles, and probably more if the terrain generator wouldn't run out of heap space.
It spits out the message:
Quote
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.OutOfMemoryError: Java heap space
   at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:116)
Caused by: java.lang.OutOfMemoryError: Java heap space

I will still look into quad-trees some more, as I know I will want to use those for entities etc

The wiki seems to be a great resource for this so far, there are a few other websites out there talking about quad-trees, and videos of people showing them off helped me understand in about 10 seconds how they work, where as reading about the quad-trees initially had me scratching my head Tongue

The wiki does show the pseudo-code for implementation however, so I will create a class and toy around until I get something working some time.

http://en.wikipedia.org/wiki/Quadtree
27  Game Development / Game Play & Game Design / Re: [LibGDX] 2D (top down) procedurally generated terrain. on: 2013-08-10 14:52:48
After some (light) reading, I am not sure if I should use quad-trees or something else just to render the map itself.
Quad-trees seem to be more so really for any entities on the map such as tree's, plants, players, moving sprites etc, am I correct?

Currently, if I up the n value of the terrain generation class, it slows things down a hell of a lot, even changing from 7 to 9 slows my fps down dramatically, despite still only rendering tiles within the view port. I do wish to do massive sized game worlds that take a very long time for the player to traverse, and I think the only way i'm going to be able to do that is rendering in chunks. I just have to work out what the best way of doing this is. Is quad-trees sufficient for this? Or should I use some other method?

I understand the concept of quad-trees, it's pretty straight forward, but once again, it's the implementation that has me scratching my head (although, I haven't really TRIED to implement it how I think I would yet).

Currently, this is my code to render tiles within the viewport for those interested:

x0, y0 = bottom left, top left viewport coordinates
x1, y1 = bottom right, top right viewport coordinates

Basically the code is saying that upon that iteration through the world map, if the tile location is within the constraints of the viewport (x0, y0, x1, y1), then draw the tiles to the screen, nothing too fancy going on here.

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  
for(int x = 0; x < map.length; x++){
         w = (float) (x * .5);
         
         for(int y = 0; y < map[x].length; y++){
            h =  (float) (y * .5);
           
            if (w > x0 + 3 && h > y0 + 3 && w < x1 - 3 && h < y1 - 3){ //if x,y position of tile upon this iteration is within viewport, render tiles within loop
              if(map[x][y] == 0){
                  batch.draw(deepwater, w, h, scalex, scaley);
               };
     
               if (map[x][y] ==1){
                  batch.draw(water, w, h, scalex, scaley);
               }
   
               if (map[x][y] ==2){
                  batch.draw(shallowwater, w, h, scalex, scaley);
               };
   
               if (map[x][y] ==3){
                  batch.draw(wetsand, w, h, scalex, scaley);
               };
   
               if (map[x][y] ==4){
                  batch.draw(sand, w, h, scalex, scaley);
               };
   
               if (map[x][y] ==5){
                  batch.draw(grass, w, h, scalex, scaley);
               };
   
               if (map[x][y] ==6){
                  batch.draw(darkgrass, w, h, scalex, scaley);              
               };
   
               if (map[x][y] ==7){
                  batch.draw(lowmountain, w, h, scalex, scaley);
               };
   
               if (map[x][y] ==8){
                  batch.draw(highmountain, w, h, scalex, scaley);
                 
               };
   
               if (map[x][y] ==9){
                  batch.draw(mountainpeak, w, h, scalex, scaley);
               };
            }
         }
      }
28  Game Development / Game Play & Game Design / Re: [LibGDX] 2D (top down) procedurally generated terrain. on: 2013-08-10 11:06:38
Ah ok, thankyou for correcting me, I honestly didn't know :O
I just kept seeing the term oct-trees being used a lot when people were talking about rendering chunks of a map.
Thinking about that now, all of the references were made in relation to games like minecraft, not a top down 2d game -_- (massive durp!).

So quad-trees makes more sense, I shall read up about them, thanks for correcting me Smiley

I was reading before about using a chunk of tiles to create one texture as you just described Smiley
I was thinking about getting to work on that tonight, but so far, all i've done today, other than a few little optimizations and uploading a youtube video showing results, is reading, reading, reading Tongue

As for what I am going to do with the terrain, I won't say just yet, it is a mystery for the time being.
But my intentions are obvious to make something awesome and fresh to the gaming scene (no surprise there!).

Clearly though, it involves sea-faring, and procedurally generated terrain. Tongue
As I develop this more into a game, more will be revealed, but until I have something that resembles an actual game, I won't be saying exactly what it is, as much as I would like to Tongue


29  Game Development / Game Mechanics / Re: [LibGDX] How to Make Game HUD and UI? on: 2013-08-10 09:03:27
I am just gonna drop this one in here. It is a good series of LibGDX tutorials which include UI stuff.
http://www.youtube.com/playlist?list=PLXY8okVWvwZ0qmqSBhOtqYRjzWtUCWylb

Also this.
http://www.youtube.com/playlist?list=PLXY8okVWvwZ0JOwHiH1TntAdq-UDPnC2L

There are a few other tutorials out there which cover more in depth on how to create your own UI, menu, splash screens, inventory etc etc.
30  Game Development / Game Play & Game Design / Re: [LibGDX] 2D (top down) procedurally generated terrain. on: 2013-08-10 06:03:12
UPDATE:

Here is the great result of optimization in action Smiley

After putting tiles into a textureAtlas, FPS doubled.

After implementing some frustum culling, FPS is...well, I really don't know, but it's running at a steady 60fps, even when zoomed out.

Next up, I need to research Octrees and/or other chunk rendering methods in combination with frustum culling.

<a href="http://www.youtube.com/v/8k8oLnWopMw?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/8k8oLnWopMw?version=3&amp;hl=en_US&amp;start=</a>
Pages: [1] 2 3
 

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

The first screenshot will be displayed as a thumbnail.

pw (11 views)
2014-07-24 01:59:36

Riven (10 views)
2014-07-23 21:16:32

Riven (11 views)
2014-07-23 21:07:15

Riven (12 views)
2014-07-23 20:56:16

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

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

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

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

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

Riven (50 views)
2014-07-14 18:02:53
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!