Tag Info

New answers tagged

2

EDIT Actually, Timer's schedule method should work in this case - maybe it's running straight away because you have 100ms as your delay time instead of 1000 (from your code above that is). If you're working in a multi-threaded environment, then make sure you handle possible concurrency issues. A possible alternative would be to use System.nanoTime() ...


2

Before anything, I'd look for a heap profiler and make sure it's the GC that's causing problems. However, if you find that it is indeed the number of objects you have in memory, you've already come up with the basic solution; page your chunks out to disk once in a while and only keep nearby ones in memory. But, as you've seen, there are problems with the ...


-1

e holds a cached set of coordinates (you keep it around and it won't ever change the x and y values). You will need to get a new mouse event or query the coordinates explicitly.


0

The good news is that constant width Gaussian filter is separable thus you can gain good performance even for large kernel sizes, i.e this cuts the computation from the naive O(n^2) cost down to O(2n). The separable Gaussian filter is implemented by having two passes over the image: First performing 1D horizontal Gaussian blur, followed by 1D vertical ...


-1

You can call .setText("Some String"); on your label in your Render-method.


2

I'm assuming you're using the standard Java 2D API, not OpenGL. In that case, you render your graphics to a buffer image first. Then, to render that image to the screen, you can either use a Graphics.drawImage call that allows resizing your buffered image: public abstract boolean drawImage(Image img, // the buffer image int dx1, int ...


0

the real question is "do the convenience methods simplify the code that is looking at any given object"... if they do, then they are worth while.. Unity uses the "Game object HAS a transform" and the transform is also where the scene graph is linked together... but that means when you grab a reference to a game object, you have to go through an additional ...


0

As others have pointer out, you should generally prefer composition over inheritance(is-a vs. has-a): public class Creature { private Inventory mInventory; public boolean hasInventory() { return mInventory != null; } public Inventory getInventory() { return mInventory; } public void setInventory(Inventory ...


1

Oh man- I've implemented this a time ago... The map is divided into map chunks - I've created separate files for each map chunk... a map chunk consist of 32x32 tiles in my implementation, you may vary on this whenever the player (centre of red X) is moving inside a chunk you can detect if the player is moving from one chunk into another... // Depending ...


1

In general you should prefer composition over inheritance if answer to question "A is a B?" is "No". E.g. Inventory is a Creature? No, then it should be a component. But Vampire is a Creature, so it's logically inherited. My other answer to similar question can be also useful.


2

An Inventory class with a matching field on the abstract class Creature seems best. You can perform a null check against this field to see if a creature has an inventory. This also allows you to reuse the inventory class as a field of non-creatures like bags, chests, rooms or anything else that suits your game.


2

This might be too late for you, but for the benefit of web searchers, I'll answer: Create an empty canvas (AWT). Set the size of the canvas to be equal to the LWJGL Display. Add the canvas to the Java Swing form. (There's a reason for this). Set the canvas as parent of the LWJGL Display using Display.setParent(canvasName);. (Remember you might also need to ...


1

Look at what's happening. SaveX is 300, SaveY is 0. When you normalize moveVec you take the Vector (300,0) and resize it to be a length of 1, which makes it (1,0). You test to see if 300 > your position, if so you add moveVec.getX(), otherwise you subtract. So you move 1 to the right. You then test to see if 0 > your position, if so you add ...


0

When starting to code a multiplayer game, you should really take your time on how you create your "packet system" (because you need one). I very strongly recommend using UDP (userdatagram protocol), which is a lot faster than tcp for real time games. Have a look at tutorials on how to create udp sockets in java, and create test projects to create a text ...


0

Services like Kongregate, Steam, and others provide an API for matchmaking and achievements, but you pretty much lock your game into working with those services.... Or you could host your own web services based matchmaker on almost any web hosting service that allows PHP or ASP.Net.. set up a forum for your game to get "free" user account creation to provide ...


0

This question is confusing but my understanding of it is something like this should solve your problem in the draw method ... this.camera.update(); // update the camera var y = sprite.getY(); // determine y value of map if(y<100 || y>=200) // if y is in usefull range { // render the tile map this.renderer.setView(this.camera); ...


2

I know this is old, but I finally discovered the solution. In my game, I am using g.translate(x,y); but I was using a float for the x and y values. So I did this: g.translate(Math.round(transX),Math.round(transY); Now there are no more vertical lines! Hopefully this helps anyone else with this problem.


1

It depends a lot of how your game actually works, but in most games it is not necessary to send all positions of all objects after every frame. In most cases, most of the information will either not change right now or will be changing in very predictable ways (like an object moving in a straight line). It is often a lot more bandwidth-economic to only ...


2

From my knowledge using the Serializable language feature for realtime game networking thats running at 40+ FPS is very bad. I would send data in a plain binary stream for example Ive got to send the following variable in a class... (String) player name, (Integer) player health, (Integer) player model id, (Integer) player x, (Integer) player y I would ...


0

To your 3rd question, yes, you could preload the necessary models and just update positions and whenever a new players connects, load the extra info (you could do this asynchronously so as to prevent lag spikes). You could also calculate movement cycles (animations) on the client or on the server and then send the player's current animation 'step' to the ...


1

To expand upon my earlier comment: For a 2D tile map, I don't usually see any need to stream the map into memory, or load it by chunks. The easiest gains will come from simply not rendering any tiles that are off screen, and not updating any entities that are more than X screen size units away. If the map is truly massive, to the point that you can't ...


0

I'm not too sure if I understand the question correctly so forgive me if my answer if off, but this is how I would go about a turn-based event system. Firstly, the actions that are represented by strings and ids can be converted into something more object-oriented which would be something like: public abstract class Action { public abstract void ...


1

Ok the obvious stuff ... Remove all the timeout calls. Remove the Thread.Sleep() calls. Have you tested just this code on its own? How do you know its "slow"? Are you sure the code that reacts to this isn't slow? Why are you creating a new connection on every send ... The process should be ... create "connection" / stream reference. send, send, send. ...


0

If i understand this correctly then you take some data and then as part of the rendering process you distort the postition of that data ... this.camera=new OrthographicCamera(); this.camera.translate(map.getMapPixelWidth()/2, map.getMapPixelHeight()/2); this.camera.update(); view=new StretchViewport(map.getMapPixelWidth(),map.getMapPixelHeight(), camera); ...


1

I'm currently writing a text-adventure myself and choosed the following (unoptimized, clumsy ect.) approach. Why is explained in the conclusion of the answer. For the short version, skip to the end of the answer. My game is structured in areas which contain locations. A player can have roles which allow him to do something (or disallow him from doing so). ...


0

ouch ! ... eventing is normally pub sub ... I say "this happened" and you as a handler go "ok now i need to do ..." this presumably is like some sort of action list system in which case I would implement it as such. Does java have lambdas yet? I would have somehting like this in c# ... class EventManager { List<Action> actions; void ...


0

Ok the question is pretty vague in that it reveals nothing about your game design but here's my take on any form of "game world": You painted a picture of this in my head .... public interface IArea { public void Enter(Character newChar) { ... } } public class World { public List<City> Cities { get; set; } } public class City : IArea { ...


0

You can start by doing this ... I can load new tiles but how do I load new chunks? Once you have that in place you can then choose what chunks to render by using some basic positional logic like "get me all the chunks with tiles between pos1 and pos2" pos1 and pos2 can be simply determined like this ... pos1 = char.Position - renderDistance; pos2 = ...


0

Cities are the same as the rest of your environment. How do you define it? I think your 'rooms' are styled different - some with treasures and some with monsters. So your cities have some rooms with shops and some with parks. For me, it is the same approach.


1

A good rule of thumb is to have your content be data driven. You would store this data externally and create a class to load in the data. There are lots of reason to do this, such as You don't have to recompile when your data changes You can use Excel or a text editor to edit the data. The data load can be abstracted from the data itself


0

Don't use JFrame, instead use BasicGame subclass and AppGameContainer (it's much better than JFrame). And to your problem, you have to create a Camera class. That's all already covered here.


1

Actually it's already present in Vector2 class. You can use something like this: Vector2 touchPoint = new Vector2(211,312); // random touch position Vector2 center = new Vector2(world.getWorldWidth() / 2, world.getWorldHeight() / 2); // center of the world float width = touchPoint.sub(center).len(); // length of resultant vector float angle ...


0

Yes, of course there is a way...if you implement it. The technique you seem to be looking is often referred to as "terrain paging". It stems from the fact that you divide your terrain/map into multiple pages (basically chunks / tiles) and only load / render those close to the player. In your tile-map scenario, you already have the pages (= your tiles or ...


0

First I agree with the other answer about camera location code. On your display loop I would draw everything first, then update everything after that, then repeat. Second, I have a game I'm working on right now that has a character (space ship) that can travel anywhere in a 2d world (3d game with a flat map). I use something like this to change the ...


1

This is very simple, actually. You don't need to translate the camera (that is dealing with Matrices, I think?) using the "translate" method. You can simple set the camera's position to your sprite's position (assuming you use the x-y coordinates where (0, 0) is the bottom-left corner. Or extend the "Sprite" class; either way should work). In your camera ...


0

From your example, I assume you are making a 2D horizontal scrolling game. If I assume your game scrolls from right to left (player moves toward the right edge of the screen), and that the CameraX value is 0 at the start of the game and increase when the player moves right, then your rendering code should be: for(int i=0; i<chunkLoad; i++) { ...


0

So IF I understand this correct you are dynamicly creating some nodes(tiles) which define the "game" engine. These nodes are connected by vicinity so that each node has a specific number of neighbour nodes and it all works great. The part of where the issue comes in is that those neighbour nodes need to exist for you to be able to define what sprite should ...


1

I have two possible solutions. 1) Generate a seed in the beginning of the load. Then load an original world using said seed. A large chunk of the world, you can then use that seed to generate large amounts of the new world while using minimal memory, and the original world will give you enough of a buffer till you get to that section. 2) Generate a group ...


0

The solution was provided by William'MindWorX'Mariager: Only update the tiles in the camera view if the camera view has moved a certain amount, and leave everything else alone. At least, that's how I perceived it, and it worked pretty well.


0

Just generate the complete map before the start of the game, generating it while playing seems silly to me, but I don't exactly know what your goal is. Then just render the the visible tiles to the screen. When a tile needs to be updated just update it, if you have too many tiles that needs updating on a single frame just update the tiles visible first and ...


1

It looks like your character is entering a tile and then you're setting it just outside of it. If that "just outside" part is actually the border then it's still intersecting and will react the next turn as well. Additionally if you don't also reset their velocity when they hit the barrier, they'll bump it again on the next loop. On a side note: you don't ...


0

I'll try to give a two-fold answer: On the one hand, giving a bit of source code as a MCVE. On the other hand, I'll quickly try to point out why implementing this on your own is a bad idea. I'll start with the latter. Why you should not implement it this way You mentioned in the comments I was always under the impression that this was a more efficient ...


1

It may not be necessary to go the Quadtree route as you're suggesting. How about breaking the problem down into two parts: Store the heightmap data in a 2D array so that nodes can be accessed with O(1) time complexity. Decide how far apart each node is in world-space coordinates. E.g. The coordinate (64, 64) might correspond to the "terrain-space" ...


0

You can pass an empty transition to the second transition parameter to prevent the additional transition from playing. this.enterState(SPLASH, new FadeInTransition(Color.black), new EmptyTransition());


1

I have never used a viewport without a stage, but replacing width and height with the calls to Gdx.Graphics.getHeight/getWidth that you are using causes the same behavior you are experiencing. Removing those calls and using the passed values should fix your problem. public void resize(int width, int height){ stage.getViewport().update(width, height, ...


2

You can't. Scaling is just applying a coefficient to all coordinates, it doesn't take the coordinate of the camera into account. If what i understood is right, the visual effect you want imply to move the camera toward the coordinate of the mouse as you zoom. You can achieve this by translating the image on the directed vector (mousePointer, ...


0

You need to transform the world space rotation vector to model space before applying the rotation. Vectors are transformed with inverse transpose of the matrix, i.e. v'=transpose(inverse(M))*v Because models generally define model->world matrix you need to invert this to get world->model matrix. So you need to calculate v' = ...


1

If you're using velocities for this, the "jump distance" will be handled automatically. The distance on the X axis traveled during the jump is the product of the time in the air, and the X axis velocity. Say your jump takes one second to complete. If your character is traveling at 10 units per second on the X axis, during that one second jump, they will have ...


0

I'm not quite sure how to do this in standard Java, but in LWJGL I made an extremely simple method to check if the game is paused or not. Also, instead of having the gamePaused as a boolean it could be an enum. while(Keyboard.next()){ if(Keyboard.getEventKeyState()){ switch(Keyboard.getEventKey()){ case Keyboard.KEY_P: ...


1

You're monster locations are based on a random number: monster.setPositionXY((r.nextInt((int) width)), (r.nextInt((int) height))); You initialize width and height with: width = Gdx.graphics.getWidth(); height = Gdx.graphics.getHeight(); So your monsters will be placed on a random location in screen coordinates. Now I'm not sure about your drawing code ...



Top 50 recent answers are included