Tag Info

New answers tagged

0

I guess you're switching to "normal" state too early. In fact, you're doing it right after you switch to "jumping" state, with just one instruction inbetween, so actually its like continuos "normal" state, "jumping" is to short to ever get noticed by render method. Jumps should last some time, and then you should switch back to "normal" state after you land ...


0

It is never called because in the touchDown function you are calling stateModifier("normal") right after stateModifier("jumping"), so the state will be set to NORMAL when the function ends. In the update function you are testing if the state is equal to JUMPING, but is not, it will be NORMAL.


1

You could update the position over time: currentPos = currentPos + Math.signum(currentPos - touchedPos) * wayPerTime * deltaTime; wayPerTimestep is your velocity. deltaTime is the time passed since the last update. currentPos is the current position of your player (might be x, y or both as vector). touchedPos is the position the player has clicked on the ...


1

You can use InputAdapter class and methods touchDown(int screenX, int screenY, int pointer, int button) Called when the screen was touched or a mouse button was pressed. boolean touchDragged(int screenX, int screenY, int pointer) Called when a finger or the mouse was dragged. boolean touchUp(int screenX, int screenY, int pointer, int button) Called when a ...


0

Well you could just start with a plane/quad with a static/animated water texture. From there you could maybe make an animated mesh with a texture. If you want to get into shaders, then you'd have to research the optical physics of water before trying to develop any


0

I want you to think about a refactoring of your code. Since you already have a vector structure (Vector3f - I guess its from lwjgl) why not use it? // Calculate the vector pointing from the mob toward the position with // a length of their distance. // This is equal to: wayTowardPlayer = playerPosition - mobPosition Vector3f wayTowardPlayer = new ...


0

Like @Terje says, the short answer is "Yes, OpenGL can outperform Swing." You've seen modern video games, you know current graphics hardware can do truly amazing things. Pragmatically, what you can do is look at the CPU load of your current "Pong" game, or whatever it is. Based on the CPU percentage, and what your ultimate goal is, maybe Swing is just ...


1

