Java-Gaming.org Hi !
Featured games (87)
games approved by the League of Dukes
Games in Showcase (670)
Games in Android Showcase (194)
games submitted by our members
Games in WIP (727)
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 ... 45
1  Game Development / Newbie & Debugging Questions / Re: Plant growth on: 2016-04-18 09:17:13
I never used Events class before, could you give an example that has for example 2-3 events implemented for different game objects? Would you use a single instance of Events, or would each object need to have a separate Events instance?

My complaint with your method is that using a decremented/incremented timestamp has a big drawback, which is that it must be advance each game tick. This might not be a problem for a small game, but if your game grows, you might start getting performance problems on certain platforms (mobile for example) if you update thousands of game objects each game tick, when you could only update the ones that are visible on screen. There is another drawback, which is that when you serialise the game object, it will be different each time, because it changes with each game tick.
2  Game Development / Newbie & Debugging Questions / Re: Plant growth on: 2016-04-18 09:04:53
I'd not use actual points in calendar/wallclock time (which could be tampered with when adjusting the local system clock), but instead use time intervals which you increment/decrement in delta steps with your game loop ticks.
So basically this means when the seed is planted you set some "timeToGrow" to 'D' where D is your interval in some time unit.
Then with every tick of your game loop you get the delta time interval elapsed since the last tick (via the monotonic clock System.nanoTime()) and decrement the timeToGrow by that amount (scaled to the appropriate time unit). Once timeToGrow is equal to or smaller than zero, you start to grow your plant.
This also survives savegames: When you want to store and restore the state of your game from some persistent storage without relying on the system's clock (for example when you submit your savegame to another person), you would just store and restore that 'timeToGrow' along with your other necessary state.

That is a bad idea. Don't ever use incremented/decremented timestamp if it will need to be saved/loaded later. The idea that the author had is much better than the one you suggested. My only suggestion would be to have 'gameTime' variable, which is basically like the current time of the device, but you can choose when to advance it.

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  
class Game
{
   public static float Time;

   public void update(float deltaTime) {
      if (!notPaused) {
         // this way its possible to control how the time flows
         // throughout the game. For example, if the game is currently
         // paused or something, you can choose not to advance the game.
         Time += deltaTime;
      }

      // .. update plant logic and stuff later
   }
}

class Plant
{
   private float endTime;
   public void update() {
      if (Game.Time >= endTime) {
         // plant is grown!
      }
   }

   public void startGrowing() {
      int growthTime = 100; // 100 seconds
      endTime = Game.time + growthTime;
   }
}
3  Java Game APIs & Engines / Engines, Libraries and Tools / Re: Java Library written IN Java on: 2016-03-22 20:36:17
Writing custom renderers just for fun is cool, you just need to realize that you only do it for fun and it will not be usable in any real world scenarios.

Actually, there is a good use for software rendering: Occlusion Culling by Software Depth Testing.

Draw a bunch of occlusion bounding boxes with a software renderer into a depthbuffer, then check with another pass if the bounding boxes of any object are hidden by the pixels in the software depthbuffer. Its one of the fastest ways to do occlusion culling; the company Umbra is selling a library that uses this technique.

Someone should write a software renderer for occlusion culling in java...

This is a very specific case. I meant that writing an entire API like OpenGL purely in Java has no real world applications.
4  Java Game APIs & Engines / Engines, Libraries and Tools / Re: Java Library written IN Java on: 2016-03-21 18:47:02
Writing custom renderers just for fun is cool, you just need to realize that you only do it for fun and it will not be usable in any real world scenarios.
5  Game Development / Newbie & Debugging Questions / Re: Nothing written to depth buffer on: 2016-03-06 09:31:20
FINALLY found the problem.

SpriteBatch.begin() call glDepthMask(false) which in turn disables writing to depth buffer.

If I call glDepthMask(true) after SpriteBatch.begin(), everything works fine!!

Yay!  Grin
6  Game Development / Newbie & Debugging Questions / Nothing written to depth buffer on: 2016-03-05 20:59:29
Trying to implement depth testing for 2d isometric game. I have this sample, and it doesn't seem that depth values are written to the depth buffer.

