Tag Info

Hot answers tagged

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 ...


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 ...


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 ...


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 ...


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 ...


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 ...


2

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 ...


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 ...


1

You could check to see if the key was pressed in the previous frame. Consider doing something like this: bool DownPressed; bool UpPressed; .... if (KeyBinding.downDown) { if (!DownPressed) { DownPressed = true; nextEntry(); } } else { DownPressed = false; } if (KeyBinding.upDown) { if (!UpPressed) { ...


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 ...


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 ...


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 ...


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 ...


1

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 ...


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; ...


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 ...


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] = ...


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.



Only top voted, non community-wiki answers of a minimum length are eligible