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.

Tiling the Windowskin selector

Star

Sponsor

What's up guys!

So I was working on making a windowskin and I found out that the selector in the window skin or the self.cursor_rect stretches across the anything you're selecting. Is there a way to make it Tile from the middle instead of stretching? I'm sure this thing is managed in a hidden window class cause I can't find it anywhere.
 
I've been all I can be today, but if you look in update_cursor_rect in Window_Selectable, you'll see where the cursor rectangle gets set.
It is a hidden object in the window class.
there are a couple scripts out there that replace the cursor with a hand or pointer.
I suspect what they do is just keep the built-in cursor invisible (clear), and draw in their own using the x & y in that method.
You would also need to use the 'width' to determine where to start tiling.

I'll take a stab at this when I have time if no one else does.

If you have time, take a look around for the other scripts I mentioned. Might be a pretty good start.

Be Well
 
Hiya! Star wanted me to let you (or you guys know) that he tried looking at those lines in the script and couldn't figure anything out. He's at work right now. >>

I tried searching for a cursor or pointer script and couldn't find anything myself, so if this doesn't work we're have to think of something. o.o
 
I just did this like an hour ago.

Go to Window_Selectable, and the update_cursor_rect method

At the bottom of that, is the self.cursor_rect.set(blahblah) line, this is where it is drawn.

I'm not quite sure what you want to accomplish. If you are looking to take the regular 32x32 selector image and make it stay 32x32, but centered across the selection, you would do something like:

self.cursor_rect.set(x + (cursor_width / 2) - 16, y + self.oy, 32, 32)

i dunno you'll have to mess with the numbers yourself but its all there in that last line.
 

Zeriab

Sponsor

Does window.stretch work? If not I am afraid you'll have do something else like playing around with planes and viewports or tile it yourself. (Dunno what the perf impact will be)
 
I found a way to do this using Selwyn's Window Rewrite. You can get the original script here.

Place that script at the very top of your script editor above all scripts. then directly below it, place the following edit:

Code:
#==============================================================================

#  –  SG::Cursor_Rect

#==============================================================================

# Edited by Draycos Goldaryn for Star on HBGames.org

#==============================================================================

class SG::Cursor_Rect

  #--------------------------------------------------------------------------

  #  — instances settings

  #--------------------------------------------------------------------------

  attr_reader   :height, :width, :skin, :margin

  #--------------------------------------------------------------------------

  #  — initialize

  #--------------------------------------------------------------------------

  def initialize(viewport)

    super(viewport)

    @width = 0

    @height = 0

    @skin = nil

    @margin = 0

    @rect = Rect.new(128, 64, 32, 32) #use the whole cursor from the windowskin

  end

  #--------------------------------------------------------------------------

  #  — draw_rect

  #--------------------------------------------------------------------------

  def draw_rect

    return if @skin == nil

    #tile the rect across the selection

    if @width > 0 and @height > 0

      #set the width and height

      self.bitmap = Bitmap.new(@width, @height)

      #find how many times it'll tile

      max_x = self.bitmap.width / @rect.width

      max_y = self.bitmap.height / @rect.height

      #tile it

      for x in 0..max_x

        for y in 0..max_y

          self.bitmap.blt(x * @rect.width, y * @rect.height,

           @skin, @rect)

        end

      end

    end

  end

end

 

#replace the default Window class now.

class Window < SG::Window ; end

The reason these need to be placed at the top is so that Window_Base will be a child of our new Window class instead of the hidden one.

This will actually tile from the upper-left instead of the center, but it should still work.
 

Star

Sponsor

I tried out what Draycos told me to do. Worked out pretty well. I just made a small edit so that it tiled and gave it ends to the beginning and end of the selector. Thanks guys!

Code:
#==============================================================================

#  –  SG::Cursor_Rect

#==============================================================================

# Edited by Draycos Goldaryn for Star on HBGames.org

#==============================================================================

class SG::Cursor_Rect

  #--------------------------------------------------------------------------

  #  — instances settings

  #--------------------------------------------------------------------------

  attr_reader   :height, :width, :skin, :margin

  #--------------------------------------------------------------------------

  #  — initialize

  #--------------------------------------------------------------------------

  def initialize(viewport)

    super(viewport)

    @width = 0

    @height = 0

    @skin = nil

    @margin = 0

    @rect = Rect.new(129, 64, 30, 32) #middle of the cursor

    @rect1 = Rect.new(128, 64, 1, 32) #ends of the cursor

  end

  #--------------------------------------------------------------------------

  #  — draw_rect

  #--------------------------------------------------------------------------

  def draw_rect

    return if @skin == nil

    #tile the rect across the selection

    if @width > 0 and @height > 0

      #set the width and height

      self.bitmap = Bitmap.new(@width, @height)

      #find how many times it'll tile

      max_x = self.bitmap.width / @rect.width

      max_y = self.bitmap.height / @rect.height

      #tile it

      for x in 0..max_x

        for y in 0..max_y

          self.bitmap.blt(0, y * @rect.height,

           @skin, @rect1)

          self.bitmap.blt(x * @rect.width, y * @rect.height,

           @skin, @rect)

          self.bitmap.blt(@width - 1, y * @rect.height,

           @skin, @rect1)

        end

      end

    end

  end

end

 

#replace the default Window class now.

class Window < SG::Window ; end
 

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