The effect I'm trying to achieve is when second.png is drawn on top of first.png, only red is displayed on screen.
But what I get is that second.png is drawn normally and green part is visible.

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  
   private SpriteBatch mBatch;

   private Texture mSprite1;
   private Texture mSprite2;

   @Override
   public void create() {

      mBatch = new SpriteBatch();
      mBatch.setShader(new ShaderProgram(Gdx.files.internal("test.vsh"), Gdx.files.internal("test.fsh")));

      mSprite1 = new Texture("first.png");
      mSprite2 = new Texture("second.png");

      Gdx.gl20.glEnable(GL20.GL_DEPTH_TEST);
      Gdx.gl20.glDepthFunc(GL20.GL_LESS);
      Gdx.gl20.glDepthMask(true);

   }

   float mx = 0.0f;
   float my = 0.0f;

   private void tick() {
      float speed = 100.0f * Gdx.graphics.getDeltaTime();

      if (Gdx.input.isKeyPressed(Keys.A))
         mx -= speed;
      if (Gdx.input.isKeyPressed(Keys.D))
         mx += speed;
      if (Gdx.input.isKeyPressed(Keys.W))
         my += speed;
      if (Gdx.input.isKeyPressed(Keys.S))
         my -= speed;
   }

   @Override
   public void render() {

      tick();

      Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

      mBatch.begin();

      float scale = 4.0f;

      float x = Gdx.graphics.getWidth() / 2;
      float y = Gdx.graphics.getHeight() / 2;

      mBatch.draw(mSprite1, x - mSprite1.getWidth() / 2 * scale, y - mSprite1.getHeight() / 2 * scale,
            mSprite1.getWidth() * scale, mSprite1.getHeight() * scale);

      mBatch.flush();

      mBatch.draw(mSprite2, mx + x - mSprite2.getWidth() / 2 * scale, my + y - mSprite2.getHeight() / 2 * scale,
            mSprite2.getWidth() * scale, mSprite2.getHeight() * scale);

      mBatch.end();

      int width = Gdx.graphics.getWidth();
      int height = Gdx.graphics.getHeight();
      FloatBuffer buffer = BufferUtils.newFloatBuffer(width * height);
      Gdx.gl20.glReadPixels(0, 0, width, height, GL20.GL_DEPTH_COMPONENT, GL20.GL_FLOAT,
            buffer);

      for (int i = 0; i < width * height; i++) {
         float pixel = buffer.get(i);
         if (pixel != 1.0f) {
            throw new IllegalStateException("OMG IT WORKS!!");
         }
      }
     
      if (Gdx.gl20.glGetError()!=0) {
         throw new Error("OPENGL ERROR: " + Gdx.gl20.glGetError());
      }
   }


vertex shader
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
#ifdef GL_ES
precision mediump float;
#endif

attribute vec3 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;

uniform mat4 u_projTrans;
varying vec4 v_color;
varying vec2 v_texCoord;

void main()
{
   gl_Position = u_projTrans * vec4(a_position, 1);
   v_color = a_color * 2.0;
   v_texCoord = a_texCoord0;
}


fragment shader
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  
#ifdef GL_ES
precision mediump float;
#endif

uniform sampler2D u_texture;

varying vec4 v_color;
varying vec2 v_texCoord;

void main()
{

   vec4 texel = v_color * texture2D(u_texture, v_texCoord);

   if (texel.r > 0)
   {
      gl_FragDepth = 0.0;
   }
   else
   {
      gl_FragDepth = 0.5;
   }


   gl_FragColor = texel;
}


first.png


second.png
7  Game Development / Shared Code / Re: Java assert? on: 2015-10-12 19:32:48
Though you need to specify some flags to VM for them to work, which I haven't figured out yet Cheesy
-ea
(enable assertions)

Yes, I saw that on stackoverflow, but where do I put that if I'm using Libgdx?
8  Game Development / Shared Code / Java assert? on: 2015-10-12 19:28:40
I just found out today that java has built in assertions.

1  
2  
3  
4  
   public void triggerAssert() {
      int number = 100;
      assert number != 100;
   }


Though you need to specify some flags to VM for them to work, which I haven't figured out yet Cheesy

