Show Posts
|
|
Pages: [1] 2 3 ... 8
|
|
5
|
Java Game APIs & Engines / Java 2D / Re: rotating and placing images by points OTHER than their upper left corner
|
on: 2007-08-18 17:30:28
|
Okay, that's quite easy to change the position's anchor to the center or any other arbitrary number. To center the image, just subtract half of the image's width from the x-position and half of the height from the y-position. Here's an example: 1 2 3
| public void paint(Graphics g) { g.drawImage(img, x-(img.getWidth()/2), y-(img.getHeight()/2), null); } |
Now to rotate an image, it gets a little more complex. You first need to create a completely empty BufferedImage, with the same width/height of the orignal image and the same transparency (ex. TYPE_INT_ARGB). Then you obtain the Graphics2D object of the empty image by calling createGraphics() on it. You then create an AffineTransform object (located in the java.awt.geom package). Then you call rotate(double, double, double) on your AffineTransform object. The first parameter is your angle to rotate upon, in radians (convert degrees to radians with Math.toRadians(int)). The second parameter is your x-anchor to rotate on. The last parameter is your y-anchor to rotate on. The next step is to call setTransform(AffineTransform) on the Graphics2D object you obtained. The last step is to draw the orignal image onto the empty image at 0,0 (using the Graphics2D again). Here's the code to rotate: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| public BufferedImage rotate(Image source, int angle) { int w = source.getWidth(null); int h = source.getHeight(null); BufferedImage image = new BufferedImage(w, h, source.getTransparency()); Graphics2D g = image.createGraphics();
AffineTransform geom = new AffineTransform(); geom.rotate(Math.toRadians(angle), w/2, h/2); g.setTransform(geom);
g.drawImage(source, 0, 0, null); g.dispose();
return image; } |
|
|
|
|
|
7
|
Games Center / 4K Game Competition - 2007 / Re: Time to plan for '08
|
on: 2007-08-04 15:52:07
|
Because, as Markus said, this whole competition is turning into a compression-contest, I'd be much happier with a 8K contest, where no compression is allowed at all. Just distributing a class-file! I know it's not going to happen. but still...  I always thought that was the whole point of 4K in the first place...? I never knew any kind of compression was used until I read this thread.
|
|
|
|
|
8
|
Games Center / Archived Projects / Re: Falling Blocks
|
on: 2007-08-02 13:15:27
|
Hmm, guess I got a lot to learn about Tetris... Oh by the way, something that's probally useless to say now, I'm gonna say anyway... I'm having trouble with the "Application's digital sig. can not be verified" (even after using keytool && jarsigner ).
If you are signing the application yourself, Java won't be able to verify it. If your application is requesting permissions to the system and your application is not signed at all, Java also cannot verify the digital signature (because it has none).
|
|
|
|
|
9
|
Games Center / Archived Projects / Re: Falling Blocks
|
on: 2007-08-02 03:44:01
|
Thanks. I'll look into the jnlp permissions. I agree with you guys, sluggish controls. I'm struggling with the fact that when you press a key it easily sends 3 or 4 key press events. If I have each keypress move a block x+1 (or x-1 depending on direction) on the grid... then each press might send the block zipping across the play grid. To slow this down, I'm using if(blockLoopDelta > blockSpeed){move()}else{blockLoopDelta+=gameDelta} logic to keep the blocks for zipping 3 or 4 units per millisecond. unfortunately, this requires 3 or 4 key press events to move a block.  Any thoughts on how to control how may key press events occur per a users physical press (or how to make the controls react correctly)?. Lastly, I'll put some collision detection in there for horizontal collisions (clearly, I only have boundary and vertical collision detection). Thanks. The best way I found to reduce this problem is to just drop my framerate to about 20 or 25 frames per second.
|
|
|
|
|
10
|
Games Center / Archived Projects / Re: Falling Blocks
|
on: 2007-08-01 13:23:50
|
|
Very nice for a Tetris clone. But like what Riven said, moving horizontally allows the block to move through another block. Would like to see a different variation of Tetris though. Such as with power ups or some kind of other wild game play never done before in a Tetris game.
|
|
|
|
|
11
|
Java Game APIs & Engines / Java 2D / Re: draw text to the screen with breaks
|
on: 2007-07-31 13:29:35
|
Here's a simple method that takes a String-array and draws it at the specified corners. (I haven't actually tested it yet - not a lot of time at the moment - but it should work with no problem.) 1 2 3 4 5 6 7 8
| public void drawStrings(Graphics g, String ln[], int x, int y) { FontMetrics fm = g.getFontMetrics(g.getFont()); int h = fm.getHeight();
for (int i=0; i<ln.length; i++) { g.drawString(ln[i], x, y+(h*i)); } } |
|
|
|
|
|
13
|
Java Game APIs & Engines / Java 2D / Re: Mirror an Image
|
on: 2007-07-30 13:27:56
|
|
g.drawImage(image, x, y, -width, height, null);
-width mirrors it horizontally -height mirrors is vertically (or combine both)
Keep note that mirroring an image will reverse the origin (as in, the origin is always top-left. Mirroring left-to-right, your new origin will be drawn from top-right).
|
|
|
|
|
14
|
Games Center / 4K Game Competition - 2007 / Re: 2008 competition?
|
on: 2007-07-25 13:25:06
|
|
Actually 5 months till '08, but yeah. I'd love to see another 4K competition next year, as I never got a chance to participate in the last years competition. But I loved playing every one else's game. Maybe next year I can actually have enough time to finish one and submit it.
|
|
|
|
|
16
|
Java Game APIs & Engines / Java 2D / Re: Help jumping in platformer.
|
on: 2007-07-04 13:31:39
|
What I do is I have two variables, gravity and speedy. Both values are float. Gravity is usually set between 0 and 1 (usually with two or three decimal values). speedy starts at 0 when the game begins. When your character needs to jump (such as the space key pressed) set your speedy variable to something like -8 (play around with both this and the gravity variable to get the desired effect) and in your game loop, you increment your y-position of your object by adding speedy to it (e.g. object.y += object.speedy;). After that line of code, you increment speedy by adding the gravity variable to it (e.g. object.speedy += object.gravity;). You'll want to limit how high speedy can get (e.g. you don't want it to be 100 or the character will fly through the floor). Usually it should be a no higher than your floor's height divided by 2). I usually use this to limit it: 1
| if (object.speedy > tileH/2) object.speedy = tileH/2; |
(After adding the gravity to the speedy!) Good luck, JJ
|
|
|
|
|
19
|
Discussions / Miscellaneous Topics / Re: How to build sites with php?
|
on: 2007-06-07 13:15:27
|
|
Not really. I used to write very advanced websites with PHP with extreme ease. I did all the coding in Notepad, surprisingly. I wrote a complete forum software like phpBB and sold it for $250 (wasn't quite advanced as phpBB, however). It was a sure nice chunk of change. I also did a lot of backend programming with PHP, such as a CMS (Content Management System). And I obviously couldn't live with having PHP without MySQL.
|
|
|
|
|
20
|
Games Center / Archived Projects / Re: Space Invaders
|
on: 2007-06-05 05:59:24
|
|
Okay, so, update! I've been able to successfully place everything (including lwjgl.jar) in separate JAR files. Now supports Windows, Linux, and Mac (so far, only tested on Windows). Another update is it supports controller input (only the first available controller that has at least one axis is selected by default).
Please run it and tell me what you think of it. I'd be interested to see what the results are on Linux and Mac (and other versions of Windows).
EDIT: Oh and by the way, thanks for all the help!!! I really appreciated it!
|
|
|
|
|
22
|
Games Center / Archived Projects / Re: Space Invaders
|
on: 2007-06-03 16:30:48
|
I cannot run the JAR file without it being signed. I get the following: (this is running from my local server) 1 2
| Unsigned application requesting unrestricted access to system Unsigned resource: http: |
It will not start up after that, just cancels it out. And as you said... the lwjgl jars needs to be signed, because running native code is not allowed per default. If they DO need to be signed... am I required to sign them myself? If not, where are the signed versions of the JARs???  Launch it now and you'll see the error.
|
|
|
|
|
23
|
Games Center / Archived Projects / Re: Space Invaders
|
on: 2007-06-03 02:04:59
|
|
Oh that. I didn't know that was on lwjgl.org. I intended my game to be like that one, but I found it on kevglass' site, cokeandcode.com. I didn't use the tutorial, but I got the art from molotov.nu, apparently he altered the art a little though.
But anyway, does anybody know why the lwjgl.jar needs to be signed? And where to get the signed jar from (or do I sign it myself?).
|
|
|
|
|
25
|
Games Center / Archived Projects / Space Invaders
|
on: 2007-06-02 20:59:52
|
Hello all, I thought I would throw my Space Invaders game your way and see what you guys think of it. It's my first LWJGL game. I cannot find a signed lwjgl.jar file (maybe I'm supposed to sign it myself?), so I had to distribute the files inside the main jar file, so it's Windows only. Here's a screenshot for those of you who can't run it if they don't have Windows (again, sorry about that).  Here's the WebStart link: http://www.myexh.com/~gonav341/SpaceInvaders/SpaceInvaders.php
|
|
|
|
|
26
|
Discussions / Miscellaneous Topics / Re: How to build sites with php?
|
on: 2007-06-02 16:37:39
|
|
It doesn't matter how you program in PHP... it's still PHP. It will always look the same. I always liked PHP's syntax, but I can't remember much of it as I have not done any in more than 4 years. I used to be a great PHP programmer but I hated general web development (eg using HTML, CSS, layouts, etc). Also, PHP-GTK+ reminds me of Java now that I think of it.
|
|
|
|
|
28
|
Java Game APIs & Engines / OpenGL Development / Re: Good enough texture loader?
|
on: 2007-06-01 01:53:52
|
Yeah, sorry. I guess I should have posted a screenshot. Here's the texture:  And here's a screenshot of the LWJGL alpha test I made (multiple sprites moving and rotating):  Click for the full size view. Notice the kind of "halo" on his head? EDIT: I found a fix for this. By adding a one pixel border around the sprite, it removes the artifacts. Looks good.
|
|
|
|
|
29
|
Java Game APIs & Engines / OpenGL Development / Good enough texture loader?
|
on: 2007-05-31 13:24:25
|
Hello all, I'm wondering if the texture loader I have is good enough for 2D games in LWJGL. It works great with 3D development, but with 2D textures with alpha values, there's small artifacts in the image. What can I do to improve this for 2D games? I'm converting the image data to bytes myself. 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
| public int loadTexture(String filename) { int ID = 0;
try { BufferedImage image = ImageIO.read(getClass().getResource(filename)); int imageW = image.getWidth(); int imageH = image.getHeight();
int size = imageW*imageH; IntBuffer data = BufferUtils.createIntBuffer(size); for (int y=0; y<imageH; y++) { for (int x=0; x<imageW; x++) { Color c1 = new Color(image.getRGB(x, y), true); Color c2 = new Color(c1.getBlue(), c1.getGreen(), c1.getRed(), c1.getAlpha()); data.put(c2.getRGB()); } } data.flip();
IntBuffer buf = BufferUtils.createIntBuffer(1); GL11.glGenTextures(buf); ID = buf.get(0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, imageW, imageH, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); } catch(Exception e) { e.printStackTrace(); Sys.alert("Error", "Unable to load texture: "+filename); System.exit(-1); }
return ID; } |
I'm using the following blend function: 1 2
| GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); |
|
|
|
|
|
30
|
Java Game APIs & Engines / Java 2D / Re: getting very high FPS with standard Java 2D
|
on: 2007-05-30 13:23:35
|
|
If your game is using vertical-sync, you shouldn't have the need to sleep. But if your just using say nanoTime() for limiting your frames per second but your running your render loop (drawing not updating) as often as possible, you'll need to sleep for at least 1 millisecond or else you'll cap the CPU to 100%. If you can find an alternative way to prevent your render loop from running as often as possible (like the technique vertical-sync uses but not being in fullscreen), you won't have a need for sleep also.
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|