Maths/logic for smooth scrolling up and down of text? (Not using scrollbar)

ChobbifaceChobbiface PRO Posts: 491
edited August 2012 in Working with GS (Mac)
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

Best Answer

  • RThurmanRThurman Posts: 2,881
    Accepted Answer
    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

  • lycettebroslycettebros Member, PRO Posts: 1,598
    edited August 2012
    sorry removing my response it is no help.
  • ChobbifaceChobbiface PRO Posts: 491
    Hey @LycetteBros no worries, thanks for trying :)

    @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!
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @chobbiface -- No problemo!

    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!
  • BIG_THINKIN_APPSBIG_THINKIN_APPS Member Posts: 944
    I am making an app that needs to do the same thing how did you get it to work!

    Thanks
    Conner
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @BIG_THINKING_APPS

    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]


  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    What I've found works best and prevents the actor from snapping to a new location when released and then tapped again is this:

    image
Sign In or Register to comment.