Would be really cool if anyone knows how to make this work in Libgdx.
9  Game Development / Newbie & Debugging Questions / Re: Any libGDX text tutorials? on: 2015-09-14 06:21:03
There are so many questions already posted in various places, that you can just probably google what you want to learn how to do, and there will already be a thread that explains how to do it, or how other people have done it.
10  Game Development / Newbie & Debugging Questions / Re: Better way to store a massive amount of variables on: 2015-09-05 06:46:03
Few hundred lines of code of getters and setters is messy? At my work there is a C++ class, and the header is like 800 lines of code, while the implementation is like 5k or even more. It is pretty much a getter setter class, but I guess you would call it whole other level. I wouldn't call it hard to maintain, because all it is one huge file and nothing more. If you actually need to add / modify something, you are only probably going to look at functions that are no more than 50 lines of code.

There is another class though which is also like 5k lines of code. That class is impossible to maintain if you happen to need to edit something that you shouldn't have. If after you edited something you start getting assserts (thank God at least the class has some of those), you can prepare to go on a long hours journey fixing code that was written assuming no one would ever again touch it. All the code is spaghetti and all the functions depend too much on each other, so in the end it seems like it is few very very big function, even though it has like 100 functions. It has all kinds of code - 2D point path to 3D point path generation, economy logic that is associated with that class and much much more that I'm not sure how to describe. Long story short is should have been long split up into many smaller classes.
11  Game Development / Newbie & Debugging Questions / Re: Grid-based entity collision issues on: 2015-09-03 06:56:20
For debug purposes, try adding a collision check after you have done all your movement code. If the unit doesn't collide before moving, but collides after moving, throw an exception or something and you will know that you made an invalid move.
12  Discussions / Miscellaneous Topics / Generating .java file before compilation during build time on: 2015-09-02 07:33:31
Right now I have 2 build targets: GooglePlay and Amazon. In the Java code, the code has some checks to see what it should do based on the build type. The problem is that each time you want to build for Amazon, you have to manually edit the source Java code to change the build type to Amazon. What would be the best way to generate a .java file during build time, before Java code is compiled? I guess I'm looking for something like Android, which generates R file, which you can access from code.
13  Discussions / Miscellaneous Topics / Re: What I did today on: 2015-08-28 20:42:32
.. got surprised by how smooth the windows 7 build-in "backup and restore" feature works. \o/

Guess they had to make it work properly, because of how much everything breaks in Windows. Cheesy
14  Game Development / Newbie & Debugging Questions / Re: Game has a bunch of short pauses on: 2015-08-28 20:36:15
Maybe you could try recording these short pauses?

EDIT-
I wasn't implying that you have GC pauses, I just described what big GC pauses are caused by. Also, I'm not sure about this, but 200kb of garbage doesn't really mean anything. For all you know you might be allocating two 100kb arrays, or thousands of small objects which would be slower for GC to clean up than a couple of arrays.
15  Game Development / Newbie & Debugging Questions / Re: Game has a bunch of short pauses on: 2015-08-28 06:24:42
Big GC pauses are caused by having a huge heap and a lot of garbage objects being generated.
16  Game Development / Newbie & Debugging Questions / Re: Multiplayer game on Android on: 2015-08-27 09:17:08
I would wonder if it is OK to host a server on a mobile phone. I don't have much MP experience, but I don't think it would be a very good idea to host a server on a phone, unless it is a very small server.
17  Discussions / Jobs and Resumes / Re: [3dFoin] Zombie and August Sale - 50% off all items :D on: 2015-08-24 19:35:20
How is he able to lean backward and forward without having any ABS? Cheesy
18  Game Development / Newbie & Debugging Questions / Re: 2D-MMORPG physics engine on: 2015-08-04 16:57:41
It depends on what you need. I guess for 2D you can go and write your own physics engine, as long as it doesn't include rotations. It also depends on how you want the objects to interact. Though I doubt that you will run into performance problems on modern PCs with Box2D when only having few hundred objects. You should just try to setup a test and see how well it runs.
19  Game Development / Newbie & Debugging Questions / Re: My map load parser is taking ages on android on: 2015-07-29 10:22:34
If you are using Eclipse, there is a Trace View in DDMS Layout. Look at answer by Seppl
http://stackoverflow.com/questions/4850974/how-to-use-traceview-in-eclipse-for-android-development

