Tag Info

Hot answers tagged

2

You could use an AlphaComposite to draw your Image transparently on top of what you have already drawn. //... float alpha = 0.5 //draw half transparent AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,alpha); g.setComposite(ac); //g.drawimage... Here is a question with a similar topic: ...


2

A simple solution would be to assign the doors IDs, where the matching pairs would share an ID, and have them send the player to the other door with the same ID. Or, if for whatever reason you find the need to make such IDs unique, you could assign door pairs matching IDs where one is negative and one is positive but the same absolute value, and when ...


2

Your algorithm only looks at the diagonals: final int[] axs = new int[] { -1, 1 }; final int[] ays = new int[] { -1, 1 }; ... for(final int ax : axs) { for(final int ay : ays) { final int x = current.x + ax; final int y = current.y + ay; You need to also check the orthogonal tiles: (x+0, y+1), (x+1, y+0), (x+0, y-1), (x-1, y+0). In ...


2

Each time the loop executes, nextGameTick is incremented by 1000 / TICKS_PER_SECOND. This puts an upper limit on the framerate. In this case, it caps the framerate at a maximum of 60fps, because if a frame takes less than 16.67ms (1000 / 60) to execute, it waits until 16.67ms has passed from when the last frame started. By combining it with the loops ...


2

There is no 'best' solution to this problem. Ultimately you're going to have to find by trial and error something that gives the best tradeoff between performance and believable intelligence. However if you want to use any sort of path finding algorithm you're going to need to subdivide your world in some way. Whether you go with tiles, polygonal zoning or ...


2

I've never tried to get this to work myself, but it seems like you would just need to increase the upward force applied to the jet ski's body as a function of the depth of the jet ski below the "surface" of the water object. The easiest way to get the distance below the surface might be to make a constant variable that describes the height of the water's ...


2

I spent a good while looking how to implement Box2D in Android studio, so for anyone else in the same boat, or just looking to implement Box2D - here goes. For implementing Box2D into your java code/framework, Box2D is tuned to work with numbers between 0.1 and 10 (it works in meters), quoting from the Box2D manual: http://box2d.org/manual.pdf Box2D ...


1

You made a simple mistake there, you go through your array, and as soon as the cell you look at does not have the specified item in it, you insert it into that cell or go on if it already has something else in it: ...else if (c.get(i).holdingid == 0) {... instead, you could do it like this (in pseudocode): insertItem(Item item) { int pos = index of ...


1

After much frustration, I found out that I had made a folder the same name with the text file by mistake!! After deleting the folder all works fine, thank you for replying!


1

This is most likely a rounding error. I'm guessing that x and y are ints. Keeping track of the x and y values as floats, I expect will fix the issue. Consider if the values are being floored: Moving Left 10 - 1.6 = 8 Moving Right 10 + 1.6 = 11


1

One way of doing this is creating and loading an image into memory that is as large as the background. However, this seems like a horrible waste of memory. To affect the whole screen with a fragment shader you don't need a full-screen texture, just a full-screen polygon (one quad or two triangles). The four vertices would have attributes on them. At the ...


1

If you are just filling with a solid color then you could pass that color to the fragment shader as a uniform, and process it from there. Use a full screen quad for the fragment shader to render onto. Another way is to this to render the background to an FBO and do the full screen quad trick but apply the FBO texture to it. This would be very memory ...


1

You can basically start leaning to program by making games. To learn game-specific programming knowledge you must make games. There is no grand preparation ceremony you must complete before you can make games. Like any other skill, it's all just practice and repetition. Make games. Make lots of little games. Don't start with a big project or grand idea. ...


1

In order to make the title appear with the image you need to use the location of the image plus an offset. The reason (PPlane.WIDTH / 2) - (title.getWidth() / 2) works to center the image is because you're finding the midpoint of the PPlane and then subtracting an offset equal to half of the title's width which has the effect of centering the image ...


1

The example you have posted should work fine. I would suggest there is something else wrong in your project if that is not working. If your loop repeats too many times, or indefinitely as you have suggested in your question then you might cause Unity to hang, since it will wait for the loop to complete before it updates the next frame. You will need to use ...


1

try using GameObject.FindGameObjectsWithTag or GameObject.FindWithTag or by name (or namepath) GameObject.Find bool playerexists = (GameObject.Find("player") != null)


1

Yes! I have figured it out. LWJGL texture files must have dimensions equal to powers of 2 (2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048 etc). Otherwise OpenGL will clamp them to nearest power.


1

Use of delta is to smooth your animation or as you said "making it independent of frames". So may be separating animation with the position calculation can solve your problem. For example, First calculate your next position in separate method then show your animation, by adding delta to initial position to final position, without loosing the initial ...


1

Assuming you have a class named Slot. Public class Slot { Public Item item; Public bool IsEmpty () { If (item == null) Return true; Return false; } } Then make a method to return the next empty slot. Public Slot GetEmptySlot() { For (int slotIndex = 0; slotIndex < inventorySlots.Length; slotIndex++) ...


1

Make the inventory a 1D Array and just use: void onpickup(Item item) { for(int i = 0; i < inventory.length; i++) if(inventory[i]==0) //using an int array for item ids where 0 is null { inventory[i]=item.id; break; } }


1

I think if it is invisible and if it is not affecting gameplay it is acceptable. But if you want a solution you can set a flag when starting collision detection, when the flag is true don't move your objects and store how amount they should move. If a collision happens extract how much it should go back from stored value and apply the stored value then set ...


1

What you want to do is determine how much the two AABBs overlap and then move them apart based on that amount. You already have an overlaps method. If you tweak that to return the amount that the AABBs overlap (on each axis) then you can just move your player back by that amount. That assumes that what you're colliding with doesn't need to be pushed back ...


1

Instead of casting rays in 360 degree fashion, cast rays to the corners of the tiles in range of the lightsource. Sort the angles from the light source to the tile corners and do a 'sweep'. You can optimize the algorithm to look for the nearest tiles first and ignore angles for culled tiles: A--B E--F o |T1| |T2| C--D G--H Angles would be ...


1

You generally use a window provided with the library that supports OpenGL. I don't have any experience with JOGL but it seems it works with Swing, although apperantly with a small performance penalty. LWJGL, another alternative for OpenGL in Java provides a window library with it which is native to C/C++ and is normally used for OpenGL rendering.


1

The way to do this is with a FBO (Frame Buffer Object). You can render each pass to a FBO and use it as a texture input in the next stage, any kind of deferred shading and post processing is reliant upon this functionality. https://www.opengl.org/wiki/Framebuffer_Object



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