Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (581)
Games in Android Showcase (162)
games submitted by our members
Games in WIP (632)
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 4
1  Game Development / Newbie & Debugging Questions / Re: LibGdx - perline noise on: 2015-05-21 22:23:03
All my worlds have variable size (and are stored in 16x16 chunks when saved or transmitted from server to client) so there is no defined height or width. In the image I gave you the world happens to be 1024x512. The code is merely like a percentage of how much of what per column. Dirt and whatnot is generated from the BOTTOM of the dirt layer to the top, ending with a grass block at the top. The stone is generated from the bottom of the dirt layer to the very bottom of the world.

Also, having a separate object for every block in the world will quickly eat up memory. You should have one instance of a block that you will reuse over and over.
2  Game Development / Newbie & Debugging Questions / Re: LibGdx - perline noise on: 2015-05-21 14:49:39
I did some basic terrain generation a while ago using OpenSimplex noise. It turned out pretty good:


The steps went a bit like this:
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  
float hillCoeff = 8f;
      float terrainLimit = hillCoeff + (sizey / 8);
      int dirtLimit = Math.round(hillCoeff + (sizey / 8));
      int caveStart = dirtLimit - (sizey / 32);
       
                // generate the hills
      for (int i = 0; i < sizex; i++) {
         float noise = (float) noiseGen.eval(i * 0.15f, -1 * 0.15f);
         int actualHeight = Math.round(noise * hillCoeff);

         int topOfDirt = actualHeight + (sizey / 16);
         int endOfDirt = actualHeight + (sizey / 8);
         for (int y = endOfDirt; y >= topOfDirt; y--) {
            setBlock(Blocks.instance().getBlock("dirt"), i, y);
         }
         setBlock(Blocks.instance().getBlock("grass"), i, actualHeight + (sizey / 16));

         for (int y = endOfDirt; y < sizey; y++) {
            setBlock(Blocks.instance().getBlock("stone"), i, y);
         }

         // long cave under surface to cover up noise's abrupt end
         for (int y = caveStart - Math.round(4 * noise) - 6; y < caveStart
               + Math.round(3 * noise) + 3; y++) {
            setBlock(Blocks.instance().getBlock("empty"), i, y);
         }
      }

      /* NOTES
       * Terrain upper limit is essentially 1 * hillCoeff + (sizey / 8)
       * dirt ends at around hillCoeff + (sizey / 8)
       * noise ends at dirtLimit - (sizey / 32)
       * caves start at dirtLimit - (sizey / 32)
       *
       */

               
                // generate the caves
      float caveStartThreshold = 0.56f;
      float caveEndThreshold = 0.825f;
      for (int x = 0; x < sizex; x++) {
         for (int y = caveStart; y < sizey; y++) {
            float noise = (float) noiseGen.eval(x * 0.1f, y * 0.1f);
            noise = (noise + 1) / 2f;
            if (noise >= caveStartThreshold && noise <= caveEndThreshold) {
               setBlock(Blocks.instance().getBlock("empty"), x, y);
            }
         }
      }

Github code here.

