Replace a Specific Color (In-Game)
#1
Posted 26 May 2012 - 04:36 AM
#2
Posted 26 May 2012 - 03:31 PM
draw_sprite_ext(spr_object,-1,x,y,image_xscale,image_yscale,0,current_color,1) //draw_sprite_ext(sprite,subimg,x,y,xscale,yscale,rot,color,alpha) //curent_color is a variable that the player can adjust.
But to use this function you have to have PRO
#3
Posted 26 May 2012 - 04:26 PM
Combine that with a mask (white in the regions you want to color, clear elsewhere) to get the effect you want.how 'bout using the draw_sprite_ext?
#4
Posted 26 May 2012 - 06:21 PM
Combine that with a mask (white in the regions you want to color, clear elsewhere) to get the effect you want.
how 'bout using the draw_sprite_ext?
Yeah that's what I was hoping to avoid though.. having to make a mask for every peice of armor in the game..
#5
Posted 30 May 2012 - 12:36 AM
Combine that with a mask (white in the regions you want to color, clear elsewhere) to get the effect you want.
how 'bout using the draw_sprite_ext?
Yeah that's what I was hoping to avoid though.. having to make a mask for every peice of armor in the game..
You can do that automatically with the transparent color feature of backgrounds and sprites, but that feature is no longer supported in gm8, I guess. You can still do something with blending, though. But I do not know how you can transfer information from one color channel to another. If you cannot do that, then you need to reserve values for each color channel to be replaced by the team color. The easiest is to reserve zero for each color channel.
Then you use black as the team color when designing the sprites. You cannot use black any more anywhere else in the sprite, but the darkest gray will do too. Now if you draw the sprite onto a black surface with extended blend mode (bm_one, bm_one), and next draw the surface eight times onto itself with the same extended blend mode, then the surface is black where you need to replace the color and white everywhere else. That surface can be used to make the team color sprite as follows. First, make a second surface and use draw_clear_alpha (team_color,0) on it. Next, draw the first surface with blend mode bm_subtract and the sprite with extended blend mode (bm_one, bm_one) on the second surface. At last, make a new sprite of the surface.
#6
Posted 30 May 2012 - 06:48 PM
I want to allow players to change the color of certain parts of a sprite. I know I could layer just that part of the sprite ontop of the original sprite, and just image_blend it, but does anyone know of an easier way (an extension perhaps) that will change every pixel of a specific color on a sprite to another color?
Couldn't you just use a surface? I would assume you're using pro/standard or something, and if so, surfaces are usable-you can draw dots on a surface, and as long as you don't clear the surface, it will look as though it's just a sprite that can dynamically change-just clear the surface and redraw the sprite to reset it.
#7
Posted 30 May 2012 - 11:49 PM
(it was called "sprite_replace_color")
/*
** Usage:
** sprite_replace_color(sprite,oldcolor,newcolor)
**
** Arguments:
** sprite sprite to change
** oldcolor color that will be replaced
** newcolor color used as replacement
**
** Returns:
** (-1) on error
**
** Notes:
** This script replaces one color in a sprite with another.
** No new sprites are created, the given sprite is changed.
**
** GMLscripts.com
*/
{
var sprite, oldc, newc;
sprite = argument0;
oldc = argument1;
newc = argument2;
var w, h, n, i, xo, yo, surf, tempsprite, newsprite, alphasprite;
w = sprite_get_width(sprite);
h = sprite_get_height(sprite);
n = sprite_get_number(sprite);
xo = sprite_get_xoffset(sprite);
yo = sprite_get_yoffset(sprite);
surf = surface_create(w,h+1);
surface_set_target(surf);
for(i=0; i<n; i+=1) {
draw_clear_alpha(c_black,1);
draw_set_blend_mode_ext(bm_inv_dest_color,bm_one);
draw_sprite(sprite,i,xo,yo);
draw_set_blend_mode(bm_normal);
draw_point_color(0,h,oldc);
tempsprite = sprite_create_from_surface(surf,0,0,w,h+1,true,false,xo,yo);
draw_clear_alpha(newc,1);
draw_sprite(tempsprite,0,xo,yo);
sprite_delete(tempsprite);
if (i == 0) {
newsprite = sprite_create_from_surface(surf,0,0,w,h,false,false,xo,yo);
if (newsprite < 0) return -1;
}else{
sprite_add_from_surface(newsprite,surf,0,0,w,h,false,false);
}
draw_clear_alpha(c_white,1);
draw_set_blend_mode_ext(bm_zero,bm_src_alpha);
draw_sprite(sprite,i,xo,yo);
if (i == 0) {
alphasprite = sprite_create_from_surface(surf,0,0,w,h,false,false,xo,yo);
if (alphasprite < 0) {
sprite_delete(newsprite);
return -1;
}
}else{
sprite_add_from_surface(alphasprite,surf,0,0,w,h,false,false);
}
draw_set_blend_mode(bm_normal);
}
surface_reset_target();
sprite_assign(sprite,newsprite);
sprite_set_alpha_from_sprite(sprite,alphasprite);
sprite_delete(newsprite);
sprite_delete(alphasprite);
surface_free(surf);
}
#8
Posted 31 May 2012 - 03:15 PM
EDIT: there are incompatibilities, but they have nothing to do with the transparent color feature, and the blending scripts in the first link of my signature have been converted to gm8.
Edited by brac37, 05 June 2012 - 06:50 PM.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











