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.

Window Problem

Hello,

I'm trying to add a window to a minigame in my project, but it always says:

Failed to create bitmap :cry:

It's with this lines:

Code:
  #--------------------------------------------------------------------------
  # * Create Window Contents
  #--------------------------------------------------------------------------
  def create_contents
    self.contents.dispose
    self.contents = Bitmap.new(width - 32, height - 32)
  end

Thanks in advance
 
Code:
class Window_Points1 < Window_Base
  
  attr_reader :points
  
  def initialize
    super(0, 0, 0, 0)
    if $game_switches[1]
      self.x = 0#640 - self.width
      self.y = 0
      self.width = 96
      self.height = 64
      self.contents = Bitmap.new(width -32,height -32)
      @points = 0
    end
    refresh
  end
  
  def refresh
    self.contents.clear
    self.contents.draw_text(0, 0, 64, 32, $game_variables[1].to_s + " Hits", 2)
    @points = $game_variables[100]
    return
  end
  
end
 

EOG

Member

BwdYeti said that
Code:
self.contents = Bitmap.new(width -32,height -32)
means something else than
Code:
self.contents = Bitmap.new(self.width -32,self.height -32)

You use:
Code:
super(0, 0, 0, 0)

Which mans that you want to create a window at position 0,0 and sizes 0,0. Looking in window_base(where 'super' leads) those are variables called x, y, width, height
and when you use code:
Code:
self.contents = Bitmap.new(width -32,height -32)
you tell:
Create bitmap using sizes 0-32,0-32 and this bitmap cannot be created.

There are two ways to solve your problem
1st: Just change the line to
Code:
self.contents = Bitmap.new(self.width -32,self.height -32)
2nd: Change line to
Code:
super(0, 0, 96, 64)
And delete lines:
Code:
self.x = 0#640 - self.width
self.y = 0
self.width = 96
self.height = 64
 
self.contents = Bitmap.new(width - 32, height - 32)

Is the same this as

self.contents = Bitmap.new(self.width - 32, self.height - 32)

As long as width is not a defined local variable before the line is called. Ruby first checks for a local_variable, then a method if a local isn't defined. The object being a window, there is a method width/height. self is really never needed to be defined within a class, unless accessing a class method (which are rare).

With what you posted above, that error shouldn't be happening (unless its VX, and VX's window class has trouble with super(0, 0, 0, 0), not creating a bitmap correctly).
 

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