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).
Related
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
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);
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
Im making a game and id like to implement raycasting for the hero's laser (and other stuff in the future), i have my sprites in a sprite sheet which i bind in the beggining and access when i draw since each element knows how to draw itself, but the spritesheet is a PNG, and thus some elements posess transparency, which works ok in openGL. i know each element's position, size etc but if some sprites have transparency, the position and size arent enough for the ray cast to be perfect since it would only hit the "bounding box". So is there a way to throw a ray using Bresenham algorithm (i believe it is the lightest way, correct me if im wrong) and make it pixel perfect in openGL, so that i can acquire the collision point of the ray with the actual non-transparent zone of the first sprite it appears in the way?
There is no easy way to do this. You would have to create a custom collision checker for your raycast to see if it would pass through or if it would collide with part of the sprite.
However it might be a better idea to use a smaller bounding box, or a circle to represent it, or both. These are much easier and faster to calculate then checking every pixel within the texture.
I write simple game with libGdx. I have a hero, which always is in screen center and I must move my background sprite (or region?) to make move illusion. But my background sprite isn't infinity.
How can I create illusion of seamless infinity world?
Of course I can add several background sprites to try to cover all empty space of screen. But I must to draw out of the sceen a lot of all another objects: Houses, monsters, others heroes, etc. So I have a second question:
When I try to draw other object (a lot of objects!) out of the screen, how badly it affects memory? How to draw it correctly?
I know that OrthographicCamera in libgdx draw only viewportWidth-viewportHeight area. If it's right, then I must to move my camera and all my sprites too. I think it's not correctly.
How can I render infinity world in libgdx with OrthographicCamera?
How can I create illusion of seamless infinity world?
Create a tile background. Tile background means that if it was besides or top or bottom of itself, the edges of sticking line will not be visible to viewer.
To do this open your background image in photoshop and go to Filters > Other > Offset.
Set the offset filter to offset the background to center then try using photoshop tools to hide the edges (the + shape in image). Now again go to offset and return to 0, 0 and save your background.
When I try to draw other object (a lot of objects!) out of the screen,
how badly it affects memory? How to draw it correctly?
I have checked this and that was not much fps loosing on my test. So don't worry about it.
How can I render infinity world in libgdx with OrthographicCamera?
Move camera where-ever you want any x, y. Every time see where is camera and calculate needing tile backgrounds to draw (for example every time draw 3x3=9 backgrounds sticking together).