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.

How to show picture with RGSS?

older thread about showing picture with RGSS : http://www.rmxp.org/forums/index.php?topic=37965.0

Code:
event_id = 0
# Create a sprite object to draw our picture.
@globe = Sprite.new
# Initialize the bitmap.
@globe.bitmap = RPG::Cache.load_picture(event_id)
# Move it to the specified location. 
@globe.x, globe.y = $game_variables[event_id], $game_variables[event_id + 50]

@globe.bitmap = RPG::Cache.load_picture(event_id)
this line defines what picture i want to show, right?
What should i do if i want to show my own picture? Should I import it first? Then what should I type there?

I don't understand this 'RPG::Cache.load_picture(event_id)'
care to explain?
 
Well really all you have to do is this:

Code:
@picture = Sprite.new
@picture.bitmap = RPG::Cache.picture('File_name') # Just replace 'File_name' with the name of the picture file. Keep quotes.
@picture.x = 0 # Change to whatever x
@picture.y = 0 # Change to whatever y

All you have to do is put your picture in the "picture" folder, name it whatever you want, and replace 'File_Name' with the name of the picture you want.

The line 'RPG::Cache.load_picture(event_id)' has nothing to do with what you're trying to do. I guess that person named their picture a number, and depending on the number, a certain picture would be called.
 

khmp

Sponsor

Ignore the event id that was something he/she requested. In your case it would be a filename of the image you want to show. So what does load_picture mean. Nothing, perhaps at the time I was just being dumb or writing nearly complete psuedocode. Probably the prior. What I probably meant was:
Code:
RPG::Cache.picture(filename)

Cache has a lot of loading methods.
battler
icon
panorama
tileset
title
picture

What they basically do are shortening this method:
Code:
RPG::Cache.load_bitmap(dir, filename, hue)

RPG::Cache.title will automatically throw in '/Graphics/Title/' as the dir and you only need the filename of the title screen image.

RPG::Cache.picture will load an image from the '/Graphics/Pictures/' directory.

If you want to show your own picture. First you should place the image in the directory you feel is most appropriate. You might even consider separating the images further within that folder. Anyway let's say you wanted to load an a file within the '/Graphics/Pictures/' directory and its named 'test.png'.

First we need to create a sprite object.
Code:
$test = Sprite.new
$test.bitmap = RPG::Cache.picture('test.png')
# Alternatively you can also initialize a bitmap like this:
# $test.bitmap = Bitmap.new('/Graphics/Pictures/test.png')

Then when you are done with the bitmap and the sprite:
Code:
$test.bitmap.dispose unless $test.bitmap.disposed?
$test.dispose unless $test.disposed?

I gave it global scope($) but it really depends on the application what scope the sprite should be. If we wanted to relegate this to a particular scene and the sprite would need to be accessed across several methods I would give it instance scope(@). Or if I could get away with it only needing to be accessed through main I would give it local scope. Which means it has no prefix.

I recall you asking what alias_method does. alias_method is used to save a reference to older code without overriding it. Whenever I code out a method and create a method by the same name within the same class I will overwrite the old method and the new one will run. Sometimes we want to avoid this situation so we use alias_method.

Like for example with the default scripts. Let's say I want to add a HUD to Scene_Map's main and have it update within Scene_Map's update. I don't want to overwrite the old code. I'd rather preserve it so I don't have to recode the whole thing.

Code:
class Scene_Map
  alias_method :old_main, :main
  alias_method :old_update, :update
  def main
    @test = HUD.new
    old_main
    @test.dispose
  end
  def update
    @test.update
    old_update
  end
end

Good luck with it DelSolu! :thumb:

[edit]
Doh, sorry xBrokenSin. I had most of it typed up but got sidetracked.
 

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