The code generated the hills using 1D noise (that's actually 2D, but the Y dimension is always -1), and added a cave at the bottom that's a bit like the inverse of the hill heights. This is to cover up the cave generation stub.

Caves are generated with 2D noise and a min-max value. If the noise function returns a value (which is changed to 0-1 for ease) that is between the min and max it will set the block to air. Likewise, you could do the same thing except for ore deposits or different types of stone, etc. before cave generation.

I hope that helps! If you need me to explain more I can!
3  Game Development / Newbie & Debugging Questions / Re: Lighting Woes (Part 1) on: 2015-05-20 03:49:24
17 days later...

I fixed the issue!

WARNING COMPLICATED THINGS BELOW

I rendered the world (without lighting) to a frame buffer. I rendered just the lighting "shadows" to another frame buffer. I rendered the world to the screen. I switched the shader to a masking shader I made here, set the mask to the world, and rendered the lighting buffer.

Code is here.

I will attempt to break it down now.

I render the world to a frame buffer (it's like a frame but stored in RAM). I do the same with the lighting shadows.

I render the background (the starry sky).
I render the world buffer to the screen. This is what's actually drawn.
I render the lighting buffer to the screen using the shader mentioned above so that it becomes masked. Imagine the shadow as a piece of paper, and the world is the stencil in which you trace on the paper. What you traced is what's left. Therefore, the traced shadow will only overlay on the blocks, and not the background.

Example:
4  Discussions / General Discussions / Re: Contacted by a publisher to be a technical reviewer on: 2015-05-13 00:02:02
They said they found me through my github profile. I'm guessing they have a bot to comb over some active github profiles and see if any one of the projects has "libgdx" in it. If they did they would request a human to look it over. I don't have my age on my github profile.

I copied the table of contents they sent over and the pdf of their reviewer information to google drive.
Table of Contents
Reviewer Information

Like I said earlier, I'm not interested in this any more(let alone the time).
5  Discussions / General Discussions / Re: Contacted by a publisher to be a technical reviewer on: 2015-05-11 22:36:38
I did some more googling about them and many people have said they've never gotten their books after reviewing the book. I think I'll ignore the email for now, thanks for your opinions.
6  Discussions / General Discussions / Re: Contacted by a publisher to be a technical reviewer on: 2015-05-11 14:58:32
I am not getting paid, I'm only getting paid in books. Maybe if I take the offer, I might give away the ebook they give me, haha.

I looked up the legal age for work in my province (BC) and they "require written parental permission" if I get paid money (I'm turning 15 in Sept.). So either way, I can't really be paid.
7  Discussions / General Discussions / Contacted by a publisher to be a technical reviewer on: 2015-05-11 14:38:16
I was contacted this morning by "PACKT Publishing" to be a technical reviewer for their book on libgdx and whatnot. They want me to look over their book, see what's wrong, get 2 free copies of it (print or digital) and an extra ebook of any other book free. Not bad!

I asked them for a table of contents (to see what topics they cover).

What should I do? Should I accept it? This is the first time someone's ever contacted me for this.
8  Game Development / Newbie & Debugging Questions / Re: [LibGDX] How to viewport? on: 2015-05-10 04:03:01
SpriteBatch will use its' default camera with a width and height set to the window size when you do not set the projection matrix. The reason the texture shows up in the center when you do set the projection matrix to your camera, however, is because by default an OrthographicCamera has (0, 0) set to the center of the screen. If you instead do this:

1  
2  
OrthographicCamera camera = new OrthographicCamera();
camera.setToOrtho(false, 800, 600);

The camera will have a width and height of 800x600 and a position of (0, 0) in the bottom left corner. The first parameter species whether you want the y-values increasing up or down the screen. False for up, true for down. This should give you the results you want. Cheesy

Can confirm, moving my width and height for the camera to the camera's constructor caused everything to be offset to the middle. Thanks for sharing! Also, you'll still need to set the batch to the combined matrix of the camera.
9  Game Development / Newbie & Debugging Questions / Re: [LibGDX] How to viewport? on: 2015-05-10 02:24:06
But setting the projection matrix would then mean that whatever is rendered in that batch is now in a so called "World" position. Meaning the position is no longer relative to the camera instead it has world coordinates. If I create the camera with the desired width and height and not set the batch's projection matrix, it will stay at the scale of the only texture I have. If I DO set the batch's projection matrix as the camera, the camera will indeed scale up to the resolution I want (In this case 1280x720), but then the 800x600 texture I have will now be in a sort of "World" space and still be 800x600. Is there something I'm not understanding that is crucial to this?  Huh

Edit: Also, can the game also be stretched down, and how would I hand HUD displays if I have to set the projection matrix for the batch for the game to scale?

This is what I'm understanding: You want the screen size to be 1280x720, but the game should be drawn as if it were 800x600.

If that were the case, keep the camera at 800x600 and make the window size 1280x720. This only works if you want to stretch it (or shrink it) to the window size. As I mentioned earlier, you don't need a viewport for this method.
10  Discussions / Miscellaneous Topics / Re: What I did today on: 2015-05-08 21:11:14
Roll Eyes Achieved 150 days of GitHub streak today Shocked

Congratulations! Now I don't feel guilty for only contributing one thing for the streak anymore  Tongue
11  Game Development / Newbie & Debugging Questions / Re: [LibGDX] How to viewport? on: 2015-05-08 14:30:32
If you want the game to simply stretch to any resolution, you don't even need a viewport. Just set a camera to your desired "render" width and height, then update the camera and set the batch matrix to the camera's combined matrix. The camera will do the work for you.

If you want the game to have black bars on the sides, you'll need a viewport, although I haven't dabbled into that quite yet.
12  Game Development / Game Mechanics / Re: Sharing components between the game screens (LibGDX) on: 2015-05-06 22:12:20
Since you only need one instance of it, you could make it static, like orelb said. You could also use the singleton design pattern.
13  Game Development / Newbie & Debugging Questions / Re: How to order the way in which objects are rendered? on: 2015-05-03 02:02:32
To go over CopyableCougar4's method (which is preferred), the Comparator interface has a method called compare(Object first, Object second). It returns either -1, 0, or 1. It returns -1 if the first object is "less than" the second. It returns 0 if they're equal, and returns 1 if the first object is "greater than" the second object. You could return it based on layer. As Ashedragon said, don't sort every frame, but maybe you should sort when an entity is added (not removed because that shouldn't have an effect on the sorted array/list).
14  Game Development / Newbie & Debugging Questions / Re: Lighting Woes (Part 1) on: 2015-05-02 23:42:40
Everything you just said can be done with the GPU so it's quite efficient.

Tinting a sprite seems easy enough (I don't know what you're using to make your game, so I can't really answer this yet). You would specify the colour and alpha value. No need for multiple spritesheets.

As for tinting a part of a sprite, I'm sure there's a way to draw a "part" of a sprite.

Example code (libgdx):
1  
2  
batch.setColor(0, 0, 0, 0.25f); // set the batch colour to black, 1/4 transparent
batch.draw(sprite, x, y, width, height, 0.25f, 0.25f, 0.75f, 0.75f); // draw the sprite at x, y with width and height, rendering only the given area


UV in textures works like this:
15  Game Development / Newbie & Debugging Questions / Re: Getting rid of an object on: 2015-05-02 15:41:54
I'm assuming you're storing your Bullets in some form of list, perhaps an ArrayList. ArrayList has some methods that you can use to remove things. They are:
1  
2  
3  
4  
remove(int)
remove(Object)
removeAll(Collection)
removeRange(int start, int end)


The first method removes the object at the index number you specify. This is the fastest method because compared to the next method (remove(Object)), it doesn't have to search the list for said object.
The second object removes the object you specify, if it exists. This is ever so slightly slower because it searches for the object first.
The third and fourth object is for removing bunches of objects. Since you're only removing one Bullet class at a time, I don't think you'll need these two just yet.

Basically, when your bullet hits an enemy and deals damage, you can call the remove method on the list containing the bullet objects.

If you want to be more efficient (warning, more advanced content):
You could "pool" bullets. Creating and removing an object every single time isn't great for memory, and the JVM has to constantly re-instantiate objects. You could "pool" them instead. Pooling is storing leftover objects to be reused for later! Here's a good wiki article on pooling (it's for libgdx, but the concept is still the same).
16  Game Development / Newbie & Debugging Questions / Re: Lighting Woes (Part 1) on: 2015-05-01 21:37:40
... I just realized my entities rely on the lighting shadows I just removed (for background) for "lighting". Oops.

Manipulating an image in real time is EXTREMELY slow. What I suggest is to render the normal image, then render the same image (or part of it) again right on top, with transparency and tint for lighting. I'll need to solve this myself; after I do I'll share results on what I did.
17  Game Development / Newbie & Debugging Questions / Re: Lighting Woes (Part 1) on: 2015-05-01 15:08:27
I just realized I have the same problem, so I'll solve it with you  Tongue

In your lighting engine, for each update, you could tag if a block is "in the sky" (while loop starting at the top of the world, you don't have to do the entire world at once, just what's around the player). "In the sky" means it's (probably) air blocks. If you could imagine taking the paint bucket tool in Paint, and filling the sky, that would be the effect.

When you're doing your shadow rendering, if it's "in the sky" you don't have to render it. However, trees won't get any light on them, so you'll have to apply lighting to them afterwards by doing these steps:
1) Render the tree with full brightness.
2) For each light level, render that "part" of the tree in black and an alpha value suitable for light. This simulates a shadow.
3) If you're doing coloured lighting, the colour you use to tint the tree part should be a mix of black and the light colour, however you should've already pre-calculated the light colour.

I hope that helps! I need to go implement this too now.
18  Discussions / Miscellaneous Topics / Re: screen scraping as a hacking method? on: 2015-04-30 22:22:40
Possibly they have decompiled your code (which is fairly easy) and implemented their own event listener, and fed in mouse clicks using the Robot class. It could be an inside job  Tongue
19  Game Development / Newbie & Debugging Questions / Re: 1D Perlin Noise on: 2015-04-29 23:11:08
I recently did something exactly like this! It had hills and a cave system (1D then 2D simplex noise respectively). I used OpenSimplex noise. I had a problem where the caves and hills were extremely rough (absolutely no pattern whatsoever). The kind folks here told me I was using an overly-large amplitude (the coefficient of the coordinates), so when I changed it to something small (times 0.15, for example) it looked perfect.

Some sample code here (very WIP): https://github.com/chrislo27/ProjectMP/blob/master/core/src/projectmp/common/world/World.java#L136-L182

For hills, I took the coordinates at X, -1 with an amplitude of 0.15. For caves, I took the X, Y coordinates (amplitude 0.1), reduced the float it gave me to a value between 0 and 1, and checked if it were in between two thresholds (in this case it was 0.56 and 0.825, these were just tuning over and over again until it looked good). If it were, it was empty. It gives really good results such as this one: http://i.imgur.com/iygn1B1.png

There's also a big cave near the surface to cover up the abrupt stop of the cave generation (it's kinda like the inverse of the hills).
20  Game Development / Game Play & Game Design / Inventory and sorting on: 2015-04-27 04:34:57
Hi

