Tag Info

New answers tagged

1

I don't think this is possible in your case. A repeating texture at the hardware level needs to span the entire texture, at least on the axis it is repeating. You can still repeat the sprite if you write your own routine. You would just call draw() multiple times. If you decide to load your repeating sprite as a separate texture so you can render it in one ...


4

The problem you are facing is conversion between two different coordinates systems: the graphical one and the input one. Graphics coordinates Like you said, libGDX uses a 1 to 1 ratio between space coordinates and pixels, and starts in the bottom left corner. But it can be anything, really. That is just the default behavior of libGDX. You could change the ...


1

In a client/server architecture it is not required that client and server are implemented in the same programming language. They usually communicate by sending raw data via network sockets. So you can choose the technology for each component separately, depending on your requirements, skillset and personal preferences. An exception would be when you want to ...


0

Subtract the box position from the mouse position, normalise that vector and apply that as force You can multiply the normalised vector by a float to increase the force.


1

You need to specify the width and height when you draw the texture. batch.draw(texture, x, y, width, height); In your case you want to set the width and height to one since one wall tile is one world unit big. Because you don't specify a width and height the batch uses the width and height of the texture. That is why it covers 16 world units instead of ...


0

(i just want to feel like i am helping a game developer) From my little knowledge in game development i think they are actually intercepting but not appearing as such, you see you have a rectangle ship-in respect to its bounds ________________ | | | | | ship one | // your rectangle shaped ship in layout | ...


0

Comparing your FishMoveHelper to the GuardianMoveHelper, I do notice two key differences. 1) You have: if (this.update) While the guardian has: if (this.update && !this.field_179930_g.getNavigator().noPath()) // |-- entity --| Try using: if (this.update && !this.entity.getNavigator().noPath()) 2) The guardian ...


0

The Text class is an Entity that has a VertexBuffer. If you want to transform the Text then just use a custom VertexBuffer with more vertices. If you have any questions concerning the calculation of the uv coordinates of the vertices to create the warp just ask.


0

Here's a launcher I made about a year ago: package Joehot200; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Toolkit; import java.io.BufferedReader; import java.io.EOFException; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import ...


0

Maybe you should consider making a two dimensional array for the chunks, [0][0] being the top left chunk of the map. That way you always know which chunks are surrounding the player and if the player reaches an end, you can put the first chunks next to the last ones, if you want to make the map loop.


0

It seems that BufferedImage does not keep that kind of information from the original PNG file. The type of the BufferedImage may or may not correlate with the type of the PNG. You can check the type of the BufferedImage with BufferedImage.getType(), which may help you, but the implementation of image loading is free to convert the images to other formats at ...


2

You need a finer-grained method of moving your viewport. What you're doing now is essentially moving it by the size of a single tile every time you scroll, when what you want is a smaller increment. You do this by using a camera object represented by an x, y coordinate. Update its position with your scrollIncrement, then use that as the starting point for ...


0

