Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Scroll Map Options

Purpose:
This script allows the map to be scrolled to a certain x, y position. It also allows the map to be scrolled to the player's position.

Instructions:
Paste anywhere above Main to use. No set-up required.

Call $game_map.scroll_to(x posiition, y position, speed) in a call script to scroll to position x, y.

Call $game_map.find_player(speed) in a call script to scroll to the player's position.

Call $game_map.clear_scroll to stop any scroll_to or find_player actions. Use $game_map.clear_scroll(false) to stop any current scrolling as well.

This script is free-to-use. Credits are appreciated but not necessary at all.

To wait for the completion of the scroll, use the following loop:
scrollingscripthelp.png


This loop can be called from a common event and in any type of event except for a parallel process will also stop the player from moving.

Code:
Ruby:
 

###############################################################################

#SCROLL-TO 

#by Pokemaniac

#

#Call $game_map.scroll_to(x posiition, y position, speed) in a call script to 

#scroll to position x, y.

#

#Call $game_map.find_player(speed) in a call script to scroll to the player's

#position.

#

#Call $game_map.clear_scroll to stop any scroll_to or find_player actions. Use

#$game_map.clear_scroll(false) to stop any current scrolling as well.

#

#This script is free-to-use. Credits are appreciated but not necessary at all.

###############################################################################

 

class Game_Map

  

  #Initialize variable

  alias initialize_scroll_to initialize unless $@

  def initialize

    initialize_scroll_to

    @scrollWaiting = []

  end

  

  #Scroll to

  def scroll_to(x, y, s = 4)

    

    @scrollWaiting << [x, s, true]

    @scrollWaiting << [y, s, false]

  end

  

  #Get scroll details

  def scroll_details(dis, s, hor)

    

    #if x-axis

    if hor == true

      dis -= 8

      dis -= @display_x / 256

    

      #Get direction

      if dis > 0

        dir = 6

      else

        dir = 4

        dis *= -1

      end

    

    #if y-axis

    else

      dis -= 6

      dis -= @display_y / 256 

      #Get direction

      if dis > 0

        dir = 2

      else

        dir = 8

        dis *= -1

      end

    end    

    

    dis = 0 if dis < 0

    return [dir, dis, s]

  end

  

  #Clear Scroll List

  def clear_scroll(finish = true)

    @scrollWaiting = []

    if !finish

      @scroll_rest = 0

    end

  end

  

  #Return to player

  def find_player(speed = 4)

    @scrollWaiting << [-1, speed, true]

    @scrollWaiting << [-1, speed, false]

  end

  

  #Change refresh

  alias update_scroll_to update unless $@

  def update

    update_scroll_to

  

    #If not already scrolling and if there are more scroll commands

    if !scrolling?

      if @scrollWaiting == nil

        @scrollWaiting = []

      elsif !@scrollWaiting.empty?

        newScroll = @scrollWaiting[0]

 

        #If scroll to player

        if newScroll[0] == -1

          if newScroll[2] == true

            xy = $game_player.x 

          else

            xy = $game_player.y 

          end

        else

          xy = newScroll[0]

        end

        

        newScroll = scroll_details(xy, newScroll[1], newScroll[2])

        dir = newScroll[0]

        dis = newScroll[1]

        spe = newScroll[2]

        start_scroll(dir, dis, spe)

        @scrollWaiting.shift

      end    

    end

  end

  

end

 
 
Nice script. This could be useful for cutscenes or showing the layout of areas for recon-esque scenes or when the player first enters an important area. This reminded me of how the later Gex game would do something akin to this, scrolling over to the level's current objective.
 
Thanks! Yeah, honestly, this could probably be used almost any time you want to use the normal scroll (to save you having to count out the number of spaces to the object) and any time you want to scroll to a variable place or you don't know where you'll be scrolling from(or both at once). It's something I've wanted in RPG Maker for ages and I only just realised today that I knew enough scripting to do it. :P
 
No, but this can:
Ruby:
###############################################################################

#INSTANT SCROLL

#By Pokemaniac

#

#Call $game_map.instant_scroll(x,y) to instantly 'scroll' to x, y.

#

#Call $game_map.instant_player to instantly 'scroll' to the player.

#

#This script is free-to-use. Credits are appreciated but not necessary at all.

###############################################################################

class Game_Map 

 

  #Set the display to an x, y co-ordinate instantly 

  def instant_scroll(x,y)

    x -= 8

    x = 0 if x < 0

    x = (width - 17) if x > width - 17

    x *= 256

    y -= 6

    y = 0 if y < 0

    y = (height - 13) if y > height - 13

    y *= 256

    set_display_pos(x,y)

  end

  

  #Sets the display to the x, y co-ordinates of the player instantly 

  def instant_player

    x = $game_player.x

    y = $game_player.y

    instant_scroll(x,y)

  end

  

end

 
 
Sorry for double post - I checked that instant scroll script - it didn't work.

It throws me an error:

Script Instant Scroll line 23: NoMethodError
undefined method 'set_display_pos' for <Game_Map>

Any solution?
 
Um, I'm a bit busy at the moment. Would someone like to take this? You'd just have to change the vocab, and change the 8, 6, 13 and 17 to the XP screen width/height in tiles, hopefully. Sorry!
 
Ruby:
###############################################################################

#INSTANT SCROLL

#By Pokemaniac

#

#Call $game_map.instant_scroll(x,y) to instantly 'scroll' to x, y.

#

#Call $game_map.instant_player to instantly 'scroll' to the player.

#

#This script is free-to-use. Credits are appreciated but not necessary at all.

###############################################################################

class Game_Map

 

  #Set the display to an x, y co-ordinate instantly

  def instant_scroll(x,y)

    x -= 10

    x = 0 if x < 0

    x = (width - 20) if x > width - 20

    x *= 128

    y -= 7

    y = 0 if y < 0

    y = (height - 15) if y > height - 15

    y *= 128

    @display_x = x

    @display_y = y

  end

 

  #Sets the display to the x, y co-ordinates of the player instantly

  def instant_player

    x = $game_player.x

    y = $game_player.y

    instant_scroll(x,y)

  end

 

end

The centering's pretty bad because XP has a stupid amount of tiles, but there you go!
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top