It will show you how much time was spent executing parts of your code.
20  Discussions / Business and Project Management Discussions / Re: TheGreyLab Development Team Recuritment on: 2015-07-15 08:11:26
Would be nice if you could post a short demo video to show the state of the project.
21  Game Development / Newbie & Debugging Questions / Re: JNI threading > JNIEnv memleaks on: 2015-07-01 04:53:28
Yes, DeatchCurrentThread is being called after every call to Java.

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  
class JNIThread:
{
   public:

   ~JNIThread()
   {
      jvm->DetachCurrentThread();
   }

   bool Attach()
   {
      switch (jvm->GetEnv(m_pEnv))
      {
        case JNI_OK:
           // Thread is ready to use, nothing to do
        break;

        case JNI_EDEATCHED:
           // Thread is detached, need to attach
           jvm->AttachCurrentThread(m_pEnv);
           // AttachCurrentThread probably also returns control value, whether it was a success
        break;
      }

      if (m_pEnv != NULL)
      {
        // If not null, means ready to use
      }

      return m_pEnv;
   }

   JNIEnv* m_pEnv;
}



// Using
funcion
{  
   JNIThread thread;  

   if (thread.Attach())
   {
      // do work
   }

   // thread is detached in destructor
}
22  Game Development / Newbie & Debugging Questions / Re: JNI threading > JNIEnv memleaks on: 2015-06-30 05:47:35
Are you sure that doing ->AttachCurrentThread spawns a new Java thread? I thought it only passes JVM context to your current thread, so that JNI calls are possible from that thread. At my work every call from native to Java (On android) tries to attach the thread if it is not yet attached. I think the code looks something 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  
JNIEnv* getJNIEnv()
{
   JNIEvn* pEnv = NULL;

   switch (jvm->GetEnv(pEnv))
   {
      case JNI_OK:
         // Thread is ready to use, nothing to do
      break;

      case JNI_EDEATCHED:
         // Thread is detached, need to attach
         jvm->AttachCurrentThread(pEnv);
         // AttachCurrentThread probably also returns control value, whether it was a success
      break;
   }

   if (pEnv != NULL)
   {
      // If not null, means ready to use
   }

   return pEnv;
}


Though this probably won't compile, I didn't write the code, not sure what are the exact parameters.
23  Games Center / WIP games, tools & toy projects / Re: Mr.mustache on: 2015-06-16 17:51:36
I think the first thing you should add are wiggling mustaches when pressing S.
24  Game Development / Newbie & Debugging Questions / Re: Best way to save game for a Dungeon Crawler? on: 2015-06-09 09:38:39
If you have never done any serialisation before, I would suggest that the easiest place to start would be using .json.

.json is a tree data structure, in which nodes can have branch nodes of leaf nodes. Simply put, a branch node is a node that contains other branches and leafs, while a leaf node is like a leaf in a real tree. A leaf node might be a string, or an int, float etc. Not going to go into details, you can read more about it on the internet.

http://json.org/

The implementation would look something 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  
49  
50  
51  
52  
53  
54  
55  
56  
public class Level {
   private ArrayList<Entity> entities;

   public JsonObject getSavingJson() {
      JsonObject json;

      JsonArray jsonEntities;
      for (Entity entity : entities) {
         JsonObject jsonEntity = entity.getSavingJson();
         jsonEntities.add(jsonEntity);
      }

      json.add("entities", jsonEntities);

      return json;
   }

   public void loadFromJson(JsonObject json) {
      JsonArray jsonEntities = json.getArray("entities");

      for (int i = 0; i < jsonEntities.size(); i++) {
         JsonObject jsonEntity = jsonEntities.get(i);

         String type = jsonEntity.getString("type");

         Entity entity = null;
         if (type.equals("Entity")) entity = new Entity();
         // else if (type.equals("Player")) entity = new Player();

         entity.loadFromJson(jsonEntity);
      }
   }
}

public class Entity {
   
   private String type = "Entity";

   public JsonObject getSavingJson() {
      JsonObject json;

      json.add("type", type);

      // additional stuff
//      json.add("position", position);
//      json.add("health", health);

      return json;
   }

   public void loadFromJson(JsonObject json) {
      // load your stuff here
//      position = json.get("position");
//      health = json.get("health");
   }
}


