Tag Info

New answers tagged

0

Make sure you request a depth buffer from LWJGL by passing a PixelFormat to your call of Display.create. Like so: Display.create(new PixelFormat(4,24,0,4)); The 24 indicates a 24 bit depth buffer.


1

A rotation is essentially that for each sample in the resulting grid, find out which texels in your original texture that your filter footprint covers and interpolate them accordingly. This will be a lossy process, and if done repeatedly will quickly obliterate all interesting information in the image. If you only look at the nearest texel, you'll get a box ...


0

I have found the answer for my problem. In order to draw an image and a shape, one can use a pixmap. It is possible to first create a pixmap on which you draw a rectangle. Then, you create another pixmap on which you draw the image. Both pixmap then can be combined by drawing one pixmap onto the other. This is the code I use to build an image containing a ...


1

You could use an ArrayList to store all your stars in. When collision is detected you remove star from array so the star is no longer updated. So : create : ArrayList <Star> stars= new ArrayList<Star>(); add the stars : stars.add (new Star (param1, param2)); update : for (int i = 0; i < stars.size(); i++) { ...


0

Based on user55565's answer, I did some reading on rotation matrices and took his main idea and did some paper sketching. In the end I came up with the class below, which works. The basic idea is to reference the position of the square by its center coordinates. When you want to rotate it, you follow these steps: Calculate the current(before the ...


1

Im not sure this works 100% but here is an idea to get you started. Let your square have x,y as center and r as its current rotation value. Let dx and dy be the displacement from center to one corner of the square when r is 0; On rotate-moving the square on the said corner: First get the corner's position: cx = x + rotated(dx, r); cy = y + rotated(dy, ...


2

I don't know what RawImage exactly is here, but once you access pixel data of a Volatile or BufferedImage in Java you lose hardware acceleration. So even if these images were stored in vram before you called renderImage, they will no longer be once you access the underlying pixel array.


2

When you really want to get good performance, implement it in hardware using pixel shaders. The graphic cards GPU is optimized for performing the same operation on lots and lots of values in parallel, so it does so really quick. When you don't want to learn GPU programming, there are many libraries available which implement many common blend effects in ...


1

Check out this blog entry on fixing your timestep. Essentially the advice here is to use a loop where you draw as much as you can until a fixed threshold of time has passed, then update. Here is the recommended game loop; double t = 0.0; double dt = 0.01; double currentTime = hires_time_in_seconds(); double accumulator = 0.0; State previous; State ...


3

You need to set to NPC a new target once in a while (e.g. each 5sec) and move it towards the target each tick little by little. Then it will be smooth. To avoid sharp turns upon setting a new target, you can mix target positions between old and new target for a second or two. Additionally, you might want to Google for "Steering behavior"


0

If you are starting to develop your adventure game, you probably have a great story, graphics, music... Sometimes it may be a good idea to try some free engines and editors just to get an idea how they work - and use them as an inspiration. Or use them for your project, of course. I mean for example something like GameStylus, which is a specialized on-line ...


1

Your canCollideWith method should be so that s1.canCollideWith(s2) == s2.canCollideWith(s1)I think. If not it means that collision will differ according to your array order. And if both return the same results you can test that only once. Then in your code, you give two differents definitions of your canCollideWith method canCollideWith(Sprite) and ...


2

The most effective way to improve collision check speed is to decrease the number of entities that needs to be checked against. Spatial partitioning such as octree helps but you can make further improvements. Suppose if currently you have one big list of collidables contains objects and bullets and in each collision check step you are looping through all ...


1

I had forgotten to ask for a depth buffer when creating my window: Before: Display.create(new PixelFormat(4,0,0,4)); After Display.create(new PixelFormat(4,24,0,4));


0

The equation of the ray is p = camerapos + t*ray which is 3 equations (after splitting it up the coordinates): p.x = camerapos.x + t*ray.x p.y = camerapos.y + t*ray.y p.z = camerapos.z + t*ray.z then we know we want the point with p.y = 0 so lets fill it in: 0 = camerapos.y + t*ray.y t = -camerapos.y / ray.y then just fill in the t in the first ...


0

I assume you know the ray direction, otherwise there are infinite rays that cross the floor. It crosses the floor when your camera pos (x,y,z) offset by a scaled ray direction k*(a,b,c) has zero height, so: y + k*b = 0 => (we only care about the y component) k = -y/b so the vector that you need to add to the camera is (-y/b)*(a,b,c) Of course, it goes ...


0

The problem is that there's two aspect ratios to take into account. You have the aspect ratio of the screen with you're calculating in the aspectRatioHeight method, but there's also the aspect ratio of the image. Consider a image that is 100x100 pixels, and you want to place that with a 10px margin on a screen that is 640x480. If you set the width of the ...


0

You should be using one of the Viewport strategies, all the documentation for it is on the wiki. https://github.com/libgdx/libgdx/wiki/Viewports


1

I have seen two ways of achieving this, one is to let the UserData of the Box2D Body hold the Sprite. body.setUserData(mySprite); And in the update you retrieve that and apply position and rotation to the Sprite according to the Body's transform; Sprite sprite = (Sprite)body.getUserData(); Vector2 position = body.getPosition(); // Center body is center ...


1

You can use the setUserData method to attach an Object to the box2D body (like for example a Sprite or an Actor): body.setUserData(sprite); Accordingly you can get your Sprite back like this: (Sprite) body.getUserData(); Note that you need to cast to Sprite.


2

I see the following reasons to encrypt data: Protect your users' actual sensitive data by adding to the amount of encrypted traffic. If hackers have to wade through not sensitive game assets, they're much less likely to find a user's actual sensitive data. Protect your servers. Using asymmetric key encryption (like TLS, what people still commonly refer to ...


0

Hopefully I understand correctly what you are trying to do. First get all the 128 x 64 rectangles with each tile by iterating through the big image and taking subimages. Then, use an alpha map to keep only the tile you are trying to separate. If you don't know what an alpha map is, there should be plenty of tutorials online explaining how to use them.


3

It depends where the bottle neck is. If you IO bound (the game is always waiting on network IO) then yes compressing will help. If your game is CPU or memory bound then it will just run slower. You should compress before encrypting because cipher text is less compressible as a result of trying to remove patterns that could be used to reverse engineer the ...


1

Encrypting the data each player receives makes cheating and ripping of assets a bit harder, but not impossible. The data needs to be decrypted by your game client anyway, so the encryption algorithm and key must exist on the users machine. That means the users have everything they need to decode the network traffic. So you only add a layer of security ...


-4

Do you care if people can get your assets? Do you transfer gameplay data? If any of the questions is true, then encrypt. I would use XOR cipher. It's super simple, super efficient, not super secure but you apparently don't care (it WILL make cheating harder of course, if you send gameplay data though). It works with streaming data, and the encryption is the ...


0

I have not tried any of these, but the following three solutions should work. Save the input data Instead of saving the Path2D object, save the values you have used to create the objects. As you said in the comments that you are creating the Path2D objects yourself using the API, you have the source data and you can control what to do with that. Java ...


1

This may not be the answer but, instead of using sprite.rotate(float angle); use: sprite.setRotation(float angle); Hope this helps! :D


1

The getRGB() method picks all channels, even alpha. You can extract color and alpha channels with something like: Color col = new Color(pixels[pixelIndex]); System.out.println(col.getRed()); System.out.println(col.getGreen()); System.out.println(col.getBlue()); System.out.println(col.getAlpha()); Depending on the image format (ABGR, ARGB), retrievieng ...


0

You can use Path2d to define the outer edge of your rounded rectangle. This actually creates a Shape. To turn this into something you can use, FlatteningPathIterator can be called to create a list of points that can be used to step along the path. You can use this information to draw your circle as it progresses around your progress bar. Here is a good ...


1

You want linear interpolation using the alpha channel of the incoming (source) pixel. This goes by different names in different APIs (mix (...) in OpenGL, lerp (...) in D3D). No matter what you call it, it boils down to the following: public static int alpha_blend(int c1, int c2) { int a1 = (c1 & 0xff000000) >>> 24; //int a2 = (c2 ...


1

It looks like you are using a matrix to rotate the image when it is drawn. This does not change the position values you have stored in your class, but it does affect how the image is drawn. If you want to know where the 4 corners of the image are drawn you will have to keep track of them yourself. Same is true of the bounding box. If the bounding box is to ...


0

I think you are over thinking this. Just have each object has its own update method that takes a delta time; then do obj.vy += 0.01 * dt; //gravity obj.y += obj.vy * dt; And call this for every object in each game step and your done!


0

Why not have a 2 dimensional array, of the size of your grid, then draw your pieces depending on how many pixels you have as the dimensions of each grid. For example: public static final WORLD_WIDTH = 6; public static final WORLD_HEIGHT = 6; public static final GRID_WIDTH = 16; public static final GRID_HEIGHT = 16; GridPoint[][] grid = new ...


1

Use a timer (delay, countdown, whatever you want to call it). Each time a menu movement is applied, reset the timer. Do not allow another movement until the timer has expired. Unlike the event-based approach, this still allows you to hold a key and move through a menu, but only at a limited speed. An implementation might look like: double m_LastMove = 0; ...


0

These kinds of problems usually happens when the key state is checked at each frame. What you want to do is use the OS event that signals a "key press", or "key down". Note that if you do the same for the mouse, the "mouse UP" event is the one, contrasting with key input. Then the repetition will happen after a delay, this is handled by the system input ...


1

Assuming the board view is from directly above, for simple rectangular boards, you can do pretty well by interpolating from the four corners of the active playing area.


0

I recall reading this: alternative method (there a few) for terrain assignment; I suggest you review and adopt this approach instead of your initial attempts. This approach differs from with your method in that the example uses an existing greyscale bitmap as the heightfield and reads the image-data to assign the elevation of the 'hills.' However, this ...


4

It would be nice if I could retrieve the values from memory after the the shader has calculated them but it doesn't seem possible - or advisable But, it IS possible, and I would advise it: https://www.opengl.org/wiki/Transform_Feedback


0

You may want to look into tweening, which is what's used to smooth out animations using various smoothing functions. If you don't wish to implement anything yourself, you may want to look into: http://code.google.com/p/java-universal-tween-engine/.


1

I don't know java, but it seems to me that the Command pattern would help you. It is a behavirol pattern by the Gang of Four wich encapsulates your information to be executed, in your case this information is user input. I'm copying/pasting wikipedia here import java.util.List; import java.util.ArrayList; /* The Command interface */ public interface ...


4

in your keyPressed and keyReleased you can use a Map to map the KeyEvent.VK_* to GameInput make a new enum with the actions you want to be controllable enum GameInput{ FORWARD, LEFT, RIGHT, BACK,PAUZE,... } and in Controller you have a Map that you use: public void keyPressed(KeyEvent e) { game.setKeyDown(keyMap.get(e.getKeyCode())); } public void ...


0

It's a problem with JAVA apps being scaled twice by retina displays. I presume your talking about the desktop version right? I currently have the same issue, it's super blurry. The solution is to turn off retina scaling for java apps, currently trying to figure this out.


1

Yes, they are required to sign in with a Google Plus account. It's possible to use the leaderboard without requiring users to sign in. You won't be able to connect players without them having accounts. The service is free because it allows Google to collect data on its users (play trends, in app payments, social sharing, etc.), thus it requires the users to ...


1

TextField has a method called getText(), it may never be null but may return an empty string. txtUsername = new TextField("", mSkin); txtUsername.setMessageText("test"); txtUsername.setPosition(30, 30); mStage.addActor(txtUsername); String test = txtUsername.getText(); System.out.println(test); ...


0

First ensure that your Actors are able to report their bounds: public class Enemy extends Actor { Rectangle bounds; public Enemy() { bounds=new Rectangle((int)getX(), (int)getY(), (int)getWidth(), (int)getHeight()); } public Rectangle getBounds() { return bounds; } private void setXY(float pX,float pY) { ...


1

The basic cause of the problem was that my value for screenY (2D location of mouseclick on Y-axis) was incorrect and so passing it to any valid picking ray function returned invalid results. My old working project got the mouse position values from the org.lwjgl.input.Mouse class whereas the new project is using java.awt.event.MouseListener. The lwjgl ...


0

This is definitely possible. I would look into this book or ebook online and it teaches you how to write effective sound classes so that you can use them in the future, with situations like you are speaking of. You can iterate through samples in any sound file and throw flags on high/low pitches, amplitudes, frequencies, etc.. Here is the book: ...


3

It seems to me that you will need to perform some sort of Frequency analysis on the audio file in question. You could either pre-process the file on level load (using the data to queue up your level actions), or perform the analysis in real-time. Either way, you'll want to divide your audio waveform into sections, each comprised of N samples, and then ...


0

In the inner for loop, shouldn't you be incrementing k instead of i? You're doing i++ twice, so at some point, your code is trying to access Main.currentBullets.get(10), which is causing your Index 10, size 10 to get thrown.


0

The solution I prefer is to put all game-specific logic in the client. The server only acts as an I/O reflector to make sure all clients are up to date. One benefit of this approach is that the same server can serve different games, since it knows nothing about the content of any specific game. There are a few things that have to be done centrally, such ...



Top 50 recent answers are included