Show Posts
|
|
Pages: [1]
|
|
2
|
Game Development / Game Mechanics / Re: Rotating rectangles for collisions?
|
on: 2012-08-15 05:46:33
|
no, This is all with a standard Rectangle() class. And yes, for collisions, i'm using rectangle.intersects.
Try this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| int degree = 90; int rectX = 100, rectY = 100, rectWidth = 150, rectHeight = 100; Shape rect = new Rectangle(rectX, rectY, rectWidth, rectHeight); Rectangle rect2 = new Rectangle(400, 100, rectWidth, rectHeight); AffineTransform transform = new AffineTransform(); transform.rotate(Math.toRadians(degree), rectX + rectWidth /2, rectY + rectHeight /2); rect = transform.createTransformedShape(rect); g2d.draw(rect); if(rect.intersects(rect2)){ } |
|
|
|
|
|
6
|
Games Center / WIP games, tools & toy projects / Re: BOUNCE - 2D Platformer w/ destructable terrain
|
on: 2012-08-03 19:32:48
|
|
The game idea is cool, i really liked the youtube vĂdeo. Anyway, I had a problem, sometimes when i'm stuck between the blocks, if i hold UP+LEFT or UP+RIGHT the ball pass through the blocks and go insane through the level (in level 1 it happened). Another thing, i think it's consuming too much CPU for a "simple" game, in level 1 for example is about 25% on my core i5 2.6 GHZ. Maybe a problem with the gameloop.
|
|
|
|
|
7
|
Game Development / Newbie & Debugging Questions / Re: How do you read an int from a txt file.
|
on: 2012-08-02 17:48:47
|
I wrote something a couple days ago. I don't know if i'll use this method to store values (i guess i'll use xml). Anyway, the point is getting a value from a variable in the String type, and then convert it to integer or another type. The method read and search in the txt file for the "<"+"variable name" + "=", so i named this string as "beforeValue", and another String called "afterValue" (just what i have after the value, including the variable to identify the block, in this case the ";"+variable+">"). I have to wrote something like this in my txt file: <x=10;x> The method will return the "10" in String, and then i convert it to integer. Code: 1 2 3 4 5
| public Data() { int x = Integer.parseInt(readValue("C:/myTxt.txt", "x")); System.out.println("The variable value is "+ x); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public String readValue(String txtPath, String variable) { String value = "0", contents = "", beforeValue = "<" + variable + "=", afterValue = ";" + variable + ">"; boolean found = false;
try { BufferedReader read = new BufferedReader(new FileReader(txtPath)); while((contents = read.readLine()) != null && !found){ if (contents.contains(beforeValue)) { value = contents.substring(contents.indexOf(beforeValue) + beforeValue.length(), contents.indexOf(afterValue)); found = true; } }
} catch (Exception ex) { System.out.println(ex.getMessage()); }
return value; } |
Obs: The txt file content also works in sequence: E.g1 (same line): <x=10;x> <y=30;y> <z=50;z> E.g2 (line breaking): <x=10;x> <y=30;y> <z=50;z>
|
|
|
|
|
8
|
Java Game APIs & Engines / Java 2D / Re: 2D-sprites and screen resolution
|
on: 2012-07-31 23:12:40
|
.... So that would be like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public static final int NORMAL_WIDTH = 1024; public static final int NORMAL_HEIGHT = 768; private float scale; public void calculateScale() { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); scale = Math.min( (float)d.getWidth() / NORMAL_WIDTH, (float)d.getHeight() / NORMAL_HEIGHT ); } public void draw(Graphics g) { AffineTransform transform = ((Graphics2D)g).getTransform();
((Graphics2D)g).scale(scale,scale); drawAllMyCrap(g); ((Graphics2D)g).setTransform(transform); } |
Thank you very much Eli Delventhal, that code helped me a lot. For those who don't want to keep the same scale for width and height, just change the code a little bit. Like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public static final int NORMAL_WIDTH = 1024; public static final int NORMAL_HEIGHT = 768; private float scaleWidth, scaleHeight; public void calculateScale() { scaleWidth = (float)Toolkit.getDefaultToolkit().getScreenSize().width / NORMAL_WIDTH; scaleHeight = (float)Toolkit.getDefaultToolkit().getScreenSize().height / NORMAL_HEIGHT; } public void draw(Graphics g) { AffineTransform transform = ((Graphics2D)g).getTransform();
((Graphics2D)g).scale(scaleWidth, scaleHeight); drawAllMyCrap(g); ((Graphics2D)g).setTransform(transform); } |
You can also implement a HierarchyBoundsListener to the JFrame, and realize some tests changing the size of it to see what happens with all the drawing stuff. 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
| ....
@Override public void ancestorResized(HierarchyEvent e) { game.setSize(getWidth(), getHeight()); game.scaleWidth = (float)this.getWidth() / NORMAL_WIDTH; game.scaleHeight = (float)this.getHeight() / NORMAL_HEIGHT; }
...
public void draw() { Graphics2D g2d = (Graphics2D) bufferStrategy.getDrawGraphics(); AffineTransform transform = g2d.getTransform(); g2d.scale(scaleWidth, scaleHeight); g2d.clearRect(0, 0, getWidth(), getHeight()); ... g2d.setTransform(transform); g2d.dispose(); bufferStrategy.show(); } |
Really simple and newbie, but i hope it may help someone...
|
|
|
|
|
9
|
Game Development / Articles & tutorials / Re: Game loops!
|
on: 2012-07-31 19:29:57
|
So I noticed when I added 15 instead of 10 to the sleep on the variable timestep, it didn't error out on me. Did it error out on anyone else?
The error was that the time to sleep was a negative value, but it look like it's only for the first time the loop runs. Every time after that it's between 8 and 10. Any ideas? I think i solved that error just adding Math.abs(); to the Thread.sleep calculation (making the result be always positive): 1
| Thread.sleep(Math.abs(lastLoopTime - System.nanoTime()) / 1000000 + 10); |
For now i didn't have any problems, but i really don't know if my solution is the correct one, and if it affects the logic behind the variable timestep loop. Maybe someone could tell me if i'm doing something stupid...
|
|
|
|
|
11
|
Games Center / Showcase / Re: My Little Dungeon - LD23 Game
|
on: 2012-07-23 14:53:00
|
|
Hey Bach, a different kind of game, cool btw. I liked the bgm.
I have one question... what method do you used to resize the game? Because when we change the size of the window, all the stuff inside changes and keep the proportion (images, texts), and i want to do the same for my game (keep the proportion for all screen resolutions).
I don't know anything about the libGdx library, i'm not using libraries (except for music and sound), so can it be a native function of the library or something like that?
Thanks.
Ps: Sorry for any english mistakes, i'm in the language learning process.
|
|
|
|
|
12
|
Java Game APIs & Engines / Java Sound & OpenAL / Re: Need a really simple library for playing sounds and music? Try TinySound.
|
on: 2012-07-20 13:51:26
|
|
kuusisto, i'm here to give my feedback about the library. Well, i was looking for a simple library, and when i say "simple", means simple functions, easy and at the same time powerful for my purpose. I tried the "Easy OGG" library, it's a very good library, but in my case i was looking specifically for sound effects, and with the easy ogg library i had no success, cause in sound effects for games we often need to play fast sequences (like a shooter game for example), and the easy ogg isn't good for this (correct me if i'm saying something wrong).
Well, in this case, your library covered everything i needed. At the moment it's working good, no problems or bugs. For sound effects using the .ogg format, is the best that i found. Thank you very much.
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|