Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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 ... 5
1  Game Development / Newbie & Debugging Questions / Re: [LibGDX,Desktop]Remeber the window position on: 2014-12-09 21:29:57
There is not much code to show. While in the menu, I replaced the action performed by the Exit button with System.out.println(Display.getX() + " " + Display.getY());. No LibGDX wrapper(those dont exist as far as I know).

Why are we talking about resizing now?
2  Game Development / Newbie & Debugging Questions / Re: [LibGDX,Desktop]Remeber the window position on: 2014-12-09 13:19:46
I did, they are the same.

I did some more tests, and the problem is definitely the values returned by getX() and getY().

For example, when the window is leftmost, getX() return a value between 60 and 90. When I move the window rightmost, the value is still around 60 and 90.
When it is in the middle, it return a value around 280.

The width of my screen is 1920.

Is it a bug in LWJGL or a misunderstanding from my part?
3  Game Development / Newbie & Debugging Questions / Re: [LibGDX,Desktop]Remeber the window position on: 2014-12-09 13:02:54
The saving is not wrong. I added a shutdown hook which stores Display.getX() and Display.getY() in a Vector2, which is serialized and exported to a file with ObjectOutputStream.

When starting the game, the saved Vector2 is read with ObjectInputStream. I then call Display.setLocation(int x, int y). The setLocation works as it moves the actual window. But the position is wrong. getX() and getY() is either giving me wrong values, or, setLocation does not work as expected. Both are poorly documented.
4  Game Development / Newbie & Debugging Questions / Re: [LibGDX Desktop]Remeber the window position on: 2014-12-09 11:41:07
Yes, its a LWJGL window.

Save the position of the window when you close it to a save file you have and when next time you open the window set it's position to that from file.
Thats what I am doing. The problem is when I am moving the window to the saved position. The position if completely wrong.
5  Game Development / Newbie & Debugging Questions / [LibGDX,Desktop]Remeber the window position on: 2014-12-09 10:53:42
I want to remember the position the of the game window when closed. Thus, when starting the game again, the window is moved to its previews position.

Doing some tests, I get odd results. Consider the following line:

Display.setLocation(Display.getX(), Display.getY());

This shouldnt move the window, but it does.
6  Java Game APIs & Engines / Engines, Libraries and Tools / Re: Slick2d - How can I rotate a polygon or any other shape ? on: 2014-11-07 16:36:17
Rotating 500 points is not a big task. At least not in LibGDX' polygon class. Shouldn't affect performance much.
But having a polygon with 500 points sounds like a design flaw. Are you sure using a polygon is the best approach?

Here is an excellent tutorial about Transform(or Matrix as it sometimes called):
http://www.senocular.com/flash/tutorials/transformmatrix/

If you are going to render the polygon, and not perform any collision detection, using a transform is probably the best way.
Obtain the transform used -> rotate it with its function -> render the polygon -> rotate it back to its original state.

Edit: Try this:

1  
2  
Transform t = Transform.createRotateTransform(* your angle *);
polygon.setTransform(t):


This should rotate the polygon and is fast.
7  Game Development / Newbie & Debugging Questions / Re: [LibGDX]Render portion of a Texture/Sprite on: 2014-11-02 23:13:11
Instead of using the sprite batch method, I have to use the functions found in TextureRegion to set the region.

The results are odd. Everything is zoomed and its looks just way off.

Edit: Managed to solve it! For those wondering how:

1  
2  
3  
4  
img.setRegion(u, v, u2, v2);
img.setSize(width, height);
img.setPosition(startX, startY);
img.draw(batch);
8  Game Development / Newbie & Debugging Questions / Re: How to code this? on: 2014-11-02 22:58:33
Okey, I did some googeling but couldn't find an good answer.

Basically, I dont want a customized scroll factor.

Example:
When translateX(world) is 0, the the background's position is also 0. As translateX increases, the background's x coordinate also increases, at a speed so that when translateX == world.width, the background is at the right most.

How to achieve this?
9  Game Development / Newbie & Debugging Questions / How to code this? on: 2014-11-02 17:23:33
In my game, the background and foreground image's dimension are equal to the size of the world.
So I just render them at coordinate 0:0 and achieve desired effect.
Example:
https://www.youtube.com/watch?v=82TL-Acm4ts

On some games, the background image is smaller than the world. In those cases, the background image is slowly moving when the camera is moving.
Example:
https://www.youtube.com/watch?v=Vd3eugNjfKI

Anyone know how to code it?
10  Game Development / Newbie & Debugging Questions / Re: [LibGDX]Render portion of a Texture/Sprite on: 2014-10-22 18:33:45
Thanks. I used the spritebatch function in the code block above. I had to google what u,v,u2 and v2 was though.

Rendering a portion of a large image is definitely preferred. Some visual glitches was fixed. And I can imagine releasing stress from the GPU.
11  Game Development / Newbie & Debugging Questions / Re: [LibGDX]Render portion of a Texture/Sprite on: 2014-10-22 17:01:17
Are you referring to the following method?

