Jump to content


Photo

Layering a Sprite in game (as in merging 2 sprite)


  • Please log in to reply
5 replies to this topic

#1 wakeskater_X

wakeskater_X

    GMC Member

  • GMC Member
  • 448 posts

Posted 06 July 2012 - 08:41 AM

So... What I am trying to do is take an in game sprite base for my player and make a new sprite by applying overlays if you will to the base sprite.

Basically if you have certain items it will change the sprite by adding different elements to the player. At first I thought sprite_merge would do this, but it seems that just tacks on the new sprites to the end of the first one.

What I want is something that will take my sprite and merge it OVER the old sprite, so like: I have 15 images for my player. I have 15 images in the exact location I need for a hat to sit on the players head in each sprite. What I want to do is MERGE the hat sprite on TOP of the base player sprite to make a new layered sprite for in game use.

this is what I had tried (in my Draw event):

var spr_merged;
if (suit)
{
  spr_merged = sprite_merge(playerSpriteBase, playerSpriteSuit);
}
if (!suit)
{
  spr_merged = playerSpriteBase;
}

but that doesn't work... in fact it bugs out so much that it turns my player into a completely different sprite all together.

If anyone knows a way to do this please let me know :( or I'll have to just make sprites for all the possibilities of items (which is doable in this case), but I'd rather figure this out the easy more efficient way.

edit: posted this in advanced because I don't think there is going to be a simple answer for this.

Edited by wakeskater_X, 06 July 2012 - 08:48 AM.

  • 0

#2 Jack Indie Box

Jack Indie Box

    GMC Member

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

Posted 06 July 2012 - 09:59 AM

just draw another image... draw_sprite or draw_sprite_ext in a draw event. the order you draw them is from back to front, so the 2nd thing you draw goes ontop of the first

if you dont already know, if you draw in the draw event it turns off the automatic drawing of the object, so you should use draw_self() or manually draw the sprite using its x,y and such
  • 0

#3 wakeskater_X

wakeskater_X

    GMC Member

  • GMC Member
  • 448 posts

Posted 06 July 2012 - 10:14 AM

hmm... that's not a bad idea i guess. Yeah I just use the draw event to draw the player sprite how I want it anyway. That way I have a little more control.

But there is no way to edit and layer the actual sprite in the game huh?

I guess I'd probably have to build an external editor.

Thanks, I didn't think about doing it that way just calling multiple draw events, I suppose that'd work for now :)
  • 0

#4 Jack Indie Box

Jack Indie Box

    GMC Member

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

Posted 06 July 2012 - 10:26 AM

if you want a specific depth. then draw it in a specific object, with a specific depth. the draw order of objects is specific to the depth of the object.

or manually code it to draw them to a surface in a specific order. or handle all drawing from one control object that decides the order
  • 0

#5 dannyjenn

dannyjenn

    GMC Member

  • GMC Member
  • 2061 posts
  • Version:Mac

Posted 06 July 2012 - 12:26 PM

Just draw each on top of each other in the right order... it's the easiest way and usually the best way

If you want them all combined into a single sprite for whatever reason, there are 2 functions: sprite_create_from_screen() and sprite_add_from_screen() (or you could use sprite_create_from_surface() and sprite_add_from_surface()). You'll still need to draw all your sprites on top of each other in the right order, but you'd only need to do it once and then it makes a new sprite out of it which you can use like any other sprite.
  • 0

#6 Jack Indie Box

Jack Indie Box

    GMC Member

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

Posted 06 July 2012 - 12:32 PM

problem being he wants them animated. so drawing them to a surface and such would be alot of pointless work to do it 15 times in one go
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users