Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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]
1  Game Development / Newbie & Debugging Questions / Re: Array Of Sub-Classes on: 2016-03-23 11:25:57
The most straightforward approach would be to create an enum (with a name such as "ItemTypes") where you manually create an entry representing each item type. You can pass a reference to the corresponding class object into each enum entry's constructor. You can then use reflection with that class object to instantiate item objects. If that is too slow, you can provide a factory lambda to each enum as well.

This may be a tedious process. The only real alternative is to use a library such as to scan your classes at runtime and find every class within a particular package or marked with a particular annotation. You could then store the results in a HashMap allowing access by item name.
2  Game Development / Newbie & Debugging Questions / Re: How to check if v-sync is actually enabled on: 2013-10-24 05:57:44
Speaking of V-Sync, Nvidia's recently announced G-Sync technology sounds like a really great idea, if such a tech does ever get standardised and become widely adopted, should be pretty nice for smooth looking games and solve the age old V-Sync/tearing problems properly.
All the advantages of V-sync without all the disadvantages of V-sync? Oh, yes.

Yeah but it would take a loooooooooooong time for wide adoption.

It sounds like most games don't need to do anything special to support g-sync. You just need to purchase a monitor that supports it, then turn it on in your driver options. Of course, most people are still using shitty 60hz monitors, so it's going to take a while for the concept of vsync to disappear...
3  Game Development / Game Play & Game Design / Re: Card Battling System on: 2013-10-23 09:24:46
OK so I thought I get some input here since I honestly I have a small infantile knowledge of the Java language (I'm learning as I go). Without giving out too much info, the game is in short a "Mega Man Chip Challenge" or basically an RPG-Like game that uses cards. I was wonder how I should go about implementing the cards...I believe making a class for the cards is the only way to go about it. Each card knows general info about itself, but in battle they can carry out a wide variety of actions.....I was thinking having a method that can read the cards ID number and thus, using a crap ton of else if statements, perform the required actions. I guess what I want to know is basically if there is an easier way to go about the entire thing. Any suggestions?

You are indeed missing the whole point of OOP design... but this is the perfect problem to help you grasp it. You shouldn't be using conditions to implement each card's behavior, instead...

1.) Make an abstract class called Card which contains all of the code that all cards share in common. Abstract classes cannot be instantiated but they can be extended by other classes.
2.) Now make a class for each type of card you want in your game, and have each one extend the Card class. Your subclasses will inherit all of the implemented methods of the parent "Card" class.
3.) Now, put an abstract method in the Card class, such as "doActions". Notice that this prevents your child classes from compiling... abstract methods must be implemented by child classes.
4.) Have each one of the child classes override "doActions"... this is where you can specify the individual behaviors of each card.

Now, whenever you have a variable of type Card, you can store any of the child classes of Card inside of it. You can even store all of your cards in an ArrayList<Card> (or any other generic container class), no matter which type of card it is.

You can call card.doActions() and it will perform the appropriate actions for whichever type of card it is. Try testing it out with debug messages.
4  Game Development / Game Play & Game Design / Re: 2D vs 3D World Immersion on: 2013-10-21 14:21:57
Have you considered using an isometric perspective? It's a nice compromise between 2d and 3d since it allows for depth and immersion, but doesn't require an unreasonable amount of artwork and engine work.
5  Game Development / Newbie & Debugging Questions / Re: How to check if v-sync is actually enabled on: 2013-10-21 14:04:02
Grimmov; the answer is to use a better API.

Java2D has many limitations; its inability to query hardware capabilities is one of the big ones.

This is the most correct answer in the thread... I will do this at some point, but I wanted to get the basics of my game sorted in Java2D before switching to a better API, so that I can understand the differences.

@SHC: as I have explained in depth in this thread, the method you have presented is insufficient for my purposes. Vsync with double buffering is the only way to ensure that each frame is rendered to the screen in sequence without skips, which is the only way to perfectly scroll by the same number of pixels per displayed frame. As I mentioned before, "CPU-sync" has its own limitations.
6  Game Development / Newbie & Debugging Questions / Re: How many tiles should cause lag? [libGDX] on: 2013-10-21 12:09:27
in addition you could also calculate which tiles have to be drawn.

