I want to make a piece of script that loads an image file but I don't know how to get the script to load an image file by path much less do stuff with it such as displaying the image file or splitting it into frames. I intend to use this to create animated battlers from scratch. Any help?
Loading Image Files using pure script.
Learning Ruby and RGSSxOK... As far as I know RM2003 has no scripting so which RM engine are you using now?
RPG Maker XP. The "Primarily Uses" field on my profile is not the version of RPG Maker that I'm referring to in this topic.
To load any supported image file you'd need to call...
RPG::Cache.picture('filename')
There "picture" can be replaced with any other variant like icon or battler, but character sets and battler sets need a second argument, the hue.
self.bitmap = RPG::Cache.picture('filename')
That line will let you assign the bitmap you loaded to a specific Sprite, if you're defining it inside a Sprite class or subclass.
RPG::Cache.picture('filename')
There "picture" can be replaced with any other variant like icon or battler, but character sets and battler sets need a second argument, the hue.
self.bitmap = RPG::Cache.picture('filename')
That line will let you assign the bitmap you loaded to a specific Sprite, if you're defining it inside a Sprite class or subclass.
Oh, okay. Because I'm making an Animated Battlers script from scratch, using 32-bit imges that are split into frames, like this:
Then you'd need to play with the frames a la Sprite_Character so go check it out.
Hm, how am I supposed to split the image into frames though? Sprite_Character has no animation in it.
Actually it does include a way to just show one frame at a time and that's what you're looking for. Then you only need to worry about updating it after n frames but that can be found there as well. Just read Sprite_Character's update method carefully.
Oh yeah, and I don't think Game_Character is for battle sprites, I think it may be for overworld sprites.
UPDATE: I managed to make the game use my custom battle sprite, but for some reason, when I use RPG::Cache.picture(Insert filename here), it insists on searching for the file in Graphics\Pictures instead of just starting in the Graphics folder. Is there a way of preventing this?
UPDATE: I managed to make the game use my custom battle sprite, but for some reason, when I use RPG::Cache.picture(Insert filename here), it insists on searching for the file in Graphics\Pictures instead of just starting in the Graphics folder. Is there a way of preventing this?
Open the help file (F1) and search for "cache". You should get a list of all the RPG::Cache function calls you can make for the various image folders.
Thanks! I changed the RPG::Cache.picture to RPG::Cache.battler(filename, 1) and now I don't have to put everything in the pictures folder.
Now to get into the bitmap cropping...
Now to get into the bitmap cropping...
Keep in mind I TOLD YOU before that you'd need to change that depending on what kind of graphics you might be using there.
Anyway, Sprite_Character's update method does include a portion of code that actually crops it and updates it every other frame or after it got some input from you. Once you learn how to use it, you'd need to adapt it to your custom battler.
Anyway, Sprite_Character's update method does include a portion of code that actually crops it and updates it every other frame or after it got some input from you. Once you learn how to use it, you'd need to adapt it to your custom battler.
I've looked at the code used in Sprite_Character and I still don't understand. I've tried using self.src_rect.set() but that just makes the sprite disappear. Which line of code do I need for this?
Here a super simple example
Code:
spr = Sprite.new
spr.bitmap = Cache.system("iconset")
loop do
Graphics.update
Input.update
end
I really doubt that that would help...
Depends. Have you tried it?
I can try to help you if you're willing to learn from very basic.
So, have you tried it? Put it in as a new script.
EDIT: I just realized that this is RMXP
But it should not be much different
Code:
spr = Sprite.new
spr.bitmap = Bitmap.new("Graphics/System/iconset")
loop do
Graphics.update
Input.update
end
What I'm trying to do is get a piece of code to crop a bitmap sprite that I've already loaded in the Sprite_Battler class. And the picture in question is in Graphics\Battlers, not Graphics\System.
EDIT: I forgot to add: I have been able to call the image file, make it appear on the battle screen, and specify the co-ordinates where I want it to appear. All I need to be able to do now is crop the sprite.
EDIT: I forgot to add: I have been able to call the image file, make it appear on the battle screen, and specify the co-ordinates where I want it to appear. All I need to be able to do now is crop the sprite.
If you don't get it, it's an example.
Are you looking for this?
Code:
spr = Sprite.new
spr.bitmap = Bitmap.new("Graphics/System/iconset")
loop do
Graphics.update
Input.update
if Input.press?(Input::RIGHT)
spr.src_rect.width += 10
elsif Input.press?(Input::LEFT)
spr.src_rect.width -= 10
end
end
Code:
spr = Sprite.new
spr.bitmap = Bitmap.new("Graphics/System/iconset")
spr.src_rect.set(0,0,24,24)
index = 0
loop do
Graphics.update
Input.update
if Graphics.frame_count % 5 == 0
index = (index + 1) % 16
end
spr.src_rect.x = index * 24
end
I don't recall XP letting scripters modify the src_rect's width or height like that. I suspect it will fail but I guess I'd confirm my suspicions...
Here is some code from Sprite_Character line 57
When I created my animated mouse cursors I had the graphics file be 1 frame high and a number frames wide. (This could be configured)
Later when I wanted to change the frame I would use
Ruby:
# Set rectangular transfer
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
When I created my animated mouse cursors I had the graphics file be 1 frame high and a number frames wide. (This could be configured)
Ruby:
class Sprite_Mouse < Sprite
# (...)
def setup_anim
# (...)
h = bitmap.height
w = bitmap.width / @anim_frames
self.src_rect.set(0,0, h, w)
self.src_rect.x = self.src_rect.width * @animation_no
end
end
Ruby:
self.src_rect.x = self.src_rect.width * animation_no
Original thread: https://forums.rpgmakerweb.com/threads/loading-image-files-using-pure-script.123407/