Author Topic: Accelerating scrolling  (Read 3364 times)

sam

  • Fanatic
  • ***
  • Posts: 303
  • This statement is false.
    • MSN Messenger - samlancashire@hotmail.com
    • View Profile
    • samlancashire.com
    • Email
Accelerating scrolling
« on: 2006-04-02, 04:29:24 PM »
Okay, this is going to be hard to explain. If you've ever played Donkey Kong Country 3 before, than you might notice when you run to the edge of the screen and then quickly run back to the other edge of the screen the scrolling speed slows down and allows the player to get a bit further away from the middle of the screen before the scrolling cathches up with the player.

Bulbaboy

  • Regular
  • **
  • Posts: 36
    • View Profile
Re: Accelerating scrolling
« Reply #1 on: 2006-04-02, 07:19:13 PM »
For something like that, I'd probably change the scroll margins.  Specifically, ProjectObj.GamePlayer.PlayerSprite.ScrollMarginX, and (possibly) ProjectObj.GamePlayer.PlayerSprite.ScrollMarginY.

Maybe have some code that lets the game know when you've turned around, change the scroll margin, and then set a timer so you know when to change it back?  I'll let someone else handle specifics, though, since I've never played the game.  But if you can handle some scripting, you might be able to do it yourself...

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Accelerating scrolling
« Reply #2 on: 2006-04-03, 06:18:23 AM »
Set your scroll margins to a low number like 32, then try adding script like this to Player_OnAfterScrollSprites:
Code: [Select]
   With ProjectObj.GamePlayer
      DiffX = .PlayerSprite.X - .MapScrollX - 304
      DiffY = .PlayerSprite.Y - .MapScrollY - 224
      If Abs(DiffX) > 5 Then XSV = XSV + Log(Abs(DiffX)) * SGN(DiffX) / 5
      If Abs(DiffY) > 5 Then YSV = YSV + Log(Abs(DiffY)) * SGN(DiffY) / 5
      .MapScrollX = .MapScrollX + XSV
      .MapScrollY = .MapScrollY + YSV
      XSV = XSV * .95
      YSV = YSV * .95
      If ABS(XSV) < 1 Then XSV = 0
      If ABS(YSV) < 1 Then YSV = 0
   End With

And add the variable declarations to the top of the script:
Code: [Select]
Dim XSV, YSV

It's not perfect, but I think it's getting close to what you want.

sam

  • Fanatic
  • ***
  • Posts: 303
  • This statement is false.
    • MSN Messenger - samlancashire@hotmail.com
    • View Profile
    • samlancashire.com
    • Email
Re: Accelerating scrolling
« Reply #3 on: 2006-04-03, 02:18:35 PM »
Holy, thanks a lot. :)
Looks so sweet!