Does this really provide any benefit? Won't objects drawn offscreen take very little time to "draw" since they aren't actually being rendered?
7  Game Development / Newbie & Debugging Questions / Re: How to check if v-sync is actually enabled on: 2013-10-21 10:55:43
I've seen it referred to as CPU sync (as opposed to vsync). It clamps framerate to the target interval by waiting to draw each graphics update. I prefer not to use this method, as non-vsync users can actually get a better experience by allowing graphics to update as quickly as possible, even if they are not rendered, as the frame that does get rendered will be more up-to-date this way. It also interferes with vsync because the CPU sync is not perfectly matched to the vsync rate.

I am trying to attain a level of smoothness that goes beyond the typical methods. In the end, I found that the best appearance was achieved by simply using delta-based scrolling combined with rounding the result to the nearest integer. My main problem with this was that extremely high FPS would cause the result to round down to 0. However, I added a check for this and use the non-rounded value when this happens, and all is well. Effectively it is a hybrid of my previous (vsync and non-vsync) approaches that works well regardless of vsync status, however, it only exhibits the actual smooth scrolling effect while vsync is enabled.

If anyone is curious, I've actually gone so far as to use a concurrent rendering thread while waiting for vsync to finish in my quest for smoothness... This basically gives me the benefits of double buffering (every graphics update is pushed to the screen, necessary for smooth scrolling) and triple buffering (game state and certain graphical updates can continue mid-frame) at the same time. Of course, concurrency leads to nightmares, but after a few days studying the concepts I've gotten a handle on it.
8  Game Development / Newbie & Debugging Questions / Re: How to check if v-sync is actually enabled on: 2013-10-21 02:42:55
Whether vsync works or not just depends upon the conditions of the computer that's running the program. Some people have vsync forced to off in their graphics driver options; some computers just don't support it under certain circumstances. There's no perfect way to predict or observe the outcome from within the code (using java2d at least). In the end this just amounts to an extra graphics option that I wanted to automatically enable if vsync was detected, but now I'll have to leave that up to the end user.

I am currently using java2d; perhaps LibGDX has better vsync support? I somehow doubt it, but I'd be pleasantly surprised if it were true. I do plan to switch to it at a certain point, anyway.
9  Game Development / Newbie & Debugging Questions / Re: How to check if v-sync is actually enabled on: 2013-10-21 02:31:45
You can't just "enable" vsync, you have to create a bufferstrategy and that object internally decides whether to use it or not based on whether it's possible under the current conditions. There seems to be no way to simply ask it whether it's using vsync or not.
10  Game Development / Newbie & Debugging Questions / Re: How to check if v-sync is actually enabled on: 2013-10-21 02:20:34
Edit: Modified for clarity.

@zngga: If you want scrolling to be perfectly smooth, simple delta timing isn't good enough. It will result in an inconsistent number of pixels scrolled per frame. Calculating the distance based upon the time delta then flooring/rounding the result works well, but the result is highly dependent upon the current framerate, since it is functionally very similar to scrolling a specified number of pixels per frame (assuming the framerate stays constant). Either way, absolutely smooth scrolling requires moving the same number of pixels per screen refresh; this makes scrolling speed partly to directly proportional to the current framerate while using this technique. And thus, it is only a good idea if the FPS meets four conditions: 1) not too high, 2) not too low, 3) stable, 4) in sync with the monitor's refresh rate to prevent strobe/tearing effects. VSync ensures that all of these conditions are typically true (assuming the framerate does not drop from rendering issues).

This kind of perfectly smooth scrolling is much more apparent in a low-res pixelated 2d game engine, so it isn't much of an issue in higher-res or 3d games. Perhaps you haven't seen just how smooth it can look while using this technique, but it is very impressive. It makes purely delta-based timing look horrible in a side-by-side comparison.

The downside is that if you attempt this kind of scrolling without vsync, it creates an extremely distracting strobe-like effect, in addition to the typical screen tearing issues.

@opiop65: I agree that it is "hackish"... I suppose I will have to give up on detecting actual vsync status since there seems to be no airtight way to do it.

Instead, I will make "smooth scrolling" a graphics option within my game engine, off by default, and recommend its use only if vsync is enabled. Technically illiterate end-users might wind up turning it on without knowing about vsync, and the smooth scrolling effect will have distracting tears and jerks... but if they notice it looks bad, hopefully they will be smart enough to turn it back off.

11  Game Development / Newbie & Debugging Questions / Re: How to check if v-sync is actually enabled on: 2013-10-21 01:37:55
You can't "always" enable vsync. Sometimes it is not supported or the graphics drivers override it, and then (it seems) there is no way to notice it's off, other than measuring the current framerate.

My rendering engine uses two different scrolling methods; one if vsync is enabled and one if vsync is disabled. The vsync-enabled method looks much nicer because it scrolls at whole pixel intervals per screen refresh, but this makes the scrolling speed (partially) dependent upon the framerate, and should be disabled if vsync is off.

In the end I've settled on measuring whether the current framerate is within +-5% of the monitor's refresh rate. This technique works well because it reverts to the non-vsync method if the rendering rate falls too far below the refresh rate.
12  Game Development / Newbie & Debugging Questions / Re: How to check if v-sync is actually enabled on: 2013-10-21 00:32:21
Yes, I can tell whether vsync is enabled based on my in-game FPS counter... but making my rendering engine's code depend on the average results of the FPS counter to "guess" whether vsync is enabled seems like a very poor solution. Not to mention, framerate fluctuations could trigger false positives or negatives.
13  Game Development / Newbie & Debugging Questions / How to check if v-sync is actually enabled on: 2013-10-20 22:35:11
I've looked for an answer to this question, but to no avail.

When using a BufferStrategy, how can I check whether VSync is currently enabled? I know that it can be overridden to "off" by graphics driver settings, and some situations may not support it, so I'd like to know when it fails so that I can compensate accordingly within my code.

Bonus question: when using triple buffering, is there any way I can synchronize some logic to the vsync pulse, despite my render thread being able to run at unlimited speed?
14  Game Development / Performance Tuning / Allocation during rendering loop on: 2013-10-16 15:46:38
IN GENERAL, is it considered to be a bad idea to perform allocations (the "new" keyword) during the rendering loop of a game? Would be be a better idea to pool/recycle objects such as vectors and positions, or keep everything in terms of raw x/y coordinates? Or is the performance gain from all of this not worth the decrease in code simplicity/readability? Especially if I have the intention to someday port a game to Android, where less memory would be available. I realize this is perhaps an overly generalized question but I'm curious as to how many people pursue this kind of optimization.
15  Game Development / Newbie & Debugging Questions / Re: animation looping using double buffering on: 2013-10-13 11:48:11
I know what a flag and a boolean are... the problem here is the inarticulate nature of the OP's question. Making assumptions in order to answer him won't help him learn to communicate better.
16  Game Development / Newbie & Debugging Questions / Re: animation looping using double buffering on: 2013-10-13 11:36:56
Your question is very unclear-- can you be more precise about what you want the image to do? Do you want to move it in a circle? I also have no idea what you're talking about with a "flag" to "get the image back".
17  Game Development / Newbie & Debugging Questions / Re: Rendering and game loop method for optimal framerate on: 2013-10-12 05:42:21
I tried out your benchmarking program, and the results were confusing.

While in fullscreen mode, I was unable to make my framerate drop below 60 no matter which settings I used. The balls stopped appearing once I reached ~7000.

While in windowed mode, my framerate was initially 400, and it took 22,000 balls before my framerate was reduced to 60.

If I set the the number of buffers to 2 rather than 3, I still had 120 FPS with over 32,000 balls, so I gave up waiting for it to get slower.

