Java LibGdx Box2d
I would like to make body borders invisible or at least different color. One body should work as sensor and thus not be visible on the screen. I could not find a valid answer for that in hours and I cannot believe there is no such option in this library so I assume I must have missed one liner somewhere in Docs.
I would like to make this square transparent/invisible or at least different color but still keep it to discover movement of these circles.
Looking over stackoverflow and googling it in docs.
Closest things I found:
Make invisible body line box2d libgdx
so maybe the only solution to this is setting some flags in render method or unique render methods for each body?
What I can see on your screenshot is Box2d's shapes for debugging.
They were not designed to have adjustable visuals and are here only to show you the precise shapes and positions of your Box2d's entities.
According to the wiki (https://libgdx.com/wiki/extensions/physics/box2d#debug-renderer):
Debug Renderer
The next thing we are going to do is setup our debug renderer. You generally will not use this in a released version of
your game, but for testing purposes we will set it up now like so: ...
You will need some other kind of renderer if you want to adjust the visuals. For example:
ShapeRenderer, for simple shapes (https://libgdx.com/wiki/graphics/opengl-utils/rendering-shapes)
SpriteBatch, for textured visuals of any kind (https://libgdx.com/wiki/graphics/2d/spritebatch-textureregions-and-sprites)
PolygonSpriteBatch / CpuSpriteBatch / any custom renderer you may find or create yourself
Retrieve the positions / shapes / sizes of your Box2d entities and use one of the more advanced renderers to draw shapes or textures in positions of your Box2d entities. Box2d is not designed for drawing stuff, it just simmulates the physics and gives you position / rotation of bodies and some other info about its world.
Just make the box the same color as the background. Adding color to lines Box2d (EdgeShape)
This post shows how to change the color
Related
I'm using SVG files in my Game and i want to add transparency and brightness effects to them. So what i want is that a sprite becomes more and more transparent until it's invisible. This looks much smoother than a just disappearing sprite. This allows also smooth transitions between the levels where a white screen gets less transparent and then again more. I hope you understand what i mean. Besides this a brightness effect would be nice, too. A sprite can get brighter or darker during the game. Nevertheless i could create a workaround for this using the transparency effect, but yeah, i have none :/
I use this library:
https://androidsvg.googlecode.com/hg/doc/reference/packages.html
I render my svgs on this way:
svg.renderToCanvas(pCanvas);
However i can also convert it to pictures:
Picture pic = svg.renderToPicture();
Maybe this information will help you.
Does there exist something what could help me? And if not, have you an idea how can i solve the problem?
EDIT:So iwant my SVGs behave like these ones:
http://scratch.mit.edu/projects/24634091/
You could use an ImageView and setAlpha(), as Frank says. Or it may just be easier to render the sprites to the canvas in your draw() method.
If you are writing a game, then you may find that rendering SVGs in your game loop may not be fast enough. So you might have to pre-render all your SVG sprites to Bitmaps (ie on startup) and draw them to your Canvas.
Paint p = new Paint();
p.setAlpha(alpha);
canvas.drawBitmap(sprite, x,y, p);
Can you modify the darkness you get on screen when using a ray handler in libgdx with box2d world? Also when I put lights over sprites they look different because the light is on top of them. Can you render lights so that the color of the sprite is the same, even though it is lighted up by a source?
Yes. You can modify the darkness by setting ambient light. For instance:
rayHandler.setAmbientLight(0.5f);
makes everything 50% brighter.
Also, if you find that the lights over your sprites cause too much of a difference in colour, you might want to set the light's colour to white and set the alpha lower (just tweak around with it until you think it looks good).
I wanted to ask if you can use box2d lights so you can see only objects that are in the lights area. For example i have a flashlight and only want to see game objects in the light. I managed to do something like this but the problem is that the sprites of the game objects lose their color intensity because I render lights on top of sprites and the game itself doesn't look good because of this (even though it is the effect that i want).I used box2d bodies with user data containing sprites. I can't figure any way out. Is there any proper way to use box2d lights library to make these objects visible and with their real color? (I am setting lights to X-rays to do this; also I am using it with libgdx in java).
It may be because the default setting is to not use diffuseLight. You have to set rayHandler.useDiffuseLight(true).
Libgdx and Box2DLights - too bright + colors grayed out
I have problems that are not as selecting a figure and that figure selected apply a rotation as many figures as I do not do the following as the first two points and I have but not the third:
The program should allow multiple draw figures in the plane.
Each time you insert a figure in the plane should ask the dimensions of the figure and the coordinates in the insertion.
Once inserted the figure the program should allow the selected shape transformations, rotations, translations and scaling.
You've not provided enough details about your problem, but, you can take a look at the following that deal with rotation
AffineTransform.rotate() - how do I xlate, rotate, and scale at the same time?
How to mirror an image with Java.awt
Change the angle/position of a drawing with a algorithm in Java
The following deal with resizing
How do I resize images inside an application when the application window is resized?
Java: maintaining aspect ratio of JPanel background image
I also suggest you take a look through
Graphics2D
Performing Custom Painting
Using Mouse Listeners
I have added objects to a box2d world in libgdx.
I am wondering if it was possible to drag objects with the mouse? If so, how?
thanks!
There are a couple of options here. You can use a mouse joint or you can use a kinematic body and set it's position manually. A good example of how to use a mouse joint check this out:
http://code.google.com/p/libgdx-backend-android-livewallpaper/source/browse/gdx-backend-android-livewallpaper-example/src/com/badlogic/gdx/tests/box2d/Box2DTest.java?r=ba02aaf34a8ca07daa0c30493bab993067c652f9
If you want to use a kinematic body you would do this:
in render():
body.setTransform(Gdx.input.getX(), Gdx.input.getY(), angle);
And then you would say body.getPosition() for the rendering of your sprites. Or if you are using the debug renderer that will draw your bodies, but just as shapes.