ScrollView with Pinch and Zoom?

PenguinHero

Member
Licensed User
Longtime User
Hi All,

I've started my next project, which is another top-down 2D game.

I've been searching the forums and found bits and pieces of what I want, but have found nothing exact. I'd rather not reinvent the wheel if what I want is already out there. :)

Is there a library that will allow me to define the game board with an area larger than the screen (like a ScrollView) that also supports Pinch and Zoom that will automatically resize whatever is visible to the user?

The best existing example I can think of is the functionality present in a game like Angry Birds where the playing area is larger than the screen, so the user can just drag to move the viewing area and/or pinch & zoom to change the size of what they are currently seeing.

Does B4A currently have a library that supports this?
If not, should I look at using a ScollView and use the Gestures library to detect the pinch/zoom and write code to resize everything that is in the now visible area of the screen?
Are there other libraries I should consider?

Thanks for any suggestions.


PenguinHero.
 

Informatix

Expert
Licensed User
Longtime User
For now, I think that the best way is to use the ScrollView2D and GestureDetector libraries. If you draw everything with a scale factor, you just have to change this scale factor to zoom in or out. It's what I do for my current game. It's mandatory if you want to adapt the display to different devices.
 
Last edited:
Upvote 0

PenguinHero

Member
Licensed User
Longtime User
Thanks Informatix.

I hadn't thought of using my scaling modifiers in that way.

I guess I could re-call my drawing routines after clearing the canvas applying the modified scale, or another way could be to iterate through the objects on the ScrollView's panel and resize them with the modified rescale value, while keeping the view centred on the area that is being pinched/zoomed.

I'll have to have a play with it and see how it goes.
 
Upvote 0

jyounger

Member
Licensed User
Longtime User
For now, I think that the best way is to use the ScrollView2D and GestureDetector libraries. If you draw everything with a scale factor, you just have to change this scale factor to zoom in or out. It's what I do for my current game. It's mandatory if you want to adapt the display to different devices.


Informatix,

Can you elaborate or give a short example on what you mean by drawing with a scale factor? I have multiple 256x256 image tiles that I lay down, and I am using Scroll2D, but I would like to know how to scale the whole panel once, rather than re-tiling at a new scale factor. Help?
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Informatix,

Can you elaborate or give a short example on what you mean by drawing with a scale factor? I have multiple 256x256 image tiles that I lay down, and I am using Scroll2D, but I would like to know how to scale the whole panel once, rather than re-tiling at a new scale factor. Help?
When I wrote this post, libGDX did not exist yet. To draw a tiled map, you should use libGDX instead of the workaround described here.
 
Upvote 0
Top