Using draw_sprite funcs instead of sprite_index seperating sprite parts

I

Ian

Guest
I was just wondering has anybody used draw_sprite functions instead of just using sprite index.

For example you have one whole sprite character:


Then you split it differentiating the torso and up up from legs:


And then use draw_sprite(); functions for them in my case using it for reload animations. So if the player is running and reloads it can do that because the legs act separate from the torso therefore the image index of the reload anim wont be restricted from the running images

Hopefully that makes sense and just wanted to know the experience people had with it and if there are any problems, I wouldnt want something like the torsos x pos to fall behind legs.
 

FrostyCat

Redemption Seeker
You just aren't drawing it at the right offsets, that's all there is to your problem.

Either change the position you draw at, or change the origin of the sprite you draw.
 
I

Ian

Guest
You just aren't drawing it at the right offsets, that's all there is to your problem.

Either change the position you draw at, or change the origin of the sprite you draw.
Wasnt a problem, just wandering peoples experience with it before i slice my sprites
 

FrostyCat

Redemption Seeker
The most important thing to keep in mind while slicing sprites is maintaining the same relative positioning and basis position among the pieces.

For simple slicing borders such as your example, one viable technique is to duplicate the sprite directly to maintain the origin point, then erase the top from one and the bottom from the other. If you intend to rotate or stretch the sprite, always leave a small buffer strip at the seam to prevent rounding errors from adding a visible gap to your result.

Sometimes the slicing requires a change of origin, such as swinging arms or weapons. In that case, you should set the origin to the pivot point you'll use most often (e.g. shoulder joint for an arm). Then get out a piece of paper and sketch out where it should be drawn relative to the main body's origin, then figure out an expression for that offset based on your sketch. This needs to be planned in advance or it'll come apart every time.
 
I

Ian

Guest
Thanks for the advice man, makes sense.


Since all characters kinda 'jump' while running was thinking for the leg sprite sheet simply cut the torso+ out and then with the torso+ just one image with a variable to control the y-pos when running. This cleared some things up with me.
 
I

Ian

Guest
The most important thing to keep in mind while slicing sprites is maintaining the same relative positioning and basis position among the pieces.

For simple slicing borders such as your example, one viable technique is to duplicate the sprite directly to maintain the origin point, then erase the top from one and the bottom from the other. If you intend to rotate or stretch the sprite, always leave a small buffer strip at the seam to prevent rounding errors from adding a visible gap to your result.

Sometimes the slicing requires a change of origin, such as swinging arms or weapons. In that case, you should set the origin to the pivot point you'll use most often (e.g. shoulder joint for an arm). Then get out a piece of paper and sketch out where it should be drawn relative to the main body's origin, then figure out an expression for that offset based on your sketch. This needs to be planned in advance or it'll come apart every time.
So the logic that ive came up with is kinda extensive.
I have 2 of each variables for more control: (sprite1 = torso+head | sprite2 = legs)
sprite1/2 = contains current sprite
sprite1/2_image = contains sub-image
sprite1/2_speed = image speed

I did that instead of using image index (-1) as the sub-image argument in draw_sprite_ext() because i would be restricted by the sprite_index's number of frames since image_index runs through the amount of frames of the sprite_index's sprite.

The code:
Code:
///Create Event

sprite1 = spr_assassin_idle1;
sprite1_image = 0;
sprite1_speed = .3;
sprite1_x = 0;

sprite2 = spr_assassin_idle2;
sprite2_image = 0;
sprite2_speed = .3;
sprite2_x = 0;
Code:
///End Step Event

sprite1_image += sprite1_speed;
sprite2_image += sprite2_speed;

//Resets the sub image so it loops instead of increment each step
if(sprite1_image > sprite_get_number(sprite1)-1) sprite1_image = 0;
if(sprite2_image > sprite_get_number(sprite2)-1) sprite2_image = 0;

//Rounds the legs sub-image
var round_sprite2 = floor(sprite2_image);

//If the legs are running, swicth through each image of that sprite and apply the y-offsets for sprite1
if (sprite2 = spr_assassin_run2) {
    switch (round_sprite2) {
        case 0: sprite1_y = 3;
                break;
        case 1: sprite1_y = 2;
                break;
        case 2: sprite1_y = -1;
                break;
        case 3: sprite1_y = -1;
                break;
        case 4: sprite1_y = 1;
                break;
        case 5: sprite1_y = 1;
                break;
        case 6: sprite1_y = 3;
                break;
        case 7: sprite1_y = 4;
                break;
        case 8: sprite1_y = -2;
                break;
        case 9: sprite1_y = -1;
                break;
        case 10: sprite1_y = 0;
                break;
        case 11: sprite1_y = 0;
                break;
        default: sprite1_y = 3;
    }
} else {
    sprite1_y = 0;
}
Code:
///Draw Event

draw_set_alpha(1);

if(sprite1 != -1)draw_sprite_ext( sprite1, sprite1_image, x, y+sprite1_y, image_xscale, 1, image_angle, c_white, 1 );

if(sprite2 != -1)draw_sprite_ext( sprite2, sprite2_image, x, y, image_xscale, 1, image_angle, c_white, 1 );
so while running the sprite1 sprite is only has 1 sub image while legs has 12 and so i went through and got the pixel offsets of each sub image of sprite2 of sprite1's sub image:


Not sure how exact i was on the offsets but is this an acceptable method of doing it? any more advice?
 

Alvare

Member
Oh wow. Never knew I could do that. :eek:
I always use +cos(walk). But it'll get out of sync. While this one stays perfectly in sync. I wouldn't know of a better way than this.
Now you could also add in a footstep sound on one of the offset changes.
 
I

Ian

Guest
Oh wow. Never knew I could do that. :eek:
I always use +cos(walk). But it'll get out of sync. While this one stays perfectly in sync. I wouldn't know of a better way than this.
Now you could also add in a footstep sound on one of the offset changes.
well as this works it needs a better way of tracking the subimage while applying the y-offset
(Paused at a certain point to illustrate):

(sprite1 [torso] was still in the offset set for sprite2's sub image prior to this one)
The offsets dont apply right when the subimage switch but maybe like 1ms later (very slightly). Maybe moving some code in different End/Begin events might help match the offsets with the subimage

Any thoughts?
 
I

Ian

Guest
Fixed it lol Since i was prototyping my code order was whack.
Declaring the variable 'round_sprite2' via create event & applying it after the subimages to their speed:
Code:
sprite1_image += sprite1_speed;
sprite2_image += sprite2_speed;

round_sprite2 = floor(sprite2_image);
 
Top