You are currently viewing the gmlscripts.pro static mirror. Forum access and script submissions are not available through this mirror.

Invert gmlscripts.pro

sprite_edit_begin

sprite_edig_begin

sprite_edit_begin(sprite)
Edit a sprite dynamically using drawing commands.
COPY/// sprite_edit_begin(sprite)
//
//  Edit a sprite dynamically using drawing commands. This script begins
//  an editing session and returns a session ID. All further drawing 
//  commands are directed to a surface holding a horizontal strip of frames
//  from a given sprite. A call to script sprite_edit_end() ends editing.
//
//      sprite      sprite to edit, real
//
//  Note: Blending mode is reset to normal after calling this script.
//
/// gmlscripts.pro/license
{
    var sprite,a,w,h,n,xoff,yoff,surface,i;
    sprite = argument0;
    a = draw_get_alpha();
    w = sprite_get_width(sprite);
    h = sprite_get_height(sprite);
    n = sprite_get_number(sprite);
    xoff = sprite_get_xoffset(sprite);
    yoff = sprite_get_yoffset(sprite);
    surface = surface_create(w*n,h);
    surface_set_target(surface);
    draw_clear_alpha(c_black,0);
    draw_set_blend_mode_ext(bm_one,bm_zero);
    draw_set_alpha(1);
    for(i=0; i<n; i+=1) {
        draw_sprite(sprite,i,i*w+xoff,yoff);
    }
    draw_set_blend_mode(bm_normal);
    draw_set_alpha(a);
    return (string(surface)+':'+string(sprite));
}
sprite_edit_end(session)
Ends a sprite editing session started with sprite_edit_begin().
COPY/// sprite_edit_end(session)
//
//  Ends a sprite editing session started with sprite_edit_begin().
//  At the end of a session, the original sprite is replaced with
//  a new version and the editing surface is freed.
//
//      session     editing session ID given by sprite_edit_begin(), real
//
/// gmlscripts.pro/license
{
    var session,p,surface,sprite,w,h,n,prec,tran,smth,load,xoff,yoff,temp,i;
    session = argument0        
    p = string_pos(':',session);
    surface = real(string_copy(session,1,p-1));
    sprite = real(string_copy(session,p+1,10));
    w = sprite_get_width(sprite);
    h = sprite_get_height(sprite);
    n = sprite_get_number(sprite);
    xoff = sprite_get_xoffset(sprite);
    yoff = sprite_get_yoffset(sprite);
    temp = sprite_create_from_surface(surface,0,0,w,h,false,false,xoff,yoff);
    for(i=1; i<n; i+=1) {
        sprite_add_from_surface(temp,surface,w*i,0,w,h,false,false);
    }
    sprite_assign(sprite,temp);
    sprite_delete(temp);
    surface_reset_target();
    surface_free(surface);
    return 0;
}

Contributors: Leif902, xot

GitHub: View · Commits · Blame · Raw