25  Games Center / WIP games, tools & toy projects / Re: Flying Cavemen - Inifinite Scroller [LibGDX][Web] on: 2015-05-16 05:16:21
It starts running normally (it seems) and then after the first try or something it seems like it slows down the same like the web version. Maybe you have leaking memory?
26  Games Center / WIP games, tools & toy projects / Re: Flying Cavemen - Inifinite Scroller [LibGDX][Web] on: 2015-05-15 20:19:19
Chrome. My hardware isn't that ancient either. Its not great, but I can play some current gen comes pretty well on low settings. (CSGO, KSP and some others)
27  Games Center / WIP games, tools & toy projects / Re: Flying Cavemen - Inifinite Scroller [LibGDX][Web] on: 2015-05-15 20:11:09
The performance is horrible. I had like 2 fps.
28  Game Development / Newbie & Debugging Questions / Re: Trying to make an object that has a sort of parent object. on: 2015-05-03 14:58:15
Hm, they really should add sroll bar to long lists of code.

Or you should use a pastebin for extraordinary long code dumps.

Quote
Got extraordinary long code dumps? Use http://www.java-gaming.org/index.php?action=pastebin&hex= to keep your thread readable. (link opens in new tab)

29  Java Game APIs & Engines / Engines, Libraries and Tools / [Libgdx] adding a source folder to build path on: 2015-05-03 10:01:46
I was trying to find how to add an additional source folder to gradle build path on google, but I seem to have failed.

Does anybody know how to add source folder to gradle build path?
30  Java Game APIs & Engines / Engines, Libraries and Tools / Re: [LWJGL] Library for rendering text. on: 2015-05-03 09:58:26
(this is kind of self-advertising)

I have made this library that will render text using FreeType in native code. The problem is that it only is available on WINDOWS, ANDROID and the .dll files take up a lot of space (9mb for windows alone).

https://www.mediafire.com/?r8uki5mk83uag1i

If you want the source code, or if you want to try to contribute:
https://github.com/gamingchris3/jfreetype

Here is some 'example' 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  
32  
      JFreeType jfreetype = JFreeType.createInstance();
     
      jfreetype.initialize(true); // the parameter is whether JFreeType should attempt to load native files itself
      // if you pass in false, you need to load native files yourself.
     
      JFreeTypeOptions options = new JFreeTypeOptions();
      options.font = "C:/path/to/font.ttf"; // full path to font file on the file system
      options.text = "A generic string of text"; // the string of text you want to render
      options.size = 20; // the size of the font
      options.width = 10000; // the width at which the size of the font will be reduced if the string is bigger than this number
      options.height = 10000; // the height at which the size of the font will be reduced if the string is bigger than this number
      options.lineSpacing = 0; // when wrapping text, spacing between lines (in pixels)
     
      Bitmap bitmap = jfreetype.render(options);
      int format = bitmap.format; // this can be ignored, right now the only format is alpha (1 byte alpha)
      int width = bitmap.width; // the width of the texture
      int height = bitmap.height; // the height of the texture
      ByteBuffer pixels = bitmap.pixels; // a byte buffer of pixels (the format is 1 byte alpha)
     
      TextMetrics metrics = bitmap.textMetrics; // contains some metrics generated from rendering the string
      int descender = metrics.descender; // the maximum descender of the string
     
     
      jfreetype.setInstantLoggingEnabled(false); // if instant logging is enabled, will print errors / info instantly to default output stream
     
      // If instant logging is disabling, will 'buffer' the messages (up to 128)
      String error = null;
      while ((error = jfreetype.getLog()) != null) {
         System.out.println(error); // prints out error messages?
      }
     
      jfreetype.destroy(); // cleanup?


On the final note, if you decide to try this lib, and something doesn't work, you might want to just drop it entirely, as this is not really a production level library yet.
Pages: [1] 2 3 ... 45
 
IanParcs (36 views)
2016-04-18 14:18:53

KaiHH (36 views)
2016-04-18 08:35:41

KaiHH (67 views)
2016-04-15 12:43:58

theagentd (67 views)
2016-04-14 02:16:17

theagentd (74 views)
2016-04-14 02:15:43

IanParcs (67 views)
2016-04-12 03:51:16

IanParcs (37 views)
2016-04-12 03:50:03

IanParcs (33 views)
2016-04-12 03:49:54

IanParcs (30 views)
2016-04-12 03:49:52

IanParcs (39 views)
2016-04-12 03:49:52
Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50

Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30
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!