I'm currently using OpenGL to draw sprites on a texture laid on a SurfaceView. Everything works except for the fact that as soon as a sprite (which as of now is a simple 2D triangle built following Google's own developer tutorial) is drawn the SurfaceView gets dimmer. It happens only the first time and then it stays with that brightness layer. What am I doing wrong?
Related
I'm quite new to LibGDX but not a beginner in java programming. I was making a Flappy bird like game. I used Orthographic camera in my play state so it would follow the bird, but now i want to make a game over screen. I created a class with all the code i need but when i try it still uses the Orthographic camera at the birds position before it died, so the textures on that game over screen are heavily out of place, although isTouched() method is at the right position, so if i press that region i set earlier it restarts the game as it should. The only problem are the textures. Could someone help me solve the problem as i can't figure it out.
I think you want something similar to HUD, which is always displayed on the screen, right?
If so, you can use another orthographic camera, name it hudCam or something you remember.
Not sure if necessary but I changed Y-down of the camera to false like this:
hudCamera.setToOrtho(false, WIDTH / 2, HEIGHT / 2); // width and height being the screen size
Then you can just switch between the cameras when drawing.
batch.setProjectionMatrix(camera.combined);
draw...
batch.setProjectionMatrix(hudCamera.combined);
draw HUD stuff...
To get the correct mouse coordinates, just do like you did with the other camera, unproject it.
imagine that, an imaginary minecraft, where you build cubes.
You have a panel where you have the diferents cubes(tool box),
and other big panel, the world where you build, but the world is bigger.
and all of this things are in the same screen, imagine how can i put a orthografic camera that only zoom the panel where you have the whole world, that it allows you to zoom and build cubes with details and presicion, but the tool box panel still the same position. always visible. ?
Use two cameras. One for the "game" and one for the "HUD".
During a render call, use one camera to render the game, then "switch" cameras and then render the HUD. How you switch cameras depends on what API you're using to render objects (for example use setProjectionMatrix on a SpriteBatch).
You could also create more than one SpriteBatch or more than one Stage (as each tracks camera state internally), but they're a bit heavy-weight.
Beware that when switching contexts, you will probably have to explicitly end/flush/complete the first context before starting the second.
You do not use one Camera to show the stuff. For example you use a Camera for the background of your game and you have a second camera for the game Hud that always has a fixed size. But the game in background can be zoomed in and out because its an different camera.
But for simple boxes on the screen you do not use a second camera. You just use one more Stage that get displayed or not where the new "ui" stuff is shown.
Hope this helps a bit.
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).
I'm currently developing a game for Android.
As part of the game, I need to have a circle that increases and decreases in size, but not with a simple single-colour paint fill.
Instead, is there a way I could dynamically draw a circle onto a canvas then fill it with a given image (probably another bitmap - tiled, in order to fill the image)?
Many thanks in advance,
Will.
You want to do a simple Canvas.drawCircle(), but using a Paint with a BitmapShader.
So I am trying to draw square over live CameraPreview.
I followed camera instructions on developer.android and I got CameraPreview class set up.
I was wondering how could I draw a square on top of the live image.
Something what we can see in face detection on cameras. I wont use it for face detection but same idea.
I have CameraPreview object that i place in my camera activity. Now any suggestions on how to go about learning about this or if you know of any code sample for it.
That would be great. And I am looking to do this in API 10. Not 14 which supports it through sdk.
This is what my current camera app code is based on http://developer.android.com/guide/topics/media/camera.html
Thanks
Put your SurfaceView (which you need for the camera preview) inside of a FrameLayout. Then, you can put that square image right on top of the camera preview.