I'd like to get some opinions/feedback on how you guys prefer the sorting of items between containers. This means "how do you prefer to move an item from your player's inventory into another inventory". For example, there's the Minecraft style (clicking swaps the contents of your cursor with the slot), and the "swap" style (clicking an item automatically moves it to the first available slot in the other container). There are many more than what I listed, but I'm just looking for a general opinion of what fits best for you.

Thanks!
21  Games Center / WIP games, tools & toy projects / Re: Pantless Hero on: 2015-04-27 04:00:20
What do you guys think about the new graphics?

They fit in a lot better! The main character has a finer detail, he kinda looks out of place when everything else around him is in lower detail. It's looking really good so far!
22  Game Development / Newbie & Debugging Questions / Re: [LibGdx] Best way to handle textures for hundreds of objects? on: 2015-04-26 15:52:46
If you have one texture that's re-used for many objects, DO NOT load them over and over and over... because you'll have to dispose of them later!

Libgdx's AssetManager is a great way to load the textures at runtime. You can call the update method to load them in your loading screen. When you want to get a loaded asset, you can call
1  
manager.get("filepathhere", Texture.class)
The only downside to this is you'll have to remember the entire filepath, so what I did was make a singleton class that stored a list of keys and values. You could reference a filepath by a nickname you gave it. Some code I have from a project is here. AssetManager also has a handy dispose method that disposes everything it has loaded.
23  Game Development / Newbie & Debugging Questions / Re: [libgdx] Drawing gradient with vertices producing diagonal line artefact on: 2015-04-26 04:18:02
I tried using a mesh. So far it renders but it's solid white. I'll have to come back to this tomorrow; it's been a long day.

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  
private static float[] gradientverts = new float[16];
   private static Mesh gradientmesh = null;

   public static void drawGradient(SpriteBatch batch, float x, float y, float width, float height,
         Color bl, Color br, Color tr, Color tl) {
      if (gradientmesh == null) {
         gradientmesh = new Mesh(false, 4, 4, new VertexAttribute(Usage.Position, 3,
               "a_position"), new VertexAttribute(Usage.ColorPacked, 4, "a_color"));
         gradientmesh.setIndices(new short[] { 0, 1, 2, 3 });
      }
     
      // bottom left
      gradientverts[0] = convertScreenXToMesh(x);
      gradientverts[1] = convertScreenYToMesh(y);
      gradientverts[2] = 0;
      gradientverts[3] = bl.toFloatBits();
     
      // bottom right
      gradientverts[4] = convertScreenXToMesh(x + width);
      gradientverts[5] = convertScreenYToMesh(y);
      gradientverts[6] = 0;
      gradientverts[7] = br.toFloatBits();
     
      // top right
      gradientverts[8] = convertScreenXToMesh(x + width);
      gradientverts[9] = convertScreenYToMesh(y + height);
      gradientverts[10] = 0;
      gradientverts[11] = tr.toFloatBits();
     
      // top left
      gradientverts[12] = convertScreenXToMesh(x);
      gradientverts[13] = convertScreenYToMesh(y + height);
      gradientverts[14] = 0;
      gradientverts[15] = tl.toFloatBits();
     
      gradientmesh.setVertices(gradientverts);
     
      gradientmesh.render(defaultShader, GL20.GL_TRIANGLE_FAN, 0, gradientverts.length);

   }
   
   public static float convertScreenXToMesh(float x){
      return (x / Settings.DEFAULT_WIDTH) * 2 - 1;
   }
   
   public static float convertScreenYToMesh(float y){
      return (y / Settings.DEFAULT_HEIGHT) * 2 - 1;
   }
