Creating a new sprite from 1 image index of another sprite?

L

LukeJapanwalker

Guest
I am trying to create a new sprite from one of the image frames of another sprite using GML.
Is this possible?

something like this:

new_sprite=sprMonster.image_index(4);

this (if it was real code) would make a sprite from frame 4 of the Monster sprite animation
 
G

Gardevoir

Guest
try changing the sprite index when you reach a certain image_index
 

Tsa05

Member
Code:
var w = sprite_get_width(sprMonster);
var h = sprite_get_height(sprMonster);
var ox = sprite_get_xoffset(sprMonster);
var oy = sprite_get_yoffset(sprMonster);
var mySurface  = surface_create(w,h,sprMonster);
surface_set_target(mySurface);
draw_sprite(sprMonster, 4, 0,0);
new_sprite = sprite_create_from_surface(mySurface, 0,0, w, h, 0, 0, ox, oy);
surface_reset_target();
surface_free(mySurface);
It's possible to create a drawing surface, to draw subimage 4 of the sprite to the surface, and to save the surface as a sprite.

But why not just draw the sprite at subimage 4 whenever you need that still-image?
 
L

LukeJapanwalker

Guest
Thank you everyone for your help.
I will try your kind suggestions and let you know how it goes.

I should have mentioned it in my post but the main reason I need a new sprite is because I'm using the "sprite_replace_color" script from GMLScripts and the thing tries to change the colors of all of the frames and I have about 100 so it is very slow.
That is why I wanted a new sprite with a single frame to speed up the color replacing process.
 

NightFrost

Member
The main issue with that is how a new texture page is created every time you define a new sprite. A better solution, I think, would be to use the existing sprite's subimage and use a shader to change a color in draw event.
 
Top