Jump to content


Photo

drawing a multi-sprite object's image to a surface


  • Please log in to reply
3 replies to this topic

#1 esco

esco

    GMC Member

  • GMC Member
  • 209 posts

Posted 29 March 2012 - 08:02 AM

Hello everyone, I have a question that I have been messing around with for hours now, yet I cannot figure out how to get it to work correctly.

My issues is that I am trying to make "trails" behind the player object that look EXACTLY like the player object's current image. The issue is that my player object uses SEVERAL sprites (a different one for each piece like a leg, arm, head, etc.), all of which are drawn in the draw event. So obviously creating a trail that just uses player.image_index only results in one piece of the object being drawn.

How can I fix this so that the trail looks EXACTLY like the player object's current image? I thought of using a surface, but I couldn't figure out how to get it to work right with this issue.

I would be happy to REP anyone who solves this issue with me. :thumbsup:

Edited by esco, 29 March 2012 - 08:02 AM.

  • 0

#2 AndrewBGM

AndrewBGM

    GMC Member

  • GMC Member
  • 199 posts
  • Version:GM:Studio

Posted 29 March 2012 - 10:38 AM

If you're already drawing everything in the Draw Event, just a little bit of smart copy and pasting will do the trick.

/* This should go before drawing the actual body parts */
var dir, i, xx, yy;
dir = point_direction( x, y, xprevious, yprevious);
for( i = 0;i < 3;i += 1) {
    xx = lengthdir_x( 2 * i, dir);
    yy = lengthdir_y( 2 * i, dir);
    draw_sprite_ext( spr_head, .., headX + xx, headY + yy, 1, 1, 0, -1, ( i / 3));
    draw_sprite_ext( spr_torso, .., torsoX + xx, torsoY + yy, 1, 1, 0, -1, ( i / 3));
    /* etc, etc */
}
Basically what this is doing is calculating the direction you are going and then drawing all the images necessary to make up the full body in that direction, also making it fade. The only issue with this is that when your direction changes, the trail will update as such and won't look as smooth, but it all depends on the scale of the sprites, etc. It's easy to work around but it takes more code than this.

If this doesn't fit your needs I'll gladly make an example of a much smoother one, well, without the body parts but the idea behind it is the same.

I hope this helps!

Edited by AndrewBGM, 29 March 2012 - 10:38 AM.

  • 1

#3 esco

esco

    GMC Member

  • GMC Member
  • 209 posts

Posted 30 March 2012 - 12:12 AM

Thanks for the help Andrew, but unfortunately this doesn't really help me. Probably because I did such a LOUSY job of explaining what I need above, lol. Let me try again: in the draw event of my player object, when he turns into a wolf, it draws several pieces for it, in addition to the player object's sprite index (the front leg). Now these rotate upward or downward as the player walks up and down slopes and adjust their positioning so that everything stays aligned. To give you examples of what I mean:

on a flat surface:
Posted Image

on a downward slope:
Posted Image

This in itself took some serious code work which is why I didn't paste it here. Now I can easily draw this to a surface by simply taking the code from the draw event, and pasting it into a step event. After doing this the surface has all of the pieces "glued" together properly and looks perfect like the above pic. I then simply copy the surface to the TRAILS object, and draw it there. Resulting in it draw the correct frame of animation, with the write alpha, color, etc.

The issue is this though: when I draw the surface I cannot get it to position properly in reference to the player. In order to get it to even show I have to use a 256x256 surface. If I use 64x64 (what I should use for this) I have to go to the upper left corner of the room and jump and then I can see a piece of the sprite on the surface appear. With a 256x256 surface (WAY too big) I get this:

Posted Image

And if I move forward and downward it seems to get further and further away QUICKLY like this:

Posted Image

Can anyone please assist me with getting this surface to position properly? I assume it is the way I am drawing the sprites to the surface that they just get drawn god knows where on it.

BTW, here is the code to draw just ONE piece of the wolf shown above. This is again in the draw event of the player object, and to draw it in the surface I just go into step event of the player object, then set the surface as the drawing target, and paste in the same code:

draw_sprite_ext(aluwolf_sword,0,x+128+lengthdir_x(point_distance(0,0,-6*hitbox.spr_dir,6+wolf_body_yoffset),image_angle+point_direction(0,0,-6*hitbox.spr_dir,6+wolf_body_yoffset)),y+128+lengthdir_y(point_distance(0,0,-6*hitbox.spr_dir,6+wolf_body_yoffset),image_angle+point_direction(0,0,-6*hitbox.spr_dir,6+wolf_body_yoffset)),hitbox.spr_dir,1,image_angle,image_blend,image_alpha);

And here is the code for the "trail" OBJECT'S draw event:

draw_surface_ext(my_trail, x, y, 1, 1, 0, c_white, image_alpha);

Edited by esco, 30 March 2012 - 12:20 AM.

  • 0

#4 AndrewBGM

AndrewBGM

    GMC Member

  • GMC Member
  • 199 posts
  • Version:GM:Studio

Posted 30 March 2012 - 05:23 PM

Okay yea I thought you were talking about something else, but I know what you're talking about now.

The only thing I can think of is where you are drawing the surface. You showed code that is drawing the surface at the objects x:y, but where is this object? Remember when rendering to a surface, the 0:0 coordinate is set to the top left of the surface, and if you don't draw the surface at 0:0 in the room, you may not get what you want.

I'm sorry if I haven't been much help, I've just never had an issue like this.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users