24  Game Development / Newbie & Debugging Questions / Re: [libgdx] Drawing gradient with vertices producing diagonal line artefact on: 2015-04-26 03:46:12
I found a class called Mesh. It has vertices and whatnot blah blah blah but you can render it with a ShaderProgram (I'm assuming default shader works?) and a primitive type. I'll try this out.

SHC, thanks for suggesting the TRIANGLE_FAN! I'll try it and see what happens!
25  Games Center / WIP games, tools & toy projects / Re: Lost Luggage - a simple play-on-the-bus game on: 2015-04-25 22:55:55
Looks pretty good so far! It seems like my type of game; something I can play to kill time.

Since you said you're using Slick2D, if you want to package a jar, you should use JarSplice. It packages the libraries for you into one runnable jar.

Maybe you should port it over to libGDX. You can easily deploy to other platforms (Android, PC, iOS, HTML) using the same base code. It also has a handy way of packaging all the things you need into a jar inside Eclipse.
26  Game Development / Newbie & Debugging Questions / Re: [libgdx] Drawing gradient with vertices producing diagonal line artefact on: 2015-04-25 17:45:31
Instead of using triangles, directly render a quad using GL_TRIANGLE_FAN. Then it should be only one shape, and the artifacts will be smaller I think. Not quite sure on this though.

Do you have an example of how I could implement this? I haven't really worked with lower-level things, mostly with libraries that do the work for me.  Tongue
27  Game Development / Newbie & Debugging Questions / Re: [libgdx] Drawing gradient with vertices producing diagonal line artefact on: 2015-04-25 16:53:25
I'm going to leave this as-is because as LiquidNitrogen said, actual textures on the blocks will help to not make the effect so visible.

Thanks for your help!
28  Game Development / Newbie & Debugging Questions / Re: [libgdx] Drawing gradient with vertices producing diagonal line artefact on: 2015-04-25 03:49:44
I did what you said (4 triangles, avg. colour in the middle). It's definitely better, but now there are visible lines on both directions, showing where each triangle's boundary is.



Code now:
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  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
   private static float[] gradientverts = new float[20];
   private static Color tempGradientColor = new Color();

   public static void drawGradient(SpriteBatch batch, float x, float y, float width, float height,
         Color bl, Color br, Color tr, Color tl) {
      tempGradientColor.set((bl.r + br.r + tr.r + tl.r) / 4f, (bl.g + br.g + tr.g + tl.g) / 4f,
            (bl.b + br.b + tr.b + tl.b) / 4f, (bl.a + br.a + tr.a + tl.a) / 4f);
      int idx = 0;
     
      // draw bottom face
      idx = 0;
      gradientverts[idx++] = x + (width / 2);
      gradientverts[idx++] = y + (height / 2);
      gradientverts[idx++] = tempGradientColor.toFloatBits(); // middle
      gradientverts[idx++] = 0.5f;
      gradientverts[idx++] = 0.5f;
      gradientverts[idx++] = x + (width / 2);
      gradientverts[idx++] = y + (height / 2);
      gradientverts[idx++] = tempGradientColor.toFloatBits(); // middle
      gradientverts[idx++] = 0.5f;
      gradientverts[idx++] = 0.5f;
     
      gradientverts[idx++] = x;
      gradientverts[idx++] = y;
      gradientverts[idx++] = bl.toFloatBits(); // bottom left
      gradientverts[idx++] = filltexRegion.getU(); //NOTE: texture coords origin is top left
      gradientverts[idx++] = filltexRegion.getV2();
     
      gradientverts[idx++] = x + width;
      gradientverts[idx++] = y;
      gradientverts[idx++] = br.toFloatBits(); // bottom right
      gradientverts[idx++] = filltexRegion.getU2();
      gradientverts[idx++] = filltexRegion.getV2();
     
      batch.draw(filltexRegion.getTexture(), gradientverts, 0, gradientverts.length);

      // draw top face
      idx = 0;
      gradientverts[idx++] = x + (width / 2);
      gradientverts[idx++] = y + (height / 2);
      gradientverts[idx++] = tempGradientColor.toFloatBits(); // middle
      gradientverts[idx++] = 0.5f;
      gradientverts[idx++] = 0.5f;
      gradientverts[idx++] = x + (width / 2);
      gradientverts[idx++] = y + (height / 2);
      gradientverts[idx++] = tempGradientColor.toFloatBits(); // middle
      gradientverts[idx++] = 0.5f;
      gradientverts[idx++] = 0.5f;
     
      gradientverts[idx++] = x;
      gradientverts[idx++] = y + height;
      gradientverts[idx++] = tl.toFloatBits(); // top left
      gradientverts[idx++] = filltexRegion.getU();
      gradientverts[idx++] = filltexRegion.getV();

      gradientverts[idx++] = x + width;
      gradientverts[idx++] = y + height;
      gradientverts[idx++] = tr.toFloatBits(); // top right
      gradientverts[idx++] = filltexRegion.getU2();
      gradientverts[idx++] = filltexRegion.getV();
     
      batch.draw(filltexRegion.getTexture(), gradientverts, 0, gradientverts.length);

      // draw left face
      idx = 0;
      gradientverts[idx++] = x + (width / 2);
      gradientverts[idx++] = y + (height / 2);
      gradientverts[idx++] = tempGradientColor.toFloatBits(); // middle
      gradientverts[idx++] = 0.5f;
      gradientverts[idx++] = 0.5f;
      gradientverts[idx++] = x + (width / 2);
      gradientverts[idx++] = y + (height / 2);
      gradientverts[idx++] = tempGradientColor.toFloatBits(); // middle
      gradientverts[idx++] = 0.5f;
      gradientverts[idx++] = 0.5f;
     
      gradientverts[idx++] = x;
      gradientverts[idx++] = y + height;
      gradientverts[idx++] = tl.toFloatBits(); // top left
      gradientverts[idx++] = filltexRegion.getU();
      gradientverts[idx++] = filltexRegion.getV();
     
      gradientverts[idx++] = x;
      gradientverts[idx++] = y;
      gradientverts[idx++] = bl.toFloatBits(); // bottom left
      gradientverts[idx++] = filltexRegion.getU(); //NOTE: texture coords origin is top left
      gradientverts[idx++] = filltexRegion.getV2();
     
      batch.draw(filltexRegion.getTexture(), gradientverts, 0, gradientverts.length);

      // draw right face
      idx = 0;
      gradientverts[idx++] = x + (width / 2);
      gradientverts[idx++] = y + (height / 2);
      gradientverts[idx++] = tempGradientColor.toFloatBits(); // middle
      gradientverts[idx++] = 0.5f;
      gradientverts[idx++] = 0.5f;
      gradientverts[idx++] = x + (width / 2);
      gradientverts[idx++] = y + (height / 2);
      gradientverts[idx++] = tempGradientColor.toFloatBits(); // middle
      gradientverts[idx++] = 0.5f;
      gradientverts[idx++] = 0.5f;
     
      gradientverts[idx++] = x + width;
      gradientverts[idx++] = y + height;
      gradientverts[idx++] = tr.toFloatBits(); // top right
      gradientverts[idx++] = filltexRegion.getU2();
      gradientverts[idx++] = filltexRegion.getV();
     
      gradientverts[idx++] = x + width;
      gradientverts[idx++] = y;
      gradientverts[idx++] = br.toFloatBits(); // bottom right
      gradientverts[idx++] = filltexRegion.getU2();
      gradientverts[idx++] = filltexRegion.getV2();

      batch.draw(filltexRegion.getTexture(), gradientverts, 0, gradientverts.length);

   }


I had to do a bit of trickery to make sure there were four vertices "per triangle". This is probably the cause of the creases, isn't it...
29  Game Development / Newbie & Debugging Questions / [libgdx] Drawing gradient with vertices producing diagonal line artefact on: 2015-04-25 01:57:43
I'm drawing a gradient using the SpriteBatch method draw(Texture, float[], int, int) that takes an array of vertices and other data alongside a texture and renders it to screen. I set each corner to a specific colour, and it renders it pretty well. However, I've noticed an artefact of sorts. There's a line going bottom-left to top-right that doesn't "seem" correct.



On the coloured (red green blue white) gradient, you don't really notice it. If you turn your head and look at it on your monitor from an angle, it becomes extremely visible. You can also see the lighting on the blocks how there's lines going top-left-to-bottom-right making it look jagged.

The gradient code is a modified version of davedes horizontal/vertical code here made to fit with four colours instead of only two. I am not using ShapeRenderer because its alpha blending (even with blending turned on) doesn't exactly work very well.
Gradient code:
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  
private static float[] gradientverts = new float[20];

   public static void drawGradient(SpriteBatch batch, float x, float y, float width, float height,
         Color bl, Color br, Color tr, Color tl) {
      int idx = 0;
      gradientverts[idx++] = x;
      gradientverts[idx++] = y;
      gradientverts[idx++] = bl.toFloatBits(); // bottom left
      gradientverts[idx++] = filltexRegion.getU(); //NOTE: texture coords origin is top left
      gradientverts[idx++] = filltexRegion.getV2();

      gradientverts[idx++] = x;
      gradientverts[idx++] = y + height;
      gradientverts[idx++] = tl.toFloatBits(); // top left
      gradientverts[idx++] = filltexRegion.getU();
      gradientverts[idx++] = filltexRegion.getV();

      gradientverts[idx++] = x + width;
      gradientverts[idx++] = y + height;
      gradientverts[idx++] = tr.toFloatBits(); // top right
      gradientverts[idx++] = filltexRegion.getU2();
      gradientverts[idx++] = filltexRegion.getV();

      gradientverts[idx++] = x + width;
      gradientverts[idx++] = y;
      gradientverts[idx++] = br.toFloatBits(); // bottom right
      gradientverts[idx++] = filltexRegion.getU2();
      gradientverts[idx++] = filltexRegion.getV2();

      batch.draw(filltexRegion.getTexture(), gradientverts, 0, gradientverts.length);
   }


filltexRegion is a TextureRegion that contains a Texture of a 1x1 white square (generated by a pixmap at runtime).

Thanks!
30  Discussions / General Discussions / Re: Check network state in libGDX on: 2015-04-22 14:36:49
You could ping a website that's generally always available (eg: google.com). If it times out then you don't have a connection.
Pages: [1] 2 3 4
 
Waterwolf (22 views)
2015-05-20 15:01:45

chrislo27 (26 views)
2015-05-20 03:42:21

BurntPizza (60 views)
2015-05-10 15:53:18

FrozenShade (46 views)
2015-05-07 09:11:21

TheLopais (209 views)
2015-05-06 13:36:48

TheLopais (193 views)
2015-05-06 13:35:14

TheLopais (200 views)
2015-05-06 13:33:39

TheLopais (217 views)
2015-05-06 13:32:48

TheLopais (215 views)
2015-05-06 13:31:28

ClaasJG (237 views)
2015-04-30 20:33:25
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

Resources for WIP games
by kpars
2014-12-18 10:26: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
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!