ZFGC

Resources => Coding => Topic started by: Scooternew on April 16, 2006, 07:35:56 pm

Title: [Example / Listing] Saving a Sprite as a File
Post by: Scooternew on April 16, 2006, 07:35:56 pm
I didn't see a tutorial section anywhere, so I'm posting here. This simply allows you to click a sprite and save it as a file. This isn't perfect - it doesn't include a menu (like in Windows), and it may capture gray area aroudn the sprite (or background) depending on how the sprite is shaped. Either way, this is how you do it.

Code: [Select]
temp_id = instance_position(mouse_x,mouse_y,all);
if(temp_id != noone) {
    var tx, ty, tsw, tsh;
    tx = temp_id.x;
    ty = temp_id.y;
    tsw = sprite_get_width(temp_id.sprite_index);
    tsh = sprite_get_height(temp_id.sprite_index);
    screen_save_part("sprite.bmp",tx,ty,tsw,tsh);
  }

That can go in global left pressed.
Title: Re: Saving a Sprite as a File
Post by: Piers on April 16, 2006, 10:42:49 pm
Could this work as a sprite ripping program?
Title: Re: Saving a Sprite as a File
Post by: shadow_caliber on April 16, 2006, 10:56:04 pm
Only to rip sprites from your own gamemaker game =P
Title: Re: Saving a Sprite as a File
Post by: Goodnight on April 16, 2006, 11:15:45 pm
Not bad, but I think I see a little error. If the sprite's origin is not (0,0), the capture will be offset. There are some variables and/or functions to find the origin, that you'll have to subtract from the object position to get the left and top edges.
Title: Re: Saving a Sprite as a File
Post by: Scooternew on April 17, 2006, 01:33:03 am
Hehe. I'm already 10 steps ahead of you. I had to go before I could put that in, and I plan to find time this week to fix that. It shouldn't be hard with some origin finding functions.

The only real times I could see this being used "usefully" would be in some kind of Game Maker paint program.
Title: Re: Saving a Sprite as a File
Post by: AoDC on April 17, 2006, 08:38:52 am
Very good. This is very good indeed... I may use it as a Portait taker :D. Good work scooter.

Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved