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.

Zooming an Image within a Window

I was working on a script for someone and needed to know how to change the zoom for an image, so basically change it's resolution. I've tried creating a sprite like so...
Code:
def refresh
  self.contents.clear
  @sprite = Sprite.new
  @sprite.bitmap = RPG::Cache.picture('test')
  @sprite.zoom_x = 0.5
  @sprite.zoom_y = 0.5
end
def dispose
  super
  @sprite.dispose
  @sprite.bitmap.dispose
end

That didn't work. Then I tried calling it within the scene that this window was being displayed on instead of in the window, but for some reason it wasn't working, and I've done it before in other scenes but it didn't work this time. I know for a fact that it isn't the image because I could set it up in the window like so...
Code:
def refresh
    self.contents.clear
    test = RPG::Cache.picture('test')
    w = test.width + 4
    h = test.height + 4
    src_rect = Rect.new(0, 0, w, h)
    self.contents.blt(0, 8, test, src_rect)
end
But, I want to get a zoom effect on it, or basically just lower it's resolution, because I don't want to have more than one of the same image, but smaller in my pictures folder. Any ideas as to how I can shrink an image?
 
The sprite zoom_x and zoom_y are not working? It was supposed to work...
To zoom the bitmap in the window you have to use strech_blt not blt:
Code:
    zoom = 0.5
    bitmap = RPG::Cache.picture('test')
    dest_rect = Rect.new(x, y, bitmap.width * zoom, bitmap.height * zoom)
    self.contents.strech_blt(dest_rect, bitmap, bitmap.rect)

Edit:
Code:
@sprite.bitmap.dispose
Don't do that, it will mess with the game cache.
 

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