Java-Gaming.org Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (616)
Games in Android Showcase (173)
games submitted by our members
Games in WIP (659)
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 ... 6
1  Java Game APIs & Engines / Engines, Libraries and Tools / Re: [LibGDX]Get pixels of a Texture on: 2015-08-28 13:13:52
For future reference, I read that Pixmap caches the pixel data in CPU.
2  Game Development / Newbie & Debugging Questions / Re: Eclipse, multiple classpaths? on: 2015-08-21 18:16:39
Note that this is a problem that only exist in development environment. Will work fine during production. So I will move the resource folder to project B.
3  Game Development / Newbie & Debugging Questions / Re: Eclipse, multiple classpaths? on: 2015-08-21 12:31:55
I have Eclipse project A which loads resources found in its project root.

I have Eclipse project B which uses project A. Whenever I execute project B, the resources A tries to load is not found, obviously because it's looking for the resources in project B root rather than A.

How do I address this issue?

For Project A:
"Java Build Path" -> "Order and Export" tab -> check the classpath elements that you wish dependent projects to have access to.


Thanks, that helped me clean up some code. But it did not solve this problem because the only folder showed up in "Order and Export" tab was A's src folder. The resource folder was not even there.

Do not load files via file system paths, use classpath resources instead and load those via ClassLoader.getResourceAsStream (for example).
So, first thing: Put all resources you want to load under some classpath root, such as /res or somewhere.
Second: Use the ClassLoader to load those resources as URL or as InputStream.
To complete this I have to refactor a lot of code, but thanks for the tip! ^^
4  Game Development / Newbie & Debugging Questions / Eclipse, multiple classpaths? on: 2015-08-21 10:39:07
I have Eclipse project A which loads resources found in its project root.

I have Eclipse project B which uses project A. Whenever I execute project B, the resources A tries to load is not found, obviously because it's looking for the resources in project B root rather than A.

How do I address this issue?
5  Game Development / Newbie & Debugging Questions / Re: Matrix/Transfom; rotate around z axis? on: 2015-08-20 07:56:10
KaiHH: I am sure your library is awesome. Personally dont to want to use an extra lib for one single method. I will try with LibGDX's Matrix4 a little bit more. Maybe you can help me?
Trying to convert this code:

1  
2  
3  
4  
5  
Matrix blockTransform =
                    Matrix.CreateTranslation(new Vector3(-blockOrigin, 0.0f)) *
                    // Matrix.CreateScale(block.Scale) *  would go here
                    Matrix.CreateRotationZ(blocks[i].Rotation) *
                    Matrix.CreateTranslation(new Vector3(blocks[i].Position, 0.0f));

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  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
        /// <summary>
        /// Determines if there is overlap of the non-transparent pixels between two
        /// sprites.
        /// </summary>
        /// <param name="transformA">World transform of the first sprite.</param>
        /// <param name="widthA">Width of the first sprite's texture.</param>
        /// <param name="heightA">Height of the first sprite's texture.</param>
        /// <param name="dataA">Pixel color data of the first sprite.</param>
        /// <param name="transformB">World transform of the second sprite.</param>
        /// <param name="widthB">Width of the second sprite's texture.</param>
        /// <param name="heightB">Height of the second sprite's texture.</param>
        /// <param name="dataB">Pixel color data of the second sprite.</param>
        /// <returns>True if non-transparent pixels overlap; false otherwise</returns>
        public static bool IntersectPixels(
                            Matrix transformA, int widthA, int heightA, Color[] dataA,
                            Matrix transformB, int widthB, int heightB, Color[] dataB)
        {
            // Calculate a matrix which transforms from A's local space into
            // world space and then into B's local space
            Matrix transformAToB = transformA * Matrix.Invert(transformB);

           // When a point moves in A's local space, it moves in B's local space with a
            // fixed direction and distance proportional to the movement in A.
            // This algorithm steps through A one pixel at a time along A's X and Y axes
            // Calculate the analogous steps in B:
            Vector2 stepX = Vector2.TransformNormal(Vector2.UnitX, transformAToB);
            Vector2 stepY = Vector2.TransformNormal(Vector2.UnitY, transformAToB);

            // Calculate the top left corner of A in B's local space
            // This variable will be reused to keep track of the start of each row
            Vector2 yPosInB = Vector2.Transform(Vector2.Zero, transformAToB);

            // For each row of pixels in A
            for (int yA = 0; yA < heightA; yA++)
            {
                // Start at the beginning of the row
                Vector2 posInB = yPosInB;

                // For each pixel in this row
                for (int xA = 0; xA < widthA; xA++)
                {
                    // Round to the nearest pixel
                    int xB = (int)Math.Round(posInB.X);
                    int yB = (int)Math.Round(posInB.Y);

                    // If the pixel lies within the bounds of B
                    if (0 <= xB && xB < widthB &&
                        0 <= yB && yB < heightB)
                    {
                        // Get the colors of the overlapping pixels
                        Color colorA = dataA[xA + yA * widthA];
                        Color colorB = dataB[xB + yB * widthB];

                        // If both pixels are not completely transparent,
                        if (colorA.A != 0 && colorB.A != 0)
                        {
                            // then an intersection has been found
                            return true;
                        }
                    }

                    // Move to the next pixel in the row
                    posInB += stepX;
                }

                // Move to the next row
                yPosInB += stepY;
            }

            // No intersection found
            return false;
        }


