Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Would someone review my pinch/zoom/scroll code?

Author
Message
CumQuaT
AGK Master
13
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 19th Jan 2018 03:12
Hi all, I'm working on a new app which involves using pinch/zoom/scroll to move the view around in the scene. The scene itself is static and laid out elsewhere, all the user does is change the offset and zoom of the viewer using SetViewOffset and SetViewZoom.

The code actually works just fine, but is a liiiiiiiiiitle bit more jittery/jumpy than I'm comfortable with, and - given that this is my first time playing with these sorts of raw data commands - I figured I'd ask the community for a bit of a code review and perhaps any suggestions which might make my life a little easier.

Help out a fellow dev! Download and rate my games! They're free!

Wizzed Off! - (Android) (iOS)
God of Thunder - (Android) (iOS)
Extreme Lawn Mowing - (Android) (iOS)
Drunken Heroes - (Android) (iOS)

And you can get Fluffy Knuckleduster merchandise at our new store!
CumQuaT
AGK Master
13
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 21st Jan 2018 03:23
No-one?
Help out a fellow dev! Download and rate my games! They're free!

Wizzed Off! - (Android) (iOS)
God of Thunder - (Android) (iOS)
Extreme Lawn Mowing - (Android) (iOS)
Drunken Heroes - (Android) (iOS)

And you can get Fluffy Knuckleduster merchandise at our new store!
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Jan 2018 03:35
I will have a look tomoz if that's ok?
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 21st Jan 2018 03:51
Well I actually did copy & paste the code into a project and ran it but couldn't see anything on screen nor see it doing anything when I clicked mouse button etc. I'd need to know what it is supposed to be doing and what it is actually doing. I mean I guess I could go through the lines of code and see if anything stands out but I was thinking I would be able to see the jittering/jumping you mentioned.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
CumQuaT
AGK Master
13
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 21st Jan 2018 09:07 Edited at: 21st Jan 2018 09:08
Blink0k that's awesome, thank you.

GarBenjamin you've gotta actually have a scene first if you're going to test it... This is just the pinch/zoom/drag code. You need to have a sprite on screen or something that you can test it with.
Help out a fellow dev! Download and rate my games! They're free!

Wizzed Off! - (Android) (iOS)
God of Thunder - (Android) (iOS)
Extreme Lawn Mowing - (Android) (iOS)
Drunken Heroes - (Android) (iOS)

And you can get Fluffy Knuckleduster merchandise at our new store!
CumQuaT
AGK Master
13
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 22nd Jan 2018 06:17
So I added a short cooldown timer to the pinch/zoom recognition so that it wouldn't allow a tap for 4 frames after releasing a pinch/zoom. That seems to have evened the whole thing out and made it nice and smooth.

I'll leave the post here for posterity in case anyone else ever needs to do this sort of thing.
Help out a fellow dev! Download and rate my games! They're free!

Wizzed Off! - (Android) (iOS)
God of Thunder - (Android) (iOS)
Extreme Lawn Mowing - (Android) (iOS)
Drunken Heroes - (Android) (iOS)

And you can get Fluffy Knuckleduster merchandise at our new store!
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 22nd Jan 2018 11:19
SetViewZoomMode(1) will centre the zoom instead of zooming from the corner. You could also keep track of the difference of the two pinch points and apply that to the view offset to allow the user to zoom and scroll simultaneously.
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 22nd Jan 2018 15:26 Edited at: 22nd Jan 2018 15:55
Sounds promising, CumQuat. I just tested with a large image in my device and worked well. You could improve the scrolling by adding more smoothness (like the inertia after swiping). Cheers!
CumQuaT
AGK Master
13
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 23rd Jan 2018 00:25
@CJB yep already doing that it'd be nice if AppGameKit had the functionality to be able to choose where the centre is, though, for more accurate zooming.

@Richard_6 - not a bad idea!
Help out a fellow dev! Download and rate my games! They're free!

Wizzed Off! - (Android) (iOS)
God of Thunder - (Android) (iOS)
Extreme Lawn Mowing - (Android) (iOS)
Drunken Heroes - (Android) (iOS)

And you can get Fluffy Knuckleduster merchandise at our new store!

Login to post a reply

Server time is: 2024-04-23 22:26:15
Your offset time is: 2024-04-23 22:26:15