Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [Example / Listing] Saving a Sprite as a File  (Read 3343 times)

0 Members and 1 Guest are viewing this topic.
[Example / Listing] Saving a Sprite as a File
« on: April 16, 2006, 07:35:56 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1635
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.
« Last Edit: February 24, 2012, 10:47:53 am by Niek »
Logged

Piers

Re: Saving a Sprite as a File
« Reply #1 on: April 16, 2006, 10:42:49 pm »
Could this work as a sprite ripping program?
Logged

shadow_caliber

Re: Saving a Sprite as a File
« Reply #2 on: April 16, 2006, 10:56:04 pm »
Only to rip sprites from your own gamemaker game =P
Logged

Goodnight

Once and future Captain
Re: Saving a Sprite as a File
« Reply #3 on: April 16, 2006, 11:15:45 pm »
  • With a Capital G
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 706
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.
Logged
Re: Saving a Sprite as a File
« Reply #4 on: April 17, 2006, 01:33:03 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1635
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.
« Last Edit: April 17, 2006, 01:42:55 am by Scooternew »
Logged
Re: Saving a Sprite as a File
« Reply #5 on: April 17, 2006, 08:38:52 am »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
Very good. This is very good indeed... I may use it as a Portait taker :D. Good work scooter.
Logged
the a o d c
Pages: [1]   Go Up

 


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



Page created in 0.164 seconds with 49 queries.