So again, my performance seemed superior in windowed mode. This mirrors the behavior I experienced with my own program.
18  Game Development / Newbie & Debugging Questions / Re: Rendering and game loop method for optimal framerate on: 2013-10-11 20:23:06
philfrei, I do happen to be following all of those suggestions... it seems that I am actually using Java2D correctly, it is just slow.

So, here's an update for anyone with similar issues: it turns out that the laptops were refusing to use video acceleration, I think. As an experiment, I set the following flags at the start of the program:

System.setProperty("sun.java2d.d3d", "false");
System.setProperty("sun.java2d.noddraw", "true");
System.setProperty("sun.java2d.opengl", "true");

This caused the laptops to freeze when the program was launched outside of fullscreen exclusive mode (they most likely cannot use OpenGL in windowed mode), but once I also enabled fullscreen, they started running quite well.

I was able to achieve 143 frames per second on the powerful laptop, and about 57 frames per second on the smaller laptop with integrated graphics (and it actually displayed about that many frames, unlike before).

So, here are my current questions:

1) How the heck can I get the laptops to utilize acceleration under D3D? Is it possible, or even desirable?
2) Why does my desktop render so much faster in windowed mode rather than fullscreen dedicated mode?
3) LibGDX or Slick (or something else)? I have read about the differences, but more opinions are nice.

19  Game Development / Newbie & Debugging Questions / Re: Rendering and game loop method for optimal framerate on: 2013-10-11 19:07:42
I will try out LibJDX and see if it improves the consistency of performance... is the general conclusion simply that Java2D is shit and inconsistent for serious games?

By the way, all three of the laptops are runnings Windows 7 or 8 with i5 processors. The computer and the powerful laptop have similarly powerful nVidia graphics cards. I see no reason for the vast performance disparity unless there's just something very inconsistent happening at a low level.
20  Game Development / Newbie & Debugging Questions / Rendering and game loop method for optimal framerate on: 2013-10-11 18:22:17
I'm working on creating my first serious game in Java... right now, it is relatively simple, and merely displays a few hundred BufferedImages and shapes on the screen. I decided to test various combinations of rendering and game loop methods on each of my three computers...

Method one:
Exclusive fullscreen mode, using a BufferStrategy for page flipping, iterate over elements using an infinite loop with no delay.
My main desktop computer gets 145 FPS, powerful laptop gets 33 FPS, small laptop gets 11 FPS.

Method two:
Windowed mode, using javax.swing.Timer for timing, iterate over the elements with each expiration.
Main desktop gets 545 FPS, powerful laptop gets 33 FPS, small laptop gets 31 FPS (but looks laggy like 11 FPS).

Method three:
Windowed mode, using an infinite loop and System.nanoTime() for timing, call repaint() every interval.
Main desktop gets 850 FPS, powerful laptop gets 31 FPS, small laptop gets 31 FPS (but looks laggy like 11 FPS).

To summarize, my desktop computer gets vastly better performance than either of my laptops. But the larger laptop has its own nvidia graphics card and a CPU even faster than my desktop, so I see no reason there should be a performance disparity. (Yes, I did ensure that the laptops are on performance mode, not power saving mode.)

Furthermore, I am puzzled as to why (on the desktop) windowed modes are so much faster than dedicated fullscreen mode. I was under the impression that the advantage of fullscreen dedicated mode is superior performance.

Any insight into these issues would be appreciated.

Pages: [1]
EgonOlsen (75 views)
2018-06-10 19:43:48

EgonOlsen (56 views)
2018-06-10 19:43:44

EgonOlsen (76 views)
2018-06-10 19:43:20

DesertCoockie (256 views)
2018-05-13 18:23:11

nelsongames (156 views)
2018-04-24 18:15:36

nelsongames (155 views)
2018-04-24 18:14:32

ivj94 (896 views)
2018-03-24 14:47:39

ivj94 (157 views)
2018-03-24 14:46:31

ivj94 (809 views)
2018-03-24 14:43:53

Solater (173 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!