Show Posts
|
|
Pages: [1] 2 3 ... 11
|
|
1
|
Game Development / Newbie & Debugging Questions / Re: File Not Found Exception
|
on: 2013-04-17 20:55:39
|
java.io.FileReader doesn't take URLs, or string representations of URLs, as parameters to its constructor; it expects a (local) file path. When you pass a string with "%20" embedded in it to represent a space, the class will assume you mean literally "%20", and not a space character. Hence the file isn't found, because what you passed to it literally does not exist. You need to pass the file name "normally," not URL-encoded. Or use some other construct, such as 1
| new BufferedReader(new InputStreamReader(classLoader.getResourceAsStream("/path/to/resource"))); |
|
|
|
|
|
3
|
Game Development / Newbie & Debugging Questions / Re: Resizing JPanels
|
on: 2013-03-15 05:03:03
|
|
I'm not 100% clear on what you're doing, but if you're adding and removing components at runtime, and want to do things the "right" way (e.g. have components laid out according to the installed LayoutManager), you typically just call revalidate().
|
|
|
|
|
4
|
Discussions / General Discussions / Re: I Switched to IDEA!
|
on: 2013-03-11 14:21:45
|
Personally I have to flex my entire hand to be able to "ctrl+y", but I can do "ctrl+d" with ease. Not that I use IDEA, but can't you just use both hands for that shortcut? If you're shortcut-driven then both hands will be on the keyboard most of the time, then shortcuts like those aren't a problem. Not to mention you get to be one of those geeky people who brag about never using a mouse!
|
|
|
|
|
5
|
Java Game APIs & Engines / Java 2D / Re: Manipulating BufferedImages with IndexColorModels
|
on: 2013-02-25 00:40:32
|
Thanks guys. Sorry about the super-small sample image; I was using the simplest test case possible, a single 16x16 tile, all one color, while trying to figure things out. I had tried all those RenderingHints in the hope they would make a difference (as well as perhaps ward off issues when creating new images with scales > 1) but they seem to make no difference - the result is still the same, apparent dithering. I found this old thread, in which Abuse gives an approach that does work. If you start with one IndexColorModel'd Image, and create a new BufferedImage with a new ColorModel but the same Raster, things are much happier. I'm still not sure why you get differing results when using a "grayscale" IndexColorModel vs. another IndexColorModel, when using a source image that has all pixels the same color, but whatever.
|
|
|
|
|
6
|
Java Game APIs & Engines / Java 2D / Manipulating BufferedImages with IndexColorModels
|
on: 2013-02-24 07:41:18
|
Hopefully it's just because it's so late, but for the life of me I can't figure this out. I start with an 8-bit PNG image. I can create a grayscale version of this image with Java2D like so: 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
| private static final IndexColorModel createGreyscaleModel() { int SIZE = 256; byte[] r = new byte[SIZE]; byte[] g = new byte[SIZE]; byte[] b = new byte[SIZE]; for (int i=0; i<SIZE; i++) { r[i] = g[i] = b[i] = (byte)i; } return new IndexColorModel(8, SIZE, r, g, b); }
private static final BufferedImage createIndexedCopy(Image orig, IndexColorModel cm, int scale) { int w = orig.getWidth(null); int h = orig.getHeight(null); BufferedImage out = new BufferedImage(w*scale, h*scale, BufferedImage.TYPE_BYTE_INDEXED, cm); Graphics2D g2d = out.createGraphics(); g2d.drawImage(orig, 0, 0, w*scale, h*scale, null); g2d.dispose(); return out; }
BufferedImage grayscaleImage = createIndexedCopy(otherImage, createGreyscaleModel(), 1); |
The end result looks like what I'd expect. So next, I thought I'd try to create a "greenscale" version of the image by creating the color model like so: 1 2 3 4 5 6 7 8 9 10 11
| private static final IndexColorModel createGreenModel() { int SIZE = 256; byte[] r = new byte[SIZE]; byte[] g = new byte[SIZE]; byte[] b = new byte[SIZE]; for (int i=0; i<SIZE; i++) { g[i] = (byte)i; } IndexColorModel model = new IndexColorModel(8, SIZE, r, g, b); return model; } |
But the end result isn't what I want. It looks as if some kind of interpolation was done, even though the image was never scaled. This happens even when the original image is just a single color. See the example below. The original (blue) image has all pixels a single color, the grayscale version looks good, but the green version doesn't...  What am I missing?
|
|
|
|
|
7
|
Java Game APIs & Engines / Java 2D / Re: Event handling
|
on: 2013-02-22 01:38:49
|
If you need custom events, and not built-in events as xsvenson speaks of, there are two available options. You can choose which one is more appropriate for your situation. 1. Use java.beans.PropertyChangeEvents. JComponents can fire such events by any of their many firePropertyChange() overloads. Then the other component interested in these events would call customComponent.addPropertyChangeListener("propName", this); This technique is common if you have say boolean, int or String properties that other components might be interested in receiving change notifications for. 2. The second option is more legwork, but allows you to notify listeners with an entire event object containing arbitrary data, instead of just an old/new value pair. Roll your own Event class (subclassing java.util.EventObject), Listener interface (extending java.util.EventListener), and make your custom component accept Listeners of that type. It follows the same pattern as the "built-in" event types like ActionListener, so it's pretty straightforward. A simple example can be found here. Note that JComponents already have a protected EventListenerList field named "listenerList", so you don't have to add such a field in your custom component yourself.
|
|
|
|
|
8
|
Game Development / Newbie & Debugging Questions / Re: JFrame/Frame and the Event Dispatch Thread
|
on: 2013-02-18 20:50:30
|
|
You're right that there's no effective "real-world" difference. The main reason I think people suggest to use AWT over Swing for games is that there's simply less overhead. As soon as you create a JFrame, a JPanel, etc., Swing's LookAndFeel-related classes all get loaded, but if you're not using any JComponents other than say a custom-painted JPanel, you don't actually use them. Why load classes you don't need or use? etc.
Again, this is a negligible "benefit", and certainly isn't noticed by users.
|
|
|
|
|
10
|
Discussions / Miscellaneous Topics / Re: Java blocked on Macs?
|
on: 2013-02-02 20:53:46
|
According to the article the Department of Homeland Security also recommends against Java...isn't their time better spent catching intentionally malicious things or, say, terrorist attacks?  This reminds me of people who get a speeding ticket and complain, "Shouldn't the cops be out catching murderers and bank robbers?"
|
|
|
|
|
11
|
Discussions / General Discussions / Re: Why java over other languages?
|
on: 2013-01-31 17:30:09
|
- the lambda introduces a new operator "->" which must be learned - Also the "e -> " part of the expression is alien to Java. It seems to be sort of argument passing to a parameter which has the same name as the argument ... it's also somethign new, other parts of java don't work this way.
But if Java 1.0 were shipped supporting lambdas and this syntax you'd think differently, as you'd be used to it. Just because you have to learn new syntax doesn't mean Java suddenly becomes bloated or confusing. If you were learning Java post-Java 8, and your education included lambdas, would you think "this one feature is just too confusing," or would you simply accept it and happily move on?
|
|
|
|
|
12
|
Game Development / Newbie & Debugging Questions / Re: Quick Swing Question
|
on: 2013-01-29 23:41:44
|
You set the layout of the JFrame to null, when you probably meant to set the content pane's layout to null. This works: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| public Window() { JFrame mainFrame = new JFrame(); mainFrame.setSize(1024, 786); mainFrame.setLocationRelativeTo(null); mainFrame.setTitle("Temp Name"); mainFrame.setDefaultCloseOperation(EXIT_ON_CLOSE); mainFrame.setResizable(false); insets = mainFrame.getInsets(); mainFrame.getContentPane().setLayout(null); JTextArea gameTextArea = new JTextArea(); gameTextArea.setEditable(false); gameTextArea.setBounds(50, 30, 100, 20); mainFrame.getContentPane().add(gameTextArea); mainFrame.setVisible(true); } |
Standard Swing-fanatic disclaimer: It's really preferable to use a LayoutManager rather than null layout, as then your UI could be designed to allow the window to be resizable and still look nice, not to mention handling different LookAndFeels having different widget sizes, the user's desktop settings, etc.
|
|
|
|
|
13
|
Game Development / Newbie & Debugging Questions / Re: [FPS Camera: Robot.mouseMove() persistency]
|
on: 2013-01-27 06:28:06
|
If someone thinks the reason I'm not getting the persistency I'd prefer is due to the reason of my implementation of compensating for the window's borders, I've executed the program without compensation and it made no difference.
I see what you're trying to do, but note that hard-coding the size of the window's title bar and borders is a bad idea. Different OSes will have different values, let alone if the user has different themes, font sizes, display settings, etc. You will need to handle such information dynamically. As for the mouse events, you'll never get one for each pixel the mouse moves. Your best bet might be to also listen for mouseExited() events and move the mouse back on them as well. You'll most likely need to handle mouseDragged() events the same way too, since they won't get handled by your mouseMoved() handler.
|
|
|
|
|
14
|
Discussions / General Discussions / Re: how to make a soccer game in 2D with java?
|
on: 2013-01-18 04:10:22
|
I had a software manager once that didn't know anything about coding and determined your performance based on lines of code....it was hell.
You had a manager that read through your code? That in and of itself is strange to me. Unless you're saying he gauged your performance based on `wc -l`, like the old joke, in which case I don't see the problem - that's easily abusable in your favor...
|
|
|
|
|
15
|
Game Development / Newbie & Debugging Questions / Re: [Loading A 'small movie' in .PNG frames (Memory DEBO)]
|
on: 2013-01-17 23:39:57
|
Yes, but you saved 20MB because the ImageIcons were simply wrapping the BufferedImages, so naturally there was more stuff in memory with a list of ImageIcons. The actual RAM used by BufferedImages was the same. If you cannot cut down your image size or resolution, you'll probably have to find an Image implementation that is more space efficient than BufferedImage (which I believe typically is just uncompressed RGB data). See this StackOverflow post for a discussion about this very problem and possibly some ideas for minimizing your memory requirements.
|
|
|
|
|
17
|
Discussions / Suggestions / Re: Bugs
|
on: 2013-01-09 22:48:46
|
|
I have the opposite problem. I get angry when sites require fewer than X characters. (And unbelievably, it's a financial institution I use that does this - where I want a long password the most!).
|
|
|
|
|
18
|
Discussions / Business and Project Discussions / Re: Looking for a part-time (or preferably full) coder for Project Zomboid
|
on: 2013-01-08 19:54:24
|
The former won't do anything, the compiler will be better than you at optimizing stuff like that in 99.9% of cases. In fact, all you will accomplish is obfuscating your code and wasting time on premature optimization. And it's micro optimization, which is even worse because it's usually wrong.
The JVM Specification actually states that the two approaches are equivalent, IIRC. Space for all local variables of a method is pre-allocated at method invocation. It doesn't matter whether a variable is declared inside of a loop or outside of it. Variable scope should be based on what makes the most sense.
|
|
|
|
|
19
|
Game Development / Newbie & Debugging Questions / Re: Specify What To Paint On? (Java2D)
|
on: 2013-01-07 23:39:02
|
Not sure if this is what you're asking for, but if you want to display different panels as the "main" content pane, depending on certain criteria, then CardLayout is what you're after. As for whether it's worth it to create them up front vs. creating new ones on the fly, the answer is: do whatever you want, as long as it performs well enough. If you can create your panels fast enough that lazily creating them shows no perceivable performance issue to the user, then why not?
|
|
|
|
|
22
|
Discussions / Miscellaneous Topics / Re: Is programming as a job boring?
|
on: 2013-01-07 14:52:21
|
Agreed. Even if they offer you a raise, it is unlikely to be as much as you could get starting new elsewhere. Besides, you already need to change jobs to keep things interesting so there is no point in letting yourself get stuck doing the same work for small raises. Change is scary, so a lot of people end up doing it wrong.  Agreed here too, but is it not also true that any good manager would also realize just that - an employee looking for another job probably isn't happy with what they do, and giving a pay raise might keep them there in the short term, but ultimately they'll still end up leaving? I've had a manager offer to find me a position in another group doing work tangential to what I was currently doing, so I'd stay close and my domain experience wasn't completely lost. I thought that a clever alternative. No pay raise offer though, don't think we really had the money (or maybe he thought I just wasn't worth anything more  ).
|
|
|
|
|
24
|
Discussions / Jobs and Resumes / Re: How to write a University Entrance Portfolio?
|
on: 2013-01-07 05:25:26
|
Can your friends tell the difference between a NFA and a DFA, NP-Hard and NP-Complete, or a monad and an applicative functor? If I go in for a computer science degree, I damn well don't want to be taught something I could get from Sams Teach Yourself Java In 24 Minutes.
Sproingie is spot on. A Computer Science degree is not the same curriculum as going to a trade school to get a .NET certification and learn to create CRUD applications. Sans single-credit electives, you're only really taught programming languages as tools to learn the math and theory. Students are pretty much expected to be self-motivated to learn languages. And as an armchair academic, I like it that way.  This is somewhat of an educated (?) guess on my part, but that may be why a masters in CS doesn't seem to help as much in private industry as it does for other fields. Getting an MS does not mean you're going to be a better programmer than the next guy who only got his bachelor's. You didn't learn Java more in-depth than him, nor did you learn how to write iPhone apps better than he did. You learned about automata theory, AI, compiler design, security, etc. You have a broader knowledge of computer science though. Whether or not you're a better programmer really boils down to how your work experience compares to his.
|
|
|
|
|
27
|
Discussions / General Discussions / Re: Trying To Make A Shared JTextArea
|
on: 2013-01-01 00:40:43
|
To do this the "right" way, you'll want to learn about the JTextComponent design - Documents, etc first. Read through this, particularly from the "Concepts: About Documents" section down. One other major consideration is that you should take care to not block the EDT with network calls whenever possible.
|
|
|
|
|
29
|
Discussions / General Discussions / Re: why are people trying to use Java2D to make games?
|
on: 2012-12-30 00:51:41
|
|
Real men write all their code in assembly. Anything else is just laziness.
@HeroesGraveDev: Your idea of where the "being lazy" line is drawn is subjective. Some people think using pre-built game libraries is lazy, others don't. Some like using full-blown game engines like Game Maker, other's don't. There is no right or wrong answer.
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|