Full code

Here is my code:

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  
37  
38  
39  
40  
41  
42  
43  
44  
45  
   public static boolean pixelPerfectRotation(Matrix4 m1, Image2D img1, Matrix4 m2, Image2D img2){
      Matrix4 AtoB = m1.mul(m2.inv());
      Vector3 trans = AtoB.getTranslation(new Vector3());
      Matrix4 AtoBnorm = new Matrix4(AtoB).translate(-trans.x, -trans.y, 0);
     
      Vector3 stepX = Vector3.X.cpy().mul(AtoBnorm);
      Vector3 stepY = Vector3.Y.cpy().mul(AtoBnorm);
      Vector3 yPosInB = Vector3.Zero.cpy().mul(AtoB);
     
      int widthA = img1.getWidth();
      int widthB = img2.getWidth();
      int heightA = img1.getHeight();
      int heightB = img2.getHeight();
     
      for (int yA = 0; yA < heightA; yA++){
         Vector3 posInB = yPosInB.cpy();

            for (int xA = 0; xA < widthA; xA++){
                int xB = Math.round(posInB.x);
                int yB = Math.round(posInB.y);

                if (0 <= xB && xB < widthB && 0 <= yB && yB < heightB){
                   int alpha1 = img1.getPixel(xA, yA) & 0x000000FF;
                   int alpha2 = img2.getPixel(xB, yB) & 0x000000FF;

                   if (alpha1 != 0 && alpha2 != 0)
                      return true;
                }
                posInB.x += stepX.x;
                posInB.y += stepX.y;
            }
            yPosInB.x += stepY.x;
            yPosInB.y += stepY.y;
        }
        return false;
   }
   
   public static Matrix4 createMatrix(Entity entity){
      Matrix4 m = new Matrix4();
      m.setToTranslation(-(entity.width() / 2), -(entity.height() / 2), 0);
      m.rotate(0, 0, 1, -entity.getRotation());
      m.translate(entity.x(), entity.y(), 0);
       
      return m;
   }
6  Game Development / Newbie & Debugging Questions / Re: Matrix/Transfom; rotate around z axis? on: 2015-08-19 09:36:54
Thanks Smiley
7  Game Development / Newbie & Debugging Questions / Re: Matrix/Transfom; rotate around z axis? on: 2015-08-19 09:07:04
Thanks. Thats a good explanation. But I cant figure out how to achive that function in one of the following classes: Affine2 or Matrix4
8  Game Development / Newbie & Debugging Questions / Matrix/Transfom; rotate around z axis? on: 2015-08-19 08:13:21
Me again, trying to translate some C# code to Java with LibGDX. There is a method in C#'s Matrix class called CreateRotationZ(float radians) which rotates the matrix around "its z axis".
What do this mean?
9  Java Game APIs & Engines / Engines, Libraries and Tools / [LibGDX]Get pixels of a Texture on: 2015-08-05 14:01:52
In LibGDX, you can get the pixels of a Texture by calling texture.getTextureData().prepare() and then textureData.consumePixmap().getPixel(x,y).

My question is, what is the performance of these calls? I am okey with prepare() being slow as its only done once(during loading for example). But what about the other part?
10  Java Game APIs & Engines / Engines, Libraries and Tools / Re: A library for 2d shapes and collisions on: 2015-07-15 16:57:54
Hi!

I am working with 2d. However, Box2D is a physics engine and way to much for what I need.
11  Java Game APIs & Engines / Engines, Libraries and Tools / A library for 2d shapes and collisions on: 2015-07-15 14:31:58
In java, we have Shape interface which defines a bunch of shapes and handles collisions. But I dont think these are strong enough.  The collision methods dont take the rotation of the shape into consideration, for exmaple.

So I am looking for something more powerful. Something that at least support the following shapes:
- Rectangles
- Circles
- Polygons
12  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?
13  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?
14  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.
15  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.
16  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.
17  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.
18  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);
19  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?
20  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?
21  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.
22  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
23  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?
24  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.
25  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.
26  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.
27  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.
28  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?
29  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?
30  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
Pages: [1] 2 3 ... 6
 
Coldstream24 (18 views)
2015-09-03 00:41:28

Andrew_3ds (29 views)
2015-09-01 19:08:10

afikri (20 views)
2015-08-31 09:30:22

afikri (27 views)
2015-08-31 09:30:07

afikri (15 views)
2015-08-31 09:27:24

afikri (17 views)
2015-08-31 09:26:40

Roquen (32 views)
2015-08-29 11:30:54

GamerC4 (38 views)
2015-08-22 20:38:50

GamerC4 (36 views)
2015-08-22 20:37:18

GamerC4 (42 views)
2015-08-22 20:37:01
HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30
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!