1  
spriteBatch.draw(texture, x, y, width, height, u, v, u2, v2);


I tried it but couldnt get it to work. I am not sure how to use it.

And the TextureRegion is not working either. I am guessing you are referring to region.setRegion(x,y,width,height) ?

EDIT: Never mind, got it to work Smiley
12  Game Development / Newbie & Debugging Questions / Re: [LibGDX]Render portion of a Texture/Sprite on: 2014-10-22 11:03:15
I am not talking about culling. And the camera is moving.

Seiya02: I will look into that. Although I dont understand much from LWJGL. Where do I set which texture to render?
13  Game Development / Newbie & Debugging Questions / [LibGDX]Render portion of a Texture/Sprite on: 2014-10-22 08:23:39
Oddly enough, I couldn't find a tutorial about this.

I have large background images and I feel it's a waste to render the whole thing when the window is 800x600.

So I want a function that renders portion of the image, but cant find anything.
14  Game Development / Newbie & Debugging Questions / Re: Custom Tile/Level Editor in Java on: 2014-10-02 22:26:30
So whats wrong with Tiled?
http://www.mapeditor.org/

LibGDX can even render Tiled maps.
15  Game Development / Newbie & Debugging Questions / Re: Custom Tile/Level Editor in Java on: 2014-10-02 21:01:31
You could import an image which is translated to a two dimensional array.
Where color Z is translated into 1, color X into 0 and Y into 2.

You dont need a program that do the conversion, it could be done in a single method.

1  
2  
3  
4  
public static int[][] encode(String imagePath)
{
         //.... Code
}


I have done similar for my game.

Also, to save RAM, you should use byte array instead of int array.
16  Game Development / Newbie & Debugging Questions / Re: Image flickering when moved (slick2d) on: 2014-09-28 20:20:40
I remembered when I used Slick2D(you should really switch to LibGDX as you are wasting your time with that buggy crap). Rendering large images was glitchy.
It was solved by using the BigImage class.
17  Game Development / Newbie & Debugging Questions / Re: Image flickering when moved (slick2d) on: 2014-09-28 18:13:37
Do you have this problem with small images to?
18  Game Development / Newbie & Debugging Questions / Re: [LibGDX]Looking for methods equivalent to the following on: 2014-09-28 08:06:11
That almost gave me accurate results. Probably because mul can not be used for both transform and transformNormal.

Applying a transform to a coordinate with a given matrix can probably be found on somewhere on the net. But what is transformNormal?
19  Game Development / Newbie & Debugging Questions / [LibGDX]Looking for methods equivalent to the following on: 2014-09-28 06:05:33
I am translating a XNA code and is looking for something that is equivalent to these two(preferably in the LibGDX library since I am working with their matrix classes):

1  
            Vector2 v1= Vector2.TransformNormal(Vector2, Matrix);


1  
            Vector2 v2 = Vector2.Transform(Vector2, Matrix);


Their documentation:
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.vector2.transformnormal(v=xnagamestudio.40).aspx
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.vector2.transform(v=xnagamestudio.40).aspx
20  Game Development / Newbie & Debugging Questions / Re: Get bounding box of rotated rectangle. on: 2014-09-27 18:10:09
What are the vertices? I don't think I have them.
21  Game Development / Newbie & Debugging Questions / Get bounding box of rotated rectangle. on: 2014-09-27 16:38:02
So, I have a rectangle with a known x, y, width and height.



The top left corner is the x:y coordinate where x is increasing while moving right and y while moving down.

I then rotate it with a known value(the rectangle is rotated around its center point):



I want to calculate the position of the red dot as well as the new width and height.
22  Game Development / Newbie & Debugging Questions / [LibGDX] Updated LibGDX, crashes when creating SpriteBatch. on: 2014-09-24 17:46:36
It was a while ago since I updated LibGDX. So when I did I first got some compile time errors with the stage class.

I changed the constructor from (int width, int height, boolean something) to (ScreenViewport()).
That solved those.

I tried to run my game and it crashed as I tried to initiate a sprite batch.

The code that crashed:
1  
batch = new SpriteBatch();


