Tag Info

New answers tagged

0

If you want the ray the vehicle is currently moving upon, you want the difference between the current position and a previous position, then normalize it for the direction of the ray (the start of the ray being the current position). Alternately, you can make a normalized copy of the velocity vector for the direction with and current position as the start of ...


1

To get the rotated sprites coordinate simply call the getVertices() method. For example: sprite.getVertices()[SpriteBatch.X2] Gets you the X coordinates of the top left corner. The same call but replacing X<number> with Y<number> gets you the Y coordinate. The corner numbers go like this: 2-3 | | 1-4


1

Don,t do any thing just set the scale of the font and it will work for all type of device font.setScale( .9f,.9f);


0

The reason it happens because you have set inputprocessor in the constructor. As there are multiple screens so it removes the inputprocessor of your StopScreen. So inplace of writing it in constructor of the game screen write the code in the show() method of your screen as i show you:- @Override public void show() { stage = new Stage(); ...


1

You should use BitmapFont.drawWrapped. public BitmapFont.TextBounds drawWrapped(Batch batch, java.lang.CharSequence str, float x, float y, float wrapWidth) All you need to do is set the wrapWidth variable as ...


0

Write multiline text in LibGdx To write a multiline text with bitmapFont just use this following code- String completeText= "In this text there are multi lines\n.To write this race in your game \n you have to write in proper manner. \nYou have to make the text look better ."; font.drawMultiLine( ...


0

No need to take an extra class for Input just write the following code in render method :- if (Gdx.input.isTouched()) { Rectangle touchRectangle = new Rectangle(Gdx.input.getX( ), Gdx.graphics.getHeight() - Gdx.input.getY( ), 10, 10); //just check if your finger overlaps on your ...


0

To get the count of your game launch first make a LocalPreferences class and write following public class LocalPreferencees{ Preferences prefs; public LocalPreferencees() { prefs = Gdx.app.getPreferences("GAMECOUNT"); } public void setCount (int count) { prefs.putInteger("COUNT",count); prefs.flush(); ...


0

Yes you can write your all code of your dispose in hide method. But if the problem still occurs then you can do your all dispose work just before when you load your Assets and make the SpriteBatch null at the starting and then make its object. Like : AssetLoader.dispose(); AssetLoader.load("path of texture","Type.class"); and spriteBatch=null; ...


0

I find solution. If it helps someone - just put Gdx.input.setInputProcessor(stage); after stage.act();


2

Change your thought process from "Moving 7 units" to "Applying a velocity of 7 units" and you can come up with something like: velocity.Y = -7; position.Y += velocity.Y; Now if we take this and we want to apply acceleration every frame we can simply update the velocity every frame. accelerationRate = 2; //arbitrarily picked - no significance velocity.Y = ...


1

position.y -= 7f; change 7f to a variable var fallspeed = 7.0f; position.y -= fallspeed; increase the fallspeed every update var fallspeed = 7.0f; var gravity = 5.0f; position.y -= fallspeed; fallspeed += gravity; This creates a linear acceleration. Gravity on the other hand isnt linear, so you might wanna try something like this var fallspeed = ...


0

initialScale looks like a constant used to scale everything in the game. zoom function calculates originalDistance / currentDistance value, applies it to Camera and prints it out. It's hard to tell more without seeing other affected code.


0

I think of having one class for wolves and sheep that has a boolean isWolf; and when it is clicked it calls animate() that is something like this: public void animate(){ if (isWolf) { //play wolf animation } else{ //play sheep animation } }


4

You should consider using a plain 2d-array or alternatively an array of rooms, where each room is a 2d-array or a grid. A grid would looks something like this: The player is the yellow dot and the blocks are the green ones. if the player is the light gray square, you only need to check for blocks that around that square area. This saves you the time of ...


1

For your collision I would merge adjacent colliding tiles together into one big collision box instead of iterating over every single tile and checking their individual collision. Also I think that a quadtree would work much better than your current approach with a HashMap as it splits your gameworld up in sections and make it easy to delete a section of ...


0

Anko and ashes999 were both right. (See their comments to my initial question) All my problems built upon my misunderstanding of spriteBatch.draw()-API. As soon as I got the right block size in place and adapted the camera to this new stuff all my problems were gone.


0

From the documentation: Socket socket = Gdx.net.newClientSocket(Protocol protocol, String host, int port, SocketHints hints);


1

I have no idea about how JSON of the libGDX parser works, but from what I can see, only keys with a value of 0 were removed. So in your code, if you cannot read the value from the JSON, put 0 as the default one. Also, you can play with the JSON parser to have a better print if you want: http://stackoverflow.com/questions/23401431/libgdx-json-parsing


0

The problem was that libgdx has the origin (0,0) in the bottom left corner, but the mouse movement from the InputProcessor has (0,0) in the top left. What I had to do was adjust the mouse y position so that its (0,0) was the bottom left. I did this with: mouseX = screenX; mouseY = Game.HEIGHT - screenY; This will give the player coordinates and mouse ...


0

I'm don't have any sources confirming it, but as far as I've tested till now, that approach provides better performance compared to using a texture of that size. I suspect the reason for getting better performance is the fact that with smaller texture there is less memory loopups gpu needs in order to render the texture, while it's still doing all the ...


0

Currently there is no way to set the position of a TiledMap. All you can do is move the camera to make it seem as though the map is moving. To do this you would have to create your own rendering code that allows for drawing position input. A workaround that you could try would be making the map twice in Tiled (i.e. in one tmx file, have the map repeat once, ...


0

you have to create an array of pooled effects Array<PooledEffect> effects = new Array<PooledEffect>(); so, in render(), you draw all effects from array. for(int i = 0; i < blocos.size();i++){ if(obj.colision(block.get(i),config)) { PooledEffect effect = block.get(i).getEffectPool().obtain(); ...


0

First, inverse the player position and the mouse position. This way, you will have the real angle from the player to the mouse, and not the opposite. Second, atan2 takes the y difference as the first argument, and the x difference as the second. That is probably why your code looks like it fails. Your code should look like this with the 2 corrections I ...


0

Try multiplying the y value with -1. And make sure to convert the mouse and playercoordinates to the world coordinates. I had this exact problem yesterday. It has to do with wrong conversion - think about the two different coordinate-systems (Viewport- and World-coordinates)


0

follow the steps: create a atlas: atlasUiPadrao = new TextureAtlas("ui/uiPadrao.pack"); (how to pack: put png images in a folder and compress with libgdx texturepack). create a skin: skinPadrao = new Skin(atlasUiPadrao); create a style: ImageButtonStyle: fireButtonStyle = new ImageButtonStyle(); //Instaciate fireButtonStyle.up = ...


0

Try using different math techniques for the rotation: Instead of degrees, try using Quaternions. It's the most used rotation technique for 3D objects in professional engines, because degrees don't work as well in 3D. There's more on Wikipedia and I found some Libgdx code. I have more materials, but I can't include them due to my low reputation, but you can ...


0

For 2 and 3 I would try to multiply like so: Scaling = 1.2f; If(Gdx.input.getAcceleratorY() < 5){ Velocity.y = (Gdx.input.getAcceleratorY()*scaling)*(-1); }else if(Gdx.input.getAcceleratorY() >= 5) Velocity.y = Gdx.input.getAcceleratorY()*scaling; } Try different values for scaling (probably has to be greater than 1). This should result in a ...


0

After doing some debugging, I figured out it's something to do with my Windleaf_Province.png where my TMX file was referencing too. After making a new map with a different tileset and calling it, it worked perfectly as per expected. Why Windleaf_Province wasn't working, I don't know, but I can do it without that :P Thanks for your help everyone!


0

In your GameScreen class do not initialize a new MainMenuScreen object in the constructor. Instead, when the drop collides with the bucket, call a method called returnToMain() or something like that, and within that method, initialized a new MainMenuScreen object and assign it to the game's screen: this.game.setScreen(new MainMenuScreen(game)). This is how I ...


1

When you call effect.setPosition(...), it changes the position of all the emitters, but not of the particles. In libGDX, there is currently no way of changing the position of a single particle, so in order to draw particles at 2 locations, you must do the following: // Pseudo-code move effect at position 1 add particles move effect at position 2 add ...


2

I found this in the libGDX source code, in class Sprite.java public void draw (Batch batch) { batch.draw(texture, getVertices(), 0, SPRITE_SIZE); } So no, no difference. It shows Sprite.draw is only syntactic sugar for the longer version you posted.


-1

You can use GameSparks for this. www.gamesparks.com


3

This game is a good example why you can't always automatically port a game from one platform to another. Having the player-character follow the mouse cursor works well when the user has a mouse, but most Android devices have no mouse, so a different input method needs to be used. In this game, the gameplay is tightly connected to the input method. This means ...


0

I am also currently working on a project that involves Tiled maps and if one of your maps is working they technically all should be. Make sure that you have not changed anything in the TMX file, and just to be safe, remake the map and export it again. Then also make sure that you have the tilesets that you used to create the map in your data folder. When ...


0

You should have a look at sampler objects, if is it a solution that would suit you. Basically a sampler object is openGL object which can store these kinds of settings for later use(binding) in shaders. Example of usage: this tutorial.


0

In your listeners, instead of returning false, do something like this: int numTouches = 0; LockerKeyHalfImage.addListener(new InputListener() { public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { System.out.println("clickrd Locker>>>>>>>>"); numTouches += 1; } }); ...


0

you have to create some table, whatever. that will be displayed on the current screen. the values is the question important here. You have to call from where? got it? if you saved the values on SQLite you can make a method that load the top scores. you can read something about multiple input processors to alternate inputs when the user click on score ...


0

Setting bucket.y only sets the buckets position, so that should not be -.5, it should be the bottom of the screen (0), or at least the ground, to start. To move the bucket you should add a method called jumpBucket() or something similar. Then call that method whenever a touch is performed (check this within your render() method). This method should add some ...


0

It is actually very simple, I have this exact thing in my game. I will solve it in a pseudo code manner. Obtain the coordinates of the gun that is firing. var gunPosition; Obtain the coordinates of the target. var targetPosition; Subtract the targetPosition FROM the gunPosition and store it in a new variable. var difference; Now you can either compute the ...


0

Try: position + directon. The method here is called raycasting. IT can be used in various ways. (cannonPosition & cannonDirection are vector2's) Like. vector2 bulletPosition = cannonPosition + cannonDirection * i Just. do: float bulletSpeed = 0.5f; float shootRange = Gun.getShootDistance(); /*(EG: 100)*/ float gravityConstant = 0.1f; float gravity ...


0

Then make something like: enum gameState = { PLAYING = 0, MAINMENU = 1, SCOREBOARD = 2, ... } if(Player.action = PLAYING) { ... do stuff ... } else if(Player.action = MAINMENU) { ... do stuff ... } else if(Player.action = SCOREBOARD) { ... do stuff ... } And about the rendering. It's hard to get around that.


-3

Calculate the angle between the origin of the shot and the mouse position with the arctan2 function.


0

I now understand how box2d works. It is 1 pixel = 1 meter and my screen size is 480 * 320. That means 480m * 320m in box2d! It is so huge. So I just needed to convert default positions of box2d Bodies something like 1/32, then box2d worlds would be like 15m * 10m. To confirm things going well, I needed to put some sprites to draw in actual size which is 480 ...


-1

Without screenshots or an idea about where the origin and target are, and what kind of coordinates you're registering for your mouse, it's really just blind guessing on my side. I think your problem is here: float dirLength= (float) Math.sqrt(dirX*dirX + dirY*dirY); dirX=dirX/dirLength; dirY=dirY/dirLength; You're using distance between ...


0

Many games do not handle player movement as a purely binary moving/not moving system, but model the players movement through acceleration, deceleration and top-speed. The result is a much more natural movement. In such a system, a slippery floor is essentially free, because you can just reduce acceleration and remove automatic deceleration when the player ...


0

If by rotating in a circle you mean WALKING on top of the circumference of a circle, then I guess any of the answers correctly answered your question. So here is my add: You can continue loading you texture with texture = new Texture(Gdx.files.internal("1325603701_wordpress.png")); but it is extremely recommended that you use the AssetManager. About it ...


-1

Do it like this 1. Load your image into AssestLoader class and store it in sprite sprite=new Sprite(AssestLoader.1325603701_wordpress); 2.Then set its size , position and color like this sprite.setColor(1, 1, 1, 1); sprite.setSize(sprite.getWidth(),sprite.getHeight()); sprite.setPosition((w / 2) - (sprite.getWidth() / 2), (h / 2) - ...


1

Swapping the width and height in ShapeRenderer.rect should fix the problem, see the documentation.


0

If you don't want multiple lines change: EnterTextCasheir.setWrap(true); to EnterTextCasheir.setWrap(false); You'll likely also have to increase the width of your text box. Wrapping occurs when the text doesn't fit in the specified width, it wraps to a new line. Alternatively you can use less text or just make the text box wider.



Top 50 recent answers are included