Jump to content


Photo

Palette swapping with an array?

gm:studio

  • Please log in to reply
4 replies to this topic

#1 Evilperson

Evilperson

    GMC Member

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

Posted 27 March 2016 - 06:45 PM

I'm trying to make a palette swapping system in my game.

In obj_palette I have made the array global.palette_colour[ *palette number*, *corresponding object colour* ]  like so:

//CREATE EVENT
global.palette = 0

global.palette_colour[0,0] = make_colour_rgb(46,53,50)
global.palette_colour[0,1] = make_colour_rgb(139,38,53)
global.palette_colour[0,2] = make_colour_rgb(139,38,53)
global.palette_colour[0,3] = make_colour_rgb(46,53,50)
global.palette_colour[0,4] = make_colour_rgb(139,38,53)
global.palette_colour[0,5] = make_colour_rgb(46,53,50)
global.palette_colour[0,6] = make_colour_rgb(210,212,200)

and

//DRAW EVENT
if instance_exists(obj_player){with obj_player{draw_sprite_ext(spr_head,0,x,y,1,1,direction,global.palette_colour[global.palette,0],1)}}

if instance_exists(obj_tail){with obj_tail{draw_sprite_ext(spr_tail,0,x,y,1,1,direction,global.palette_colour[global.palette,1],1)}}

if instance_exists(obj_small_debris){with obj_small_debris{draw_sprite_ext(spr_small_debris,0,x,y,1,1,direction,global.palette_colour[global.palette,2],1)}}

if instance_exists(obj_pellet){with obj_pellet{draw_sprite_ext(spr_pellet,0,x,y,1,1,direction,global.palette_colour[global.palette,3],1)}}

if instance_exists(obj_debris){with obj_debris{draw_sprite_ext(spr_debris,0,x,y,1,1,direction,global.palette_colour[global.palette,4],1)}}

if instance_exists(obj_wall){with obj_wall{draw_sprite_ext(spr_wall,0,x,y,1,1,direction,global.palette_colour[global.palette,5],1)}}

if instance_exists(obj_background){with obj_background{draw_sprite_ext(bg_purple,0,x,y,1,1,direction,global.palette_colour[global.palette,6],1)}}

The sprites for the objects are gray by default.

In the game, obj_wall is the only object which changes colour and not even the right colour.

Is there anything wrong with my code? 

 


  • 0

#2 flyingsaucerinvasion

flyingsaucerinvasion

    GMC Member

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

Posted 27 March 2016 - 08:02 PM

you don't need the instance_exists statement at all here, the with statement will only deal with instances that actually exist.

 

What color does the wall change to, and what color is it supposed to change to?  According to the code you posted, the wall should be blended with a dark grey, slightly greenish-teal color.


Edited by flyingsaucerinvasion, 27 March 2016 - 08:03 PM.

  • 0

#3 Evilperson

Evilperson

    GMC Member

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

Posted 27 March 2016 - 08:35 PM

you don't need the instance_exists statement at all here, the with statement will only deal with instances that actually exist.

 

What color does the wall change to, and what color is it supposed to change to?  According to the code you posted, the wall should be blended with a dark grey, slightly greenish-teal color.

Actually, I just noticed, obj_wall is the only one that doesn't change, and remains with the default sprite (128,128,128 RGB).

All other objects change to the colour 107,107,100 RGB.


Edited by Evilperson, 27 March 2016 - 08:35 PM.

  • 0

#4 flyingsaucerinvasion

flyingsaucerinvasion

    GMC Member

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

Posted 27 March 2016 - 08:43 PM

Huh.... what are thier original colors? 

Also, you know you can set the blend color of individual instances, right?

    image_blend = some_color;

 

that way you don't have to add any drawing code, you could just have the instances draw themselves.

 

Also, you probably are already aware that when you have a blending color, it is multiplying the original color by the blend color.  In other words:

new_color = col1 * col2 / 255


Edited by flyingsaucerinvasion, 27 March 2016 - 08:44 PM.

  • 1

#5 Evilperson

Evilperson

    GMC Member

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

Posted 28 March 2016 - 10:28 PM

Thanks! I didn't know about about image_blend.

I implemented it like this

//Step Event
with obj_player{image_blend = global.palette_colour[global.palette,0]}

with obj_tail{image_blend = global.palette_colour[global.palette,1]}

with obj_small_debris{image_blend = global.palette_colour[global.palette,2]}

with obj_pellet{image_blend = global.palette_colour[global.palette,3]}

with obj_debris{image_blend = global.palette_colour[global.palette,4]}

with obj_wall{image_blend = global.palette_colour[global.palette,5]}

with obj_background{image_blend = global.palette_colour[global.palette,6]}

and it works now.

Huge thanks!


Edited by Evilperson, 28 March 2016 - 10:28 PM.

  • 0





Also tagged with one or more of these keywords: gm:studio