Scaling multiple views in android - java

I'm creating a board game in android. In my absolute layout, I have a board view, and a tile view. Those two views can overlap each other, since you're placing a tile onto the board by click and drag. I am not using a bitmap drawing for this since I want to handle two separate onTouchEvent for the board and for the tile.
Problem: I want my board view to be able to zoom in and pan. At the same time, I want to tile to know to scale itself. Is there anyway to do this on android? My current solution is to scale the two view separately(which is a lot of work) but I think there should be a better solution than this out there. Or my approach on this is completely off?
Any ideas or help would be appreciated. Thanks!

Related

Scaling renderered shapes in libGDX using ShapeRenderer

I've made an Asteroids game and am having trouble with different screen sizes. Yes, I know about viewports but in my case I don't think that can work. I've tried to use it but my objects are not images. Instead they're rendered by a ShapeRenderer and therefore the viewports probably not affect them I guess. I've solved how to fit the text for most types of smartphone screens but not the rendered objects like the player and asteroids. On some screens they're perfect size and other screens either too small or too big.
Is there a way to scale rendered (ShapeRenderer) types in libGDX so that they will fit the screen size / resolution? Or must I try to implement a class for common resolutions that can be used?
Here is two pictures that illustrates the problem. The text in the images are aldready fixed by the way.
EDIT:
It does work to create and apply the viewport for the ShapeRenderer now, but I'm still having the same problem. The game objects inside the viewport aren't scaled to fit the current screen. I need a way to scale down the game objects s using a viewport (if possible). The way the game is going to be implemented is that the size of the smartphone screen is the game world size. Therefore, there are little space to move the ship if the screen is pretty small. I want the objects to be moving around in an area that fits the viewport size. The game should not get more difficult or easier depending on the screen size.
Example on left: The game on a large smartphone screen
Example on right: The ShapeRenderer viewport is working
Viewports were created in order to reduce the effort needed to render on different sized screens. So are ideal for situations like this.
In order to use a Viewport with a ShapeRenerer you simply need to set the ShapeRenderer's projection matrix to the one in the viewport's camera.
shapeRenderer.setProjectionMatrix(veiwport.getCamera().combined);
This means the shapeRenderer will render the way the viewport is configured.

Stage is bigger than the screen in LibGDX, how to fit it in the screen?

I'm developing a game in libGDX, and the levels in my grid contains a grid actor which contains mirrors inside (see my game). The problem is that the grid is too big and I want to be able to see all the stage.
I'm using an OrthographicCamera and an ExtendViewport.
I tried using frustrum (I don't really know what it is): I create four BoundingBox (left, right, top and down) which are placed out of the grid. I set the camera position to the middle of the grid actor and i make a loop zooming the camera until the boxes are in the frustrum, but I don't know if it is the best solution...
I think you want to use a FitViewport, which will make sure you don't 'spill' off the screen.
FYI, the frustum is used to determine depth of your camera- how far it can see. I agree that that won't help you in this situation.

How to paint the portion of the image inside its border line via using libgdx?

I am creating an image painting app in libgdx where user would touch the portion of the image. e.g If the user touch the wheels of a car that should turn into the selected color.
I don't really know how to specify the custom area around the touch. That can be a wheel, a door which are not always rectangle and circle. I just need an idea to do it. Whether libgdx pixelmap can achive this. I have to paint the image inside the border line of the touch region. I hope my problem is clearly stated.
I woule really appreciate for your time for giving the answers. Thanks in advance
I think you want to look at flood fill algorithms. I don't think there is any built-in support for this in libGDX, but you should be able to implement your own flood fill on a libGDX pixmap.

Android Drawing on Multiple Canvas Multiple Activities

Here is my problem:
I currently have on Canvas in my main game activity that is constantly being drawn with OnDraw(). This is a board game with two players. When a player's turn begins, there are many options that the player can do, and I would like all of this to be put in a different class.
Also, this new class must draw NEW animations on top of the current canvas. These animations will came from attacks (I haven't even looked into animations yet). So basically I would like another canvas on top of the main one.
Furthermore, the OnDraw function in the main activity must PAUSE and wait for the other class with the canvas on top to complete.
Let me try and summarize this: I have a main game class with one canvas. This class handles the players' turns and setting up the game. It also draws the playing field. I need another class, when it is a player's turn, to draw animations and other things on top of the current canvas.
Can anybody help me with this?
NOTE : I looked into Fragments and FragmentManager, but it seems I can only use XML Views with that and not RenderViews.
Thank you!
You might want to consider using multiple bitmaps as buffers and then just add them on top of each other before rendering to the canvas.
There is a nice example in the "samples" pack that comes with the sdk that shows of how you can merge bitmaps on top of each other.
Let me know if you want to try this out and need some more pointers on how to do it :)

mouseListeners and JLabels using images with transparent pixels

I'm willing to make a isometric game but I'm having hard time with the mouseListener.
I'm using Swing and make losanges by using square images with transparent pixels (GIF format).
The problem is that making losanges touch each other edge means having the transparent pixels of one on the top of the others, which is a problem with the mouseListener.
I'm willing to know exactly which losange was clicked on, but as the transparent pixels of the nearby losange get on the top of the one that was clicked on, the wrong losange is selected as the KeyEvent source.
Is there a way to have mouseListener not considering transparent pixels as part of the shape ?
Thanks for reading.
It's not clear
1) why the tiles have to overlap, or
2) why you're using JLabels for the tiles
There's are many ways to solve the problem you're having, but I'd just make a single JComponent that renders the tiles as needed, and is the sole MouseListener.
As mentioned by Jonathan, I think you're using the wrong technology for the job. I've had great success using a 2D graphics framework for software such as this. In my case I'm a big fan of Piccolo. I know you don't want to hear this, but consider starting over with the appropriate toolset.

Categories

Resources