Maths/logic for smooth scrolling up and down of text? (Not using scrollbar)
Hey guys, am a bit stumped on this one, so would appreciate any input.
I'm developing for iPhone portrait and have an actor 1500 pixels tall with an image which is essentially a block of text. I'm trying to implement touch-drag scrolling on the actual actor (not through a scrollbar) so that you'll be able to read all the text, since at any one time only 480 pixels (iPhone height) will be visible.
While it's easy enough just constraining self position Y to mouse Y position, it is not seamless. The moment you touch the screen anywhere, the actor's self position Y will of course jump straight to your finger, no matter how far you've scrolled before. Swiping upwards or downwards multiple times consecutively is the most noticeable - the centre of the image will always jump back to your finger before scrolling up/down slightly. This is really irritating as you can imagine, if you're reading a book, every time you scroll, the image 'jumps'.
I'm trying to achieve the scrolling you'd expect naturally (just try scrolling a webpage on safari on your iPhone), the centre of the page will not 'jump' to your finger the moment you touch your screen.
I'm not sure if I've explained this very well, but have been staring at a blank for way too long. Have also tried numerous values e.g. taking account height - mouse position Y etc type equations, but can't seem to get it quite right.
If any expert can jump in I'd appreciate it
Cheers
I'm developing for iPhone portrait and have an actor 1500 pixels tall with an image which is essentially a block of text. I'm trying to implement touch-drag scrolling on the actual actor (not through a scrollbar) so that you'll be able to read all the text, since at any one time only 480 pixels (iPhone height) will be visible.
While it's easy enough just constraining self position Y to mouse Y position, it is not seamless. The moment you touch the screen anywhere, the actor's self position Y will of course jump straight to your finger, no matter how far you've scrolled before. Swiping upwards or downwards multiple times consecutively is the most noticeable - the centre of the image will always jump back to your finger before scrolling up/down slightly. This is really irritating as you can imagine, if you're reading a book, every time you scroll, the image 'jumps'.
I'm trying to achieve the scrolling you'd expect naturally (just try scrolling a webpage on safari on your iPhone), the centre of the page will not 'jump' to your finger the moment you touch your screen.
I'm not sure if I've explained this very well, but have been staring at a blank for way too long. Have also tried numerous values e.g. taking account height - mouse position Y etc type equations, but can't seem to get it quite right.
If any expert can jump in I'd appreciate it
Cheers
Best Answer
-
RThurman Posts: 2,881
Make an attribute called 'offset' (type = integer or real)
When touch is pressed
-- Change Attribute: (self.offset) To: (self.Position.Y - game.Mouse.Position.Y)
-- Constrain Attribute: (self.Position.Y) To: (game.Mouse.Position.Y + self.Offset)
Answers
@RThurman thanks! I thought maths in the title would attract your presence ;p I feel like duh after reading your response (I blame years of prolonged Wow abuse for frazzling the lateral thinking part of my brain). Now it's all clear and solved the problem perfectly. Combined with max and min functions, I've got it to work flawlessly. Thanks again!
Obviously I can't take credit for the solution. I'm sure I picked it up from one of the great luminaries of GameSalad.
Love your signatuure!
Thanks
Conner
Hmmm... strange that my replies from last August are missing from the above discussion.
Well... anyway -- Here is a solution that might work for you.
Make a new actor-attribute called yOffset (type = real). Then give your scrolling actor the following rule:
When touch is pressed
-- Change Attribute: [self.yOffset] To: [self.Position.Y - game.Touches.Touch 1.Y]
-- Constrain Attribute: [self.Position.Y] To: [game.Touches.Touch 1.Y + self.yOffset]