From here, you can see how to use the touchUpmethod that is in the InputProcessor interface with the GestureListener that you already implemented. For what are you asking, it should be something like this: public class Inputs implements ApplicationListener, GestureListener, InputProcessor { boolean isFling= false; //A lot of code with the ...


0

Not directly, but you could create a font for libgdx from a .otf using the Hiero tool to convert your font, or create one at runtime but (like the author of this site says), it's something that you should try to avoid. An example of how to load an .otf font can be found here


0

What I have found is that is good to make a handler class that has a list of GameObjects and draws, ticks(update) and can add new objects. ex: import java.awt.Graphics; import java.util.LinkedList; public class Handler { public LinkedList<GameObject> objects = new LinkedList<GameObject>(); private GameObject temp; public void tick(){ ...


0

It is not necessarily a better way to have a separate class to draw your entities. It is just one way how to implement how your entities get drawn. But to answer your question. One way could be that each of your entities give access to the the data which are necessary to draw a entity. As soon as your entity provides such function then your rendering ...


-1

When you draw a shape, there is sometimes a degree parameter (at least when you draw a rect) http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/glutils/ShapeRenderer.html#rect-float-float-float-float-float-float-float-float-float- EDIT: also, any libgdx Shape Class will have a rotate function. Maybe instead of keeping your ...


0

All of your code seems fine exept for this typo on getRandomPosition(): pos.right = pos.left + Tile.TILE_HEIGHT; which should be pos.right = pos.left + Tile.TILE_WIDTH; I'm not sure if that can be the root cause of the problem, but there's always the option of not using recursion and use a loop, should be easier to debug: private RectF ...


1

I think problem is that you are using the size variable instead of the current count of the items that the array contains, in your for-loop. Example for-loop you should use: for(int i = 0 ; i < count ; i++) playerUnits.get(i).doSomething();. When you create an array, its default size is 16, even though it contains 0 items. As seen from the Array source ...


0

To render in a seperate class create a Renderer.java file with a single method named render and create an instance of it in the create() method of your main game class called Renderer renderManager = new Renderer() (filling in any constructors you need). In the render() method of your main game class call renderManager.render(). Now any code that would ...


2

A class is a chunk of code that can be reused as an object. An object is a single instance of something that can have certain properties (e.g. an integer representing a characters intelligence or money amount). Now that we have that settled... Going light on object creation and heavy on object reuse is generally better. It uses significantly less RAM to ...


1

Disclaimer: artemis-odb dev here. -Changing the Entity System, i know of Artemis, but it would be great if you could point me at something else for Java if you know a library that does it better. I'm not sure whether you're referring to vanilla artemis or artemis-odb, but the latter improves on performance considerably with regards to mutating ...


0

So, i figured out how to do it quick and dirty, i subclassed Array (libGDX.util) to allow for faster removal of Entities and then i swapped it with the normal Array inside the Engine class of Ashley: package de.vatterger.threadedSim.tools; import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ObjectMap; ...


1

Your problem is your translation matrices. You are not translating enough. Your quad starts at position (50, 50) and is of size (200, 200). That means we have 4 vertices: ( 50, 50) (250, 50) (250, 250) ( 50, 250) You are applying a translation of 200/2 (100) on both axis, which will transform your vertices to these: (-50, -50) (150, -50) (150, 150) ...


1

I had the solution for awhile, but I forgot to post. Here's the method to move a list of enemies towards the player. public void moveAlien() { for (Aliens a : aliens) { //List of Aliens (Enemy) Sprite s = a.getSprite(); //Get current enemy's sprite float targetX = spacemarine.getX(); //Player's X float targetY = spacemarine.getY(); //Player's Y ...


3

In very broad strokes, you can accomplish this by: Yes, using shaders Binding three textures to the shader program before drawing On your polygons, have the usual UV vec2 for each vertex. This is used by any of the textures Have another attribute which is "weight of each texture at this vertex". It could be a vec3 or three separate floats. For the ...


4

There is a nuance here. You asked: So I am wondering, why not just do something like: while(running){ Update(); } I believe this would call every frame. This is false. If you place your Update() method inside a simple while(true) loop, it will be called as much times as the processor can handle. If your processor can run it 123456 times a ...


-1

Move the tick function outside the while loop and next to the render function Then you can even make a whole new function with render and tick if you want. While (running) { Render (); Tick (); }


1

Try this: package com.mycompany.mygame; import com.badlogic.gdx.*; import com.badlogic.gdx.graphics.*; import com.badlogic.gdx.graphics.g2d.*; import com.badlogic.gdx.math.*; public class MyGdxGame implements ApplicationListener { public float x; public float y; public float w = 50; public float h = 50; Texture texture; ...


0

Using SpriteBatch is likely going to be the best option. Passing your batch as an argument to another class' method is generally not going to have any noticeable performance impact. This is also a very easy way of going about the problem because you can just call batch.draw() on your textures inside the desired method.


0

No. Pixels are squared. At least from an API point of view, you can safely assume that your pixels are square, and that if you draw a circle, you will get a circle. What you're most likely experiencing is a problem where your target canvas size is not the same as the screen resolution, so pixels will seem stretched. What you need to do is figure out the ...


0

Java can be quite a pain when trying to load files that are inside the .jar. So first, try to put your sprites folder outside of your jar, on the same level. See if that works. To load files that are inside the jar, you must use this following piece of code to retreive it's URL: getClass().getResource("myimage.png") So your line of code would be : ...


0

Thread handling is always a pain and the source of countless obscure and irreproducible bugs. I would recommend you to leave the thread management of the receiver threads to the operating system and use Non-Blocking IO with Selectors and SocketChannels. This allows you to handle hundreds or even thousands of sockets with a single thread. A common NIO ...


1

JSON Philipp makes a good point about JSON. It is human readable and makes debugging network code easy. If you have no experience in programming network code, this would be the way to go. Yes, there is a lot of overhead by using JSON, but for small to medium data transfers, it should be more than enough. And like Alexandre Vaillancourt said, you can always ...


0

When you make an online game where multiple connections to clients will be made, you want to read from them as fast and soon as possible. Inducing lag on the server side is a bad idea, especially for packets that need to be treated fast. The best way to handle these connections is to have one thread running for each client. Most networking engines will ...


2

To get decent performance, you should define your own private class FloatArray which contains a float[] values; (lowercase f !) and an integer count which keeps track of the "logical" size. When there are no elements, set values to a new array of 16 items and count to zero. Then when you need to add elements, check whether count is greater than or equal ...


1

You cannot use a standard array without knowing its size. You must use an ArrayList. But that is not where your lag is coming from. You have an issue with your algorithm. If you share your code, we can help you beat it into submission. I suggest just starting and finishing with an ArrayList. If you are creating a new ArrayList and adding the objects ...


1

In your Map class, you are instanciating a Peter object on creation on line 25: Peter peter = new Peter(); In your Peter class, you are instanciating a Map object on creation on line 12: Map map = new Map(); So, when you create on of the two objects, it will start creating an infinite amount of maps and Peters (probably not what you want). This is a ...


1

I am not 100% sure that this will solve your problem but it seems that you forgot to register the PositionMessage class. Be sure to register it in the same order on the client and the server and also, do not register the server and client classes.


0

You don't have to provide the host address in your server code on Kryonet. Your computer network has its own IP address which is used by Kryonet when you start the server. So on client code, when you start the client you put in the IP address (127.0.0.1) in case where both client and server are on same network. In the case when server and client are on ...


2

In your DesktopLauncher it's not enough to just new up a LwjglApplicationConfiguration, you have to pass that along with your Game instance to the constructor of a LwjglApplication. Try changing your main method to this; public class DesktopLauncher { public static void main (String[] arg) { LwjglApplicationConfiguration config = new ...


1

Your issue seems to be coming from the fact that you are using degrees to calculate your rotation instead of radians. Here would be a way to fix your issue: else if (key == KeyEvent.VK_SPACE) { double deltaX = p.getDestX() - p.getX(); double deltaY = p.getDestY() - p.getY(); double angleRad = Math.atan2(deltaY, deltaX); double angleDeg = ...


1

I just had the same problem This is my solution public class SpriteAccessor implements TweenAccessor<Sprite> { public static final int ALPHA = 1; @Override public int getValues(Sprite sprite, int tweenType, float[] returnValues) { switch (tweenType) { case ALPHA: { returnValues[0] = ...


0

I have found some sort of a workaround this, but I am not sure if this is a good way to code. When a key is pressed, I set the angular velocity to 10 and then at every update, I ask it to check if(weapon.getAngle() >= Math.PI / 2) { weapon.setAngularVelocity(-10); } if(weapon.getAngle() <= 0) { ...


0

The call to camera.setToOrtho sets the cameras position to the center. So it's P(0,0) is the middle of the Screen. So you are seeing everything from P(-Gdx.graphics.getWidth() / 2, -Gdx.graphics.getHeight() / 2), which is the lower, left corner, to P(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2), which is the upper, right corner, where your ...



Top 50 recent answers are included