In game scrolling and zooming - android

I'm in the process of developing an android game. I have an activity that has a custom class that extends the view and where everything is drawn. Everything works fine and I have implemented a way to draw levels and it looks good.
The problem that I have is that the levels are clearly too big for just 1 screen and re-designing them is not an option as it affects the user experience. The only solution that I see is making the screen scrollable so that you can move around the rendered stuff and zooming. What I'm looking for is double tapping anywhere to zoom in and out and scrolling to move around the map.
What I need help with is how to do this. I know how to detect that the user has scrolled or double tapped but I don't know what I should do to actually zoom in and out and scroll (if a scroll is detected).
I have been looking around and saw some very simple tutorials but all of them deal with zooming in/out of an image which is not what I need. My level is rendered using many different bitmaps so I know I need to redraw all of them when updating the screen (zoom or scroll).
Is my case the same as having a single image. When it comes to scrolling I think what need to be done is calculating how much the screen is "moved" then update the and redraw the view bitmaps with the new scaled coordinates, is this correct? What about zooming?
Any help would be much appreciated. Thanks

Zooming should be easy once you have detected where you are currently at (zoom level i.e.)
image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);
Something like that should help you zoom out/in on the image. When the zoom levels cross a certain level, you can consider swapping out an image that is more detailed that the one you are currently rendering.

Related

100 animated pics on an Android screen

Imagine emptying a pouch having 100 stamps on a small area. That would be the starting point for my screen. I should be able to scale individual stamps in and out, animate them on a swiping gesture, overlay them and animate them so they all come towards the place of a former stamp that just got swiped out of screen, filling that space in. Plus zooming and panning over the entire screen.
I have made canvas level zooming, panning, and drawing by hand, but I feel this is going to benefit a lot from some kind of library. What should I be looking for ? Math libraries, physics, game engines ?
I don't suppose making these into ImageViews and all together into a ViewGroup and trying to make it work from there would be a good idea.
Thanks

think my Android app needs a pinch zoom and pan LAYOUT

So. Iv'e got a straight forward relative layout which I add multiple ImageViews to.
I don't want the images to obscure each other so as they are added they are translated so they don't.
As more ImageViews are added they need to be translated further and further away from the centre of the layout so as not to overlap other images and so they fall off the edge of the user's screen - no problem so far ...
I need to give the user the ability to pan to see the images that are off screen and also zoom in and out (with gestures not buttons) to see all images or focus in on one.
I think the solution to this problem is to modify the layout to allow pinch and pan but all I can find is how to create views that support pinch and pan.
I need each image to be in a separate ImageView.
Forgive me if this is the wrong way to come at this problem but any help would be much appreciated.
This might help explain:
want to scroll about and zoom around this layout (click to see)

Build my own map and interact with it with zoom and clickable areas

I need to build a screen with map of a theater, and user can interact with zoom in/out and choose seats on map.
When user touch on a seat, the icon of seat is changed.
Is there some lib/component to build my own map with touch areas? Or some good idea to use Android API to solve this problem?
Thanks.
You should take a look at the SurfaceView API.
It provides you with an easy to use abstraction for drawing on a canvas. You can use it to render your theater image and intercept touch events on it. However, zoom in and zoom out are not supported out of the box, so you should implement them separately.
Another thing you can do is show your image in an ImageView and use scaling to implement the zoom in/zoom out, but then intercepting the exact touch position can get a little tricky.

Scrolling home screen in LibGdx

I am using LibGdx to develop a game. For Now I am not using scene2D. I am struck up in increasing the levels of the game as I do not have the scrolling screen.
I like to design a a scrolling screen as it is in many games which are level based (for ref, lets say Candy crush). Could you please point me a example on how to have such a scrolling screen to show a bigger area where I can show many levels.
Thanks is Advance !
Using the Scene2D function is not necessary for this and is more for GUI implementation and different screens. The Scroll pane really shines when creating reading content that does not fit your phone. I do advice to start learning Scene2D to create MenuScreens and UI though.
What Candy Crush "simply" does is having multiple backgrounds that are placed next to each other and tile seamlessly. They use buttons in the correct place for levels. By dragging a finger across the screen the camera will move in that direction. For the movement from one level to the next there is probably something like a spline in play.
It is important only to draw the background tiles and buttons that are actually visible on the screen if you have many. Since these have fixed positions and you know your camera area and position you can calculate what to draw and what not. Just drawing everything each frame is likely to slow down your fps.
You can do a search on:
Tilemaps, for you backgrounds but you probably want them in just one direction so a simple 1D array would suffice.
Dragging, to move your camera. Here I gave a basic explanations on how I do it.
Splines, are a bit tougher and you do not really need them. They could be used to animate or move something along a curve.
Thats all, expecting you know how to create something like a button (click a sprite).

Pinch-To-Zoom feature for TiledScrollView

I used https://github.com/ened/Android-Tiling-ScrollView library to display large tiled image. Everything is working fine. Only problem is that, I want to zoom only particular part which I touched(pinch-to-zoom as in Google map). Now, its always display tiles from beginning for all zoom levels irrespective of where I touched. Sometimes, it takes me near where I want to zoom but its not perfect as sometimes it takes me to different part. Following code does moving logic
mScroller.startScroll(getScrollX(), getScrollY(), newOffsetX, newOffsetY);
First 2 parameters indicate start scroll offset and last 2 indicates destination points to where scroll ends. I tried different combinations for last 2 parameters but ran out of luck.
If it's a ImageView, I would have done
canvas.translate(x, y);
to Zoom particular part but unfortunately its not ImageView. Even though I applied ImageView zoom logic as in https://github.com/jasonpolites/gesture-imageview to tile Zoom but had no luck.
Suggestions or clues are greatly appreciated.
Thanks.
Got a very nice library for custom mapView with almost all the features of google map. Its here.

Categories

Resources