Tag Info

New answers tagged

0

If you want it to be in update, you can use the setCenterX and setCenterY methods. mouseImage.setCenterX(Mouse.getX()); mouseImage.setCenterY(Mouse.getY()); However Y coordinates are going to be reversed. If you want them to correspond to proper ones you can do: mouseImage.setCenter(container.getInput().getMouseY());


0

I got around my problem by re-writing my code to remove ComponentListener. Doing this I got a single response to a left-click (or right-click). This doesn't differentiate between left or right-clicks - it just picks up clicks, but that works for me. My test code is posted below. package testslick2dbutton; import java.util.logging.Level; import ...


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!


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 ...


0

You are rotating the sprite using an int, 0-360, instead of a float. Try doing sprite.setRotation(angle/360f);


0

In my experience the AbstractComponent section of slick has some problems. I am quite sure there are some bugs and so I stopped using it. The rest of the slick framework seems to work fine though. Try alternatives like Nifty GUI which is compatible with slick


0

I've found what I've done wrong: for (w = 0; mask[sum + w] == type && !done[sum + w] && w < 15 - x; w++) {} The code above was wrong, because it incremented w first and then it checked everything. Therefor the code should be: for (w = 0; w < 15 - x && mask[sum + 1 + w] == type && !done[sum + 1 + w]; w++) {} This ...


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 ...


0

I suggest you make a skybox: A skybox is a large cube which you render around your camera which will give you the ability to pass each pixel through a fragment shader. And you can render anything onto the skybox: a color, an image, a gradient, etc. Just be sure to call glClear(GL_COLOR_BUFFER_BIT || GL_DEPTH_BUFFER_BIT); A good tutorial on this topic is ...


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 ...


0

I know this is an old thread, but I just had this same problem and got it fixed, so.. Select your snowman in blender and press alt+R to clear rotation. Now it's probably going to look the same as in jMonkey. Apparently the ogre exporter doesn't apply rotations you made to the object. To fix this, apply the rotation permanently to the snowman in blender: ...


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 ...


0

There is no exact (and short) answer for what you are asking, but I'll try to help you for some parts that you need to know in order to achieve this. for simplicity, I'll skip and resume a lot of code * First part is How can I render text?. There are plenty of tutorial in internet. A fast example is the Scene2D library (already in libGDX yei!) using the ...


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 ...


0

I have to agree with Xkynar on this, but I'd like to add something. In order to keep track of the different animations, you can use the libGDX Hashmap in order to store each Animation object under a string name, like "running" ,"walking", or whatever. Each animation can then be accessed by requesting the name of the animation in the Hashmap. If you'd like ...


0

your code actually draws a scaled image, have a look at Chris Campells article, it's really useful... what you have to do to simply draw the whole image without scaling... g.drawImage(getImage("Numbers/icon0.png"), 0, 0, null);


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.


0

The server loop depends on the functionality required by the game. Generally the server is going to be responsible for maintaining an accurate game state because it is usually the authoritative party. So what does this mean for our server loop? The server loop handles new connections from clients, client transmissions, and automated functionality. Let's ...


0

Adding an answer to my question above. what happened was I was thinking in exact pixel coordinates. When I should have thought of world units when using viewports yes thecamera is centered at (0, 0) by default but the world width and height was only 100. There is a transparent space at the bottom left of my image. That is why even though it is also at ...


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 ...


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 ...


0

It looks like you're incorrectly assuming that the item is removed from the ground immediately upon picking it up. However, it isn't, and the player keeps intersecting with the same item, picking it up multiple times. Before pickup, you should check if the item has already been put in an inventory slot: if(play.items.p.get(i1).remove != false && ...


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 ...


0

Please go through this tutorial, published by libgdx, https://github.com/libgdx/libgdx/wiki/A-simple-game In above tutorial, in "Loading the assets" section, you can change/remove the image (badlogic's by default image) as per your requirement.


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++) ...


0

Because by default Camera sees your game screen from top, having it's 0,0 fixed at top left corner. On the other hand, things you draw in render method, have 0,0 fixed at bottom left corner. To combine your game screen's coordinate with camera's coordinate, you use, batch.setProjectionMatrix(camera.combined); Read this article, written by libGDX ...


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; } }


0

You could also use a jar bundler to create a .app and .exe with your icon.


0

I'm sure there is an implemented way of doing this in lwjgl, but you could just find the lwjgl image png and replace it with your png.


0

Simply use a function like itertools like there on Python . I am not aware of the name of the same function in Java try ".http://code.google.com/p/neoitertools/" Find out all the permutations of the object called "cards"


0

You need to to point your working directory to the assets folder. Snippet from https://github.com/libgdx/libgdx/wiki/Manual-project-setup The Android project has a subfolder named assets, which is created automatically. Files available to the Android application must be placed here. This is problematic, because these same files must be available to the ...


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 ...


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: ...


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 ...


0

There are multiple issues with this code. First of all your quad vertices are not centered around the origin, this doesn't have to be a problem but note that it will use the corner of the quad as the pivot to rotate the sprite then. Secondly, you are rotating on the X-axis. This seems weird since the general direction your camera in looking in is the -Z ...


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


0

Okay so I solved it: 1. Make sure glEnable(GL20.GL_BLEND_COLOR); is on and the blend function is Gdx.gl.glBlendFunc(GL20.GL_BLEND_SRC_ALPHA,GL20.GL_ONE_MINUS_SRC_ALPHA); 2. Edit the light texture in something like GIMP to double check that your background is transparent. 3. MOST IMPORTANT Make sure the lightFramebuffer is Format.RGBA4444 or ...


0

On the resize event method in your ApplicationListener (the main game class) change public static width and height integers like so: WIDTH = Gdx.graphics.getWidth(); HEIGHT = Gdx.graphics.getHeight(); float scale = (float)prefferedWidth / (float)WIDTH; WIDTH = (int) (WIDTH * scale); HEIGHT = (int) (HEIGHT * scale); The prefferedWidth is the ...


0

A guess here, but logging on the same thread as your rendering work, before you send gpu instructions, can add synchronous disk latency? Possibly in a sporadic fashion if it's buffered and dumping. @Override public void create() { batch = new SpriteBatch(); img = new Texture("badlogic.jpg"); } @Override public void render() { ...


0

3.5mm support would probably be easier if you want something to work out of the box by default. Android is a very mature platform at this point and it has plenty of other applications besides just a Phone operating system. The OS has a fairly well documented USB api: https://developer.android.com/guide/topics/connectivity/usb/index.html which can probably ...


0

This is a post by @OrangePixel for one way to make efficient lightning with Libgdx. It describes a simple technique. You can put alpha blended Dot above the map and make it seem like a lightning effect. The article is interesting and all the thanks go to the author! http://techblog.orangepixel.net/2015/07/shine-a-light-on-it/


1

It's unfortunate that I have to answer my own question, but I'll post the fix that I worked out in case it helps someone else. int current_image = 0; int current_image_add = 1; These two variables inside of the animate() function were being reset every time animation() was called, meaning that it never really cycled through anything because it continued ...


0

Your best bet is to extend the Image class and add a touch listener. Add this code into your Image subclass: private void addTouchListener() { this.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { YourClassName.this.wasTouched(); } }); }


2

What is the problem? Generally speaking, you want to do a topological sorting, where the nodes are your bricks and the edges mean "is this node behind that other node" relationship. So all you need to do in order to sort anything anywhere is to decide on "is behind" relationship. It seems that your code treats bricks as uniform objects in a grid, ...



Top 50 recent answers are included