In this line ball.applyLinearImpulse(new Vector2(0f, 5000f), ball.getPosition(), true); I think the point where you put force it relative to object position, so you put impule in ball.getPosition() + ball.getPosition() Try to use public void applyForceToCenter(Vector2 force, boolean wake) or ball.applyLinearImpulse(new Vector2(0f, 5000f), new ...


1

I guess the reason why you were choosing this architecture was to keep the computation costs and computation effort low on the server, allowing it to be lightweight. (Another advantage of this approach is that the usually low upstream of the clients are relieved by a server acting as a broadcasting intermediator.) Of course the downfall is that it now ...


0

It's usually not a good idea to couple the framerate to the update rate of the network. The internet is just too unreliable for this. Your clients will feel every single lag and jitter. A better method is to have the server only send changes and have the clients interpolate with them. So when an object is moving from position A to position B over the ...


1

OpenGL performance will outperform Swing quite heavily once you start doing something a little more advanced. I dont have hard numbers to back my claim, but I have experience. I too started out with pure Java2D, with BufferStrategy and the works. And it was ok for Pong, Snake, Tetris, and so on. But once venturing beyond in graphical effects (blending, ...


0

The way that I did it was by taking the player's x co-ord and y co-ord, made them negative and added them to screen width/height divided by two FactoryWU.frame.GP.cam.locationX = (int) (-FactoryWU.world.player.getXInt()+((this.getWidth()/cam.zoomLevel)/2)-(10*cam.zoomLevel)); FactoryWU.frame.GP.cam.locationY = (int) ...


0

if yow saw this pop up while you start to run your code just click your main class which contains your main method


2

You probably have object leaks. Objects that are still referenced somewhere in an array or list, creating more and more objects for the garbage collector to process as the game advances. Or more and more AI objects that are off-screen but still active and processing on every frames.


0

You only truly need a separate class if you're multithreading, so you can have separate constructors, one ran in the render thread. Even then its up to you whether or not you want to do that. The big reason is just organization. More important than anything is to make sure your textures and render programs are static. You also want to render all of a single ...


0

Divide the map in chunks of tiles, lets say chunks of 32x32 tiles, and create a mesh with the geometry of that chunk and map each 4 vertex of each tile with a tileset texture. Build all the map using those chunks join together and draw only the ones visible to improve performance. Use the texture only as reference to know the type of tile to draw at each ...


1

I suggest moving the target slowly rather than the angle. Try this: Vector2 Target; // Interp is a value between 0 and 1. When 0, the target never moves. // When 1, the target moves instantaneously. Intermediate values cause the target // to move at different rates. void UpdateTarget(float interp) { Target = interp * Mouse.Position + (1 - interp) * ...


1

I think any linear function would be fine for this. You can keep two variables one for your spaceship's current angle spaceshipAngle = Math.PI*k, and one for the current angle that the user inputs with his cursor cursorAngle = Math.PI*p. And what you do is if (Math.Abs(Math.PI*k, Math.PI*p) < Math.PI) { if (Math.PI*k < Math.PI*p) k += ...


0

This could be due to double & triple buffering and processing spikes, probably due to GC. frame 0, delta 0, display buffer 0, draw buffer 1 time passed: 0.016 frame 1, delta 0.016, display buffer 1, draw buffer 0 (at +0.016) time passed: 0.016 frame 2, delta 0.016, display buffer 0, draw buffer 1 (at +0.016) time passed: 0.032 hickup frame 3, delta ...


0

I've had some trouble with this myself. I've never actually found a perfect way to do it, but a* pathfinding with Jump point search should make it possible. Take a look at this: http://gamedevelopment.tutsplus.com/tutorials/how-to-speed-up-a-pathfinding-with-the-jump-point-search-algorithm--gamedev-5818


0

You don't have to do it that way. That just happens to be one of the easier solutions that also give good results. You can also attempt to compile a font down to outlines and render those, but that's a lot harder. Note that what you're saying isn't that difficult because you can do it mostly automatically. And yes, there are libraries that already implement ...


0

You're doing something strange: Every frame, you calculate the x,y,z values of the bullet's movement, based on a yaw and pitch that will never change. Why not create a vector3 that stores the direction and speed of the bullet in the bullet constructor? This way, you can do the calculations once per bullet, and then just add its speed vector to its current ...


0

Well for one, your x,y,and z would stay zero based on moveFromPosition. If you want the bullet to follow a certain path, you need to get rid of the zeros, math calculates anything multiplied by 0 is equal to 0 Your next problem is you are over-complicating the math in moveFromPosition. All you need to do during an update is loc.x += ...


0

First question: You need to have multiple images to suit the user's screen size. Second question: To get the user's screen size you would need to call the onSizeChanged() method which automatically captures the values of the screen, which you can then use to scale your images to fit the screen.


5

Sarting with the clouds, a simple method is to draw them as three layers: Layer 1 is the bottom layer, and is drawn first. It just contains the cyan background. Layer 2 is the middle layer, drawn between the other two, and it represents the 3D highlights. The background in this layer would again be transparent (represented by a purple colour in the ...


0

You should let the user choose the resolution in the graphics options, or at least the ratio (16:9, 4:3). Obviously if the resolution is right for the screen, there shouldn't be any pixel stretching.


3

You could achieve this effect using parallax scrolling by making the earth and each shade of green a separate layer. With a parallax effect, no 3D calculations are required, and you get to stay with the pixelated, simple color style you're using. Note that parallax doesn't have to be limited to just horizontal motion. Vertical movement (when the camera ...


0

I would recommend having something like this in your loop: if (<death check>) break; <death check> would probably best be suited to a method (to steal from Josh Petrie, Character.IsDead()) which does the actual checking and returns a boolean true if they are dead. What the break keyword does is immediately, unhesitatingly break out of the ...


3

You already have a game loop that (currently) runs "forever:" while (true) { ... do stuff ... } What you want to do instead is guard this loop with a variable that says if the game is done yet: bool done = false; while (!done ) { ... do stuff ... } Then, every time through the loop after you've checked for player input, drawn the map, et cetera, ...


0

You can add a depth component to your 2D textures and set the depth value in the pixel shader. There will be some performance loss due to setting the depth in the pixel shader but shouldn't matter for a 2D game on PC. The other way is to use multiple layers of 2D textures for your background.


0

The setBounds() method comes from the Actor class, which the Table class subclasses. It is usually used for stuff like collision detection, but not setting the size of your actors. In your case, you can go as simple as calling table.setFillParent(true); to have your table fill up the entire space in its parent (btw, are you adding it to a stage or ...


0

All collision detection methods can benefit from pruning the list of objects to test before testing. One of the ways is to partition your world so you can query the objects that may intersect with some area (false positives are allowed) then only do the collision test on those objects. For example store the axis aligned bounding box in a grid and knowing ...


1

You need to change the collision of a ball against an infinitely thin line to an infinitely small point (ray) against a thick segment with two round ends You transfer the ball's thickness to the segment. Both end points become circles. The collision then becomes a 2D ray-cast operation.


1

TLDR: VBOs makes a huge difference in performance. One simple reason to use them would be that OpenGL ES (mobile devices) don't support glBegin(...)/glEnd() so you have to use glDrawArrays() but not necessarily VBOs. The main reason to use VBOs is that it allows the OpenGL driver to keep the vertex data in GPU memory, rather than CPU memory which forces ...


2

That spacing is called font kerning. And that is exactly why there is padding in front. The purpose of kerning is so that letters fit nicely next to each other, and that they aren't too close or too far away from each other.


0

Double check if you are truly using viewport correctly. You're not rebinding the texture to the FBO. That SHOULDN'T be necessary, however the spec makes no guarantee that glTexImage won't screw up any attached framebuffers, so assume that it can. If that doesn't work then its the way you're sampling from it. For simply allocating a texture with undefined ...


0

If someone is able to pick through the binary and find out the algorithm - you'll never really be able to prevent that, so don't bother. To stop simply use a cryptographic hash! Suppose you have this: function computeHash(levels) { code = ""; for(level in levels) { code = hash(code+level+level.isComplete()+"MAGICSALT") } } It's ...


9

You can create a replay file as proof of work while the player is playing. Start the game, save the starting conditions including the name of the level and the pseudorandom seed, record the exact timestamped input states (mouse movements, key or button presses, etc.) that your game's input layer passes to its logic layer, and stop recording once the ...


2

To be safe I'd delete and recreate the entire FBO. Some drivers have strange stability issues when recycling/resizing FBOs. I've had entire screen flickers and occasional crashes. Switching attached textures to another of the same size & type seem to work fine all the time on all drivers but with some drivers it is much faster (more than 100x) to have ...


3

If you want to do this totally in the client side and you don't consider the private storage provided by your platform to be secure enough (e.g. if there's actual money involved in completing levels), what you need is a proof of work. Your save file must contain an information that is designed such that creating the information is difficult to calculate ...


1

If you prefer using an external file to hold save information and it is in a place that would be tamper-able by users you may want to read up on how encryption works and use that to prevent anyone from being able to make meaningful changes to the file. Something like a Feistel Cipher should be a good starting point and would be sufficient to stop someone ...


18

Storing the completion information in a local file is a simple and perfectly acceptable method of doing so. Fundamentally, this is what every game will do to track progress (in some fashion, although the specific formats used for the data and the storage mechanism will differ). Protecting the file from tampering is more difficult. If there's no compelling ...


0

for (int i = 0; i < wallList.size(); i++) { Wall wall = wallList.get(i); wall.update(); if (wall.getX() < -1 * wall.getImageWidth()) { wallList.remove(i); } } If you remove a wall then the next wall at index i but you skip it. Decrement i after the remove or use an iterator based loop: for ...


2

I use Interpolation.bounceIn.apply(current_position, target_position, smoothness) to achieve this effect. Take a look at this. Edit I found the answer on their site MoveToAction action = Actions.action(MoveToAction.class); action.setPosition(x, y); action.setDuration(duration); action.setInterpolation(Interpolation.bounceOut); actor.addAction(action); (I ...


0

The purpose of the fix step time loop is to always update at a fixed time interval. This is important in things like collision which that big delta times could cause objects to phase through another. Updating multiple times between rendering is the desired behaviour. Your loop looks fine but the problem is that the device (or other part of your code) is not ...


0

Okay, So I think you're asking how to do it so here's my Bullet class remodeled to fit a player. Keep in mind this was a bullet class so edit it to fit for your player. Pay close attention to the use of Vectors. public class MovingPlayer { static final float PLAYER_SPEED = 800; Vector3 position, velocity, acceleration; Texture texture; public ...


0

Since in order to take his turn the player needs to know the outcome of other players actions, one way to solve this is a message consumer/producer pattern. First, you need to define a queue structure with objects sharing a common functionality; this can be as simple as just List of Unit objects where Unit is a class providing an unique identifier for each ...


1

Try fetching the position buffer: Vec2[] positions = m_world.getParticlePositionBuffer(); additionally you might want to grab the colors: ParticleColor[] colors = m_world.getParticleColorBuffer(); Then I would draw the corresponding color at every position using OpenGL. I believe that you can write a very simple shader that would work very well for ...


0

The client can use the files to reduce network latency but everything must be confirmed by the server. For example, if the client's map has been modified to remove a wall and the client tells the server "I move from Point A to Point B" on the other side of the wall that has been removed, the server rejects the move and sends back a packet "you're at Point ...


2

XML is just a data storage (or transfer) format. The XML file itself has nothing to do with rendering tilemaps. You actually need to have the data in memory in a better format suited for rendering tile maps. I think you should tackle the problem from another direction. Rather than trying to figure out how to render XML data as tile map, you should just ...



Top 50 recent answers are included