The exception:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
LwjglGraphics: created OpenGL 3.2+ core profile context. This is experimental!
Exception in thread "LWJGL Application" java.lang.IllegalArgumentException: Error compiling shader: Vertex shader failed to compile with the following errors:
ERROR: error(#272) Implicit version number 110 not supported by GL3 forward compatible context
ERROR: error(#273) 1 compilation errors.  No code generated

Fragment shader failed to compile with the following errors:
ERROR: error(#272) Implicit version number 110 not supported by GL3 forward compatible context
ERROR: error(#273) 1 compilation errors.  No code generated


   at com.badlogic.gdx.graphics.g2d.SpriteBatch.createDefaultShader(SpriteBatch.java:152)
   at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:115)
   at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:72)
   at ui.screens.Splash.show(Splash.java:41)
   at com.badlogic.gdx.Game.setScreen(Game.java:61)
   at ui.screens.ScreenManager.create(ScreenManager.java:33)
   at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
   at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)


How do I resolve this?
23  Game Development / Newbie & Debugging Questions / Re: [LibGDX]Get points of rotated rectangle? on: 2014-09-22 14:21:13
Can you give an example on how to use AffineTransform with this issue?
24  Game Development / Newbie & Debugging Questions / Re: [LibGDX]Get points of rotated rectangle? on: 2014-09-21 21:50:29
Thanks all. Solved it 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  
    /**
    * Rotates this entity and returns the updated {@code x} and {@code y} coordinates.
    * @param x The relative x position we want after a rotation.
    * @param y The relative y position we want after a rotation.
    * @param rotation The angle in degrees.
    * @return The point that contains the absolute coordinates.
    */

   public Point2D.Float getRotatedPoint(float x, float y, int rotation)
   {
      if(width != height)
         throw new IllegalArgumentException("Width and height mismatch. The GameObject must use a square image!");
     
      final double rot = Math.toRadians(rotation);
      final float halfWidth = getWidth() / 2;
     
      y -= x;
      x -= x;
     
      y = -y;
     
      float rotX = (float) (x * Math.cos(rot) - y * Math.sin(rot));
      float rotY = (float) (y * Math.cos(rot) + x * Math.sin(rot));
     
      rotY = -rotY;
     
      rotX += halfWidth;
      rotY += halfWidth;
     
      return new Point2D.Float(rotX + currX, rotY + currY);
   }


Can probably be improved to work with rectangular shapes and not just squares.
25  Game Development / Newbie & Debugging Questions / Re: [LibGDX]Get points of rotated rectangle? on: 2014-09-21 18:44:50
That didnt work either. But I do not get it. What do you mean rotate around (0,0)?  How am I suppose to calculate the position of the rotated point if I rotate around 0,0 instead of the entity┬┤s position?
26  Game Development / Newbie & Debugging Questions / Re: [LibGDX]Get points of rotated rectangle? on: 2014-09-21 18:16:24
My code is not working. Can someone look at it? Btw using LibGDX.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
   private Point2D.Float getSpawnPos(int rotation)
   {
      /*
       * 0 degrees is facing west in my engine. Increasing this value is rotating clockwise.
       */

      final double rot = Math.toRadians(rotation);
      final float midX = getCenterX(); //The center position of the entity in the world
      final float midY = getCenterY(); //The center position of the entity in the world
      final float sin = (float)Math.sin(rot);
      final float cos = (float)Math.cos(rot);

      //currX respective currY is the absolute position of the entity in the world(top-left corner of the entity)
      float x = currX - midX;
      float y = currY - midY;
     
      float rotatedX = x * cos - y * sin;
      float rotatedY = x * sin + y * cos;
     
      rotatedX += midX;
      rotatedY += midY;
     
      return new Point2D.Float(rotatedX, rotatedY);
   }


The returned point contains absurd values.
27  Game Development / Newbie & Debugging Questions / Re: Get points of rotated rectangle? on: 2014-09-19 23:14:37
float rotatedX = x * cos - y * sin;
float rotatedY = x * sin + y * cos;
how do I apply that to my coordinate system?
28  Game Development / Newbie & Debugging Questions / [LibGDX]Get points of rotated rectangle? on: 2014-09-19 16:20:13
I have a rectangle like this:



I then rotate it  by 45 degrees and want to calculate the coordinates of the four white points.

The x/y position of an entity is the top left corner, where x is increasing moving rightwards and y downwards.
29  Java Game APIs & Engines / Engines, Libraries and Tools / Re: [LibGDX]Render an electric beam? on: 2014-09-15 15:23:29
Alright, I used this:
http://www.java-gaming.org/?action=pastebin&id=1025

And I got it to work. Its draws a jagged line between the two given points.

The problem is, it doesnt look good ingame. It looks so dull, color wise.

The image used is 7x7 white image. If I forexample use a black image, the beam is not visible. If its yellow, the beam appear green or something else ingame.
Totally weird.
30  Java Game APIs & Engines / Engines, Libraries and Tools / [LibGDX]Render an electric beam? on: 2014-09-11 22:30:16
I want to create an method that renders electricity.

1  
2  
3  
4  
public void renderTeslaBeam(Point startPos, Point endPos, Color boltColor, float boltThinkness)
{
      .....
}


I want the beam to look something like this:
http://www.youtube.com/watch?v=beZHpaLo7e8&t=1m7s

Pages: [1] 2 3 ... 5
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (50 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (45 views)
2014-12-05 12:39:02

SHC (59 views)
2014-12-03 16:27:13

CopyableCougar4 (57 views)
2014-11-29 21:32:03

toopeicgaming1999 (123 views)
2014-11-26 15:22:04

toopeicgaming1999 (114 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!