Tag Info

New answers tagged

0

You might want to implement a 2Ds pathfinding algorithm and call it in your tick() method. There are several pathfinding algorithms, but the A* algorithm might be the best for you as it is rather simple to understand and code.


0

Well, just a simple way to do it, in your player class create the 3 textures for each animation if you're not using a TextureAtlas, then use a int playerState to specify the state of the player (1 for running, 2 for jump, 3 rolling down),and finally in the draw method use a bool to check playerState and draw each animation.


3

Basically, you'll need some kind of container or collection to hold all entities. Then create some spawn or factory function to actually add them. When drawing (or updating) your game entities, you'll just iterate through this list and modify them accordingly. Here's some pseudo-code example: List<Entity> entities; function spawnEnemy(position pos) ...


0

Im using libgdx particle system for a snow effect here's the draft file ,this will need some tuning but a good start. In this effect the png get some light blue tint. You can simply import it ParticleEffect snowEffect = new ParticleEffect();<br> snowEffect.load(files.internal("snow_effect"), [files.internal("particle.png")][2]);<br> ...


0

If you mean by view the screen size / viewport , you could use the ScreenViewport function of libgdx.. ScreenViewport (LibGDX API)


0

It's called a Hash data structure aka an associative array. It is often used to represent a sparse array. For instance like in your case, a huge world with myriads of tiles, that is sparsely occupied by only hundreds or thousands of units. It is very fast because it knows where to look for values (in your case units) with a certain key (in your case ...


3

In my experience with android, it is the garbage collection the kills the performance, not the allocation, although these two are tied hand and hand. As mentioned on the comments, pre-allocation is a way to deal with this issue. This is known as a memory pools. Another similar solution is object pool pattern. An object pool allocates as needed, but does ...


6

How are you passing your normals to the vertex shader? It looks like those are the normals for each of the six faces of a cube, but the vertex shader operates on vertices, not faces. Unless you're doing something unusual, you need to specify a normal for each vertex. In addition, if you want a cube to look right, you will need 24 vertices rather than 8, so ...


0

I, you may have a look at Box2d light box2D light. The idea is to create shape in a box2D world and then use Box2D light to perform the shadow casting and light rendering. You then have to render the light on top of your scene.


2

You can explicitly get those numbers from id = glGetAttribLocation(program, name); after linking; the name is the string that appears in the vertex shader for the attribute. For example if you passed "vertexPosition" for name then you would get 0. If the layout information is not in the shader then openGL will create a default layout (usually in order as ...


1

What you need is double buffering I stole this from somewhere just to give you a quick answer: "Double buffering is conceptually pretty simple, instead of drawing your objects one by one, you draw them on an image and then tell the renderer to draw that entire image. This eliminates the flickering. Here's an example of how you might do this" class ...


0

My guess is that the problem is in g.drawImage(texture, posX * 32, posY * 32, null); In your loops, it looks like you are manually incrementing posX, and posY. The posX * 32 and posY * 32 should probably be posX and posY. g.drawImage(texture, posX, posY, null); Either that, or if you want to use the x and y values of your loops then it should be: ...


1

I figured out the problem myself! After printing the coordinates of the mouse to the console I realized that where just something missing with my Input. Sure enough, I added GameContainer to the constructor of minigun and set input to equal GameContainer.getInput();. It works perfectly now :D public Minigun(GameContainer container){ try { ...


3

You don't need to call glVertexAttribPointer for the indexes; the indexes are found from the bound GL_ELEMENT_ARRAY_BUFFER during the drawElements call (which is saved in the VAO state IIRC). However indexes start from 0 so the contents of your index buffer are flawed they should be: {0,1,2,2,3,0}


1

The positions and color (and all other vertex attributes) all use the same index buffer, there is no way to change that. So if you have an index X then that vertex will have the position at index X and the color at index X. The size parameter indicates how many values to take (1 to 4). Sometimes positions are stored in the homogenic format (essentially add ...


0

Ex-Bukkit dev here. Not sure if you still want this with the whole bukkit situation... Really, the only thing to do here is use some tricky packets, to make it not collide, or simply offset the y of where you spawn in up one. You could even use trig to see whee the arrow would fly, and spawn it one block in that direction. Easiest would be to simply offset ...


1

LET THIS BE A CAUTIONARY TALE ABOUT BOX2D! Haha! Here's the solution I came up with The problem I amrunning into is due to the fact that Box2D uses meters instead of pixels for the scale, in my game a screen that is 1920x1080 would be 1920 meters wide and if I am using sprites a small sprite will be only as many meters wide as it is in pixels. The reason ...


0

Note: This question specifically asks how to make an 8*8 sprite sheet using 8 bit graphics. A sprite sheet is a series of images meaning more than one image on a single image(not 8px*8px). You can do all the editing and creating you want to do before changing the image to the indexed format using Gimp which will convert the image to the required 8 bit ...


3

Sure, this is quite simple really. I'll guide you through Paint.net. Open the application and go to New. In the dimensions, put 8 for width and 8 for height. A new 8x8 canvas will open, typically I zoom in all the way to 3200%. I'll also get rid of the white background layer, by making a new layer, then deleting the background one. Now you have the canvas ...


1

you say it's so complicated to implement a path-finding algorithm, but it isn't... and what's even better, once you have implemented one you can use that algorithm whenever needed again... i can provide you with an simple one (A* it is - and it is easy) and it's so open you can use it on hexfields, squared fields or even on cubes... private ...


1

The distance moved does not take the delta time into account, so if you get updates coming at an irregular interval you'll get jerky motion. Scale your speed by the elapsed time, dt; public void update(float dt){ if(cont == true){ vec = makeVec(); x += vec.x * speed * dt; y += vec.y * speed * dt; } } This might mean you'll ...


2

Try doing this:- try { Robot bot = new Robot(); bot.keyPress(KeyEvent.VK_F6); bot.delay(50); bot.keyRelease(KeyEvent.VK_F6); } catch (AWTException ex) { Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex); }


1

Dialog is better suited for modal pop-up windows, and it includes a "button" and "content" table already in the window (as the docs say). You can grab these tables with getButtonTable() or getContentTable(). The dialog makes it easy to work with pop up windows. For example, here is a confirmation dialog: Dialog diag = new Dialog("Warning", skin, "dialog") ...


0

Right well, since no one has replied, I will post my solution. When adding Actors to the Stage, rather than doing: stage.add(actor); Which adds a Cell with the given Actor in it, I done the following: stage.addActor(actor); I was then free to overlap actors and move/scale/rotate them via tweening. The only probably I currently see with this is the ...


0

Thank you world, this library works: https://github.com/StrikerX3/JXInput


2

Convert them to the normalised space: float r1 = color1.r / 255.0f; float g1 = color1.g / 255.0f; float b1 = color1.b / 255.0f; float a1 = color1.a / 255.0f; float r2 = color2.r / 255.0f; float g2 = color2.g / 255.0f; float b2 = color2.b / 255.0f; float a2 = color2.a / 255.0f; and them multiply them: float r3 = r1 * r2; float g3 = g1 * g2; float b3 = b1 ...


1

yeah, all solutions have already been made... i'll just add some more code (i'm rather from stackoverflow ^^) assuming you're using bounding box assuming you use plain java (java.awt) . List<Shape> shapeList = ...; //you know where you get them Shape exampleShape = shapeList.get(0); Rectangle2D boundingBox = exampleShape.getBounds2D(); see ...


1

Imagine the radius is one. That means every point around the circle is exactly one unit away from the center. Now what kind of vectors always have a length of one? Unit vectors of course. You can get a unit vector by normalizing a non-unit vector. Take the vector CA (center to A). Next, normalize CA to make it a unit vector, then scale it by the radius of ...


1

If you know the canvas is a rectangle then this simplifies to the case of checking if the bounding rectangle of the shape being drawn is contained within the canvas' rectangle. That's a fairly efficient check to run, and (generally) finding the bounding rectangle for your shape should be fairly easy (just finding the minimum and maximum x and y coordinates) ...


3

As already pointed out in the comments and answer: This can be arbitrarily complex. Particularly, depending on the exact use case and performance requirements, you can employ some rather sophisticated data structures in order to make these tests fast. The bounding box test is the simplest one that should be done in any case (and in fact, could already be ...


1

One obvious solution is to store the entityId inside each component structure or class. This way when you need to obtain components or do some entity-specific logic, you already have an easy way to obtain the entityId based on a given component. Another solution that may be a tad more complex but has some useful side affects is to assign each component a ...


5

I have good news and bad news for you: The Bad News: I don't know or remember any Java library that does what you want The Good News: It's really easy to implement this type of algorithm yourself! Here's a couple, you can mix them to optimize your collision detection depending on the type of shape. BB Collision Detection You can imagine a box around ...


0

[EDIT: as I don't know what lib you're using, and as this question is not specific to Java, my answer is in pseudo-code.] If I understand your question correctly, atan2 is not what you're looking for. What you want to achieve is moving something (which has coordinates) from one point to another according to time. You just need to compute the vector between ...


0

Suppose the projectiles curret position is $(x,z)$. Then, in each step, you let $x_{new} = x_{old} + t \cos(\theta)$ and $y_{new} = y_{old} + t \sin(\theta)$ where $\theta$ is the angle you found, and $t$ is some small number (depending on the number of milliseconds since last update, for example).


0

I have to say that the current build JavaFX 8 is very well suitable for professional games at least for 2D. The big advantage is that JavaFX has a very professional GUI library which makes it very suitable for UI heavy games.


0

Edit: just realised this is pretty old. Anyways, I did something similar to this in a TD game so hopefully the same would apply here. In my TileMap class I have a method called getTileCoord(int mouseX, int mouseY) and for your game it would be translated to something like this: int tileX = (int) (mouseX - camX) / tileWidth; int tileY = (int) (mouseY - ...



Top 50 recent answers are included