Jump to content


Photo

Turn all colored sprites into black and white


  • Please log in to reply
20 replies to this topic

#1 classicgamelover1985

classicgamelover1985

    GMC Member

  • GMC:Member
  • 195 posts
  • Version:Unknown

Posted 17 October 2011 - 10:25 PM

I have an options menu with a setting that allows the players to decide how they'd like the game to look. I have an option to have all graphics colorized or BLACK AND WHITE. But creating duplicates of the sprites just to make black and white ones creates clutter. I was wondering if there was any CODE that would automatically turn ALL SPRITES to that black and white contrast. The backgrounds too if possible. See I notice in the sprite editor that there is a black and white option under the "image" menu. Well if it can do that with a single sprite, I was thinking perhaps there was something that could do it for every level automatically if the setting was set that way. You all know what I mean? I hope I'm being descriptive enough for you all to understand... thanks!Also keep in mind I need to allow the sprites to CHANGE BACK to color if the player returns to the options menu and changes it back. Thanks.

Edited by classicgamelover1985, 17 October 2011 - 10:26 PM.


#2 loverock125

loverock125

    GMC Member

  • GMC Member
  • 1830 posts
  • Version:GM8.1

Posted 17 October 2011 - 11:52 PM

The only way I can think of is by checking every pixel on the screen and making changes which would cause a performance decrease.


Here's another topic that may be of help.
http://testgmc.yoyog...howtopic=467366

Edited by loverock125, 17 October 2011 - 11:53 PM.

  • 0

#3 classicgamelover1985

classicgamelover1985

    GMC Member

  • GMC:Member
  • 195 posts
  • Version:Unknown

Posted 18 October 2011 - 10:15 PM

no that's script that is WAY too complicated for me to figure out...

#4 epicpiedude

epicpiedude

    Artist/GameDeveloper

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

Posted 18 October 2011 - 10:19 PM

Well, you can create a folder called 'color' in your sprites. Then duplicate ALL the sprites, and make them all black and white. That might take too much memory, though.
  • 0

#5 classicgamelover1985

classicgamelover1985

    GMC Member

  • GMC:Member
  • 195 posts
  • Version:Unknown

Posted 19 October 2011 - 01:45 AM

Well, you can create a folder called 'color' in your sprites. Then duplicate ALL the sprites, and make them all black and white. That might take too much memory, though.


Yeah, this was my original plan, but like I said at the top, i was wondering if there was code that would switch everything to black and white, however, I also use check variable "sprite_index" in some areas, so doing this would create a bit of a complication as switching to a different sprite would cause bugs and errors in certain functions of the game. I was just hoping there was code.... man do I ever hope there's code that will do this instead. If not, then its going to be a WHOLE HECK OF A TON of work to get this set up! Actually the folder is called "black and white" where I store all the black and white sprites. Default setting will be for color. I don't know I kinda like black and white contrast too--sorta like game boy pocket--good ol retro style

Edited by classicgamelover1985, 19 October 2011 - 01:46 AM.


#6 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9322 posts
  • Version:Unknown

Posted 19 October 2011 - 02:09 AM

The only way to make things black-and-white through code is extremely slow (not quite as slow as per-pixel checking, but still slow). It involves generating new black-and-white sprites from the color ones, and creating new resources is a bit slow.

But if you really want to, then you could do the processing during a loading screen or something. It would be useful to use the map_sprites script so you can process all the sprites and save the black-and-white versions to useful variable names.

var spr_map, spr_name, spr, w, h, surf, temp;
spr_map=ds_map_create();
map_sprites(spr_map);

key=ds_map_find_first(spr_map);
while (is_string(key)) {
  spr = ds_map_find_value(spr_map, key);
  w = sprite_get_width(spr);
  h = sprite_get_height(spr);
  temp = sprite_duplicate(spr);
  sprite_set_alpha_from_sprite(temp, temp);

  surf = surface_create(w, h);
  surface_set_target(surf);
  draw_clear_alpha(c_white, 1);
  draw_set_blend_mode_ext(bm_zero, bm_src_alpha);
  draw_sprite(temp, 0, sprite_get_xoffset(temp), sprite_get_yoffset(temp));
  draw_set_blend_mode(bm_normal);

  sprite_delete(temp);
  temp = sprite_create_from_surface(surf, 0, 0, w, h, 0, 0, sprite_get_xoffset(spr), sprite_get_yoffset(spr));
  execute_string("globalvar "+key+"_bnw; "+key+"_bnw = temp");

  surface_free(surf);
  key = ds_map_find_next(spr_map, key);
}

That should make all your sprites (at least the first subimage of them) black-and-white and store them in globalvar variables with names identical to the original sprites' names followed by a _bnw (so a spr_stand would become spr_stand_bnw).

For multi-framed sprites, you'd do something similar but with a for() loop and sprite_add_from_surface() for every frame after the first.

It's very slow, but if you absolutely need it and can't pre-make your black-and-white sprites, it will get the job done.

-IMP
  • 0

#7 classicgamelover1985

classicgamelover1985

    GMC Member

  • GMC:Member
  • 195 posts
  • Version:Unknown

Posted 19 October 2011 - 02:24 AM

The only way to make things black-and-white through code is extremely slow (not quite as slow as per-pixel checking, but still slow). It involves generating new black-and-white sprites from the color ones, and creating new resources is a bit slow.

But if you really want to, then you could do the processing during a loading screen or something. It would be useful to use the map_sprites script so you can process all the sprites and save the black-and-white versions to useful variable names.

var spr_map, spr_name, spr, w, h, surf, temp;
spr_map=ds_map_create();
map_sprites(spr_map);

key=ds_map_find_first(spr_map);
while (is_string(key)) {
  spr = ds_map_find_value(spr_map, key);
  w = sprite_get_width(spr);
  h = sprite_get_height(spr);
  temp = sprite_duplicate(spr);
  sprite_set_alpha_from_sprite(temp, temp);

  surf = surface_create(w, h);
  surface_set_target(surf);
  draw_clear_alpha(c_white, 1);
  draw_set_blend_mode_ext(bm_zero, bm_src_alpha);
  draw_sprite(temp, 0, sprite_get_xoffset(temp), sprite_get_yoffset(temp));
  draw_set_blend_mode(bm_normal);

  sprite_delete(temp);
  temp = sprite_create_from_surface(surf, 0, 0, w, h, 0, 0, sprite_get_xoffset(spr), sprite_get_yoffset(spr));
  execute_string("globalvar "+key+"_bnw; "+key+"_bnw = temp");

  surface_free(surf);
  key = ds_map_find_next(spr_map, key);
}

That should make all your sprites (at least the first subimage of them) black-and-white and store them in globalvar variables with names identical to the original sprites' names followed by a _bnw (so a spr_stand would become spr_stand_bnw).

For multi-framed sprites, you'd do something similar but with a for() loop and sprite_add_from_surface() for every frame after the first.

It's very slow, but if you absolutely need it and can't pre-make your black-and-white sprites, it will get the job done.

-IMP



I'm going to give it a shot, but let me just say, this is beyond me! I'm not that good with code, but I'm fairly okay with it. I've got a little experience. I've just heard from many people on this site that code is the best way to go with game development. That code works better than those drag and drop icons. I'd like to learn it someday--fluently. Alright man, just let me know what I need to change if you don't mind taking the time in doing so. I got an error in "map_sprites(spr_map);" what is this for? Its the third line down. the error says line 3 position 2. unknown function or script map_sprite. I'm using game maker 8.1 by the way. Do I need to create a script too? How is the function wrong?Hmmm i'm not sure about this I really need to learn GML. Just as a second side-question, Any idea where there might be a tutorial or something out there to help inexperienced users like myself on how to learn GML?--that'd help allot! Thanks.

Edited by classicgamelover1985, 19 October 2011 - 02:33 AM.


#8 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9322 posts
  • Version:Unknown

Posted 19 October 2011 - 02:32 AM

I linked you to the script you'll need in the post. But here it is again: map_sprites . You need that script in your game for it to work.

-IMP
  • 0

#9 classicgamelover1985

classicgamelover1985

    GMC Member

  • GMC:Member
  • 195 posts
  • Version:Unknown

Posted 20 October 2011 - 01:09 AM

I linked you to the script you'll need in the post. But here it is again: map_sprites . You need that script in your game for it to work.

-IMP


OH!!! I didn't see the link, i'm sorry. Thanks. Well that's weird, even the script has an error. its this:

no = sprite_create_from_screen(0,0,1,1,false,false,false,false,0,0);

so what now? The bottom says "Wrong number of arguments or functions to script".

Edited by classicgamelover1985, 20 October 2011 - 01:15 AM.


#10 loverock125

loverock125

    GMC Member

  • GMC Member
  • 1830 posts
  • Version:GM8.1

Posted 20 October 2011 - 01:26 AM


I linked you to the script you'll need in the post. But here it is again: map_sprites . You need that script in your game for it to work.

-IMP


OH!!! I didn't see the link, i'm sorry. Thanks. Well that's weird, even the script has an error. its this:

no = sprite_create_from_screen(0,0,1,1,false,false,false,false,0,0);

so what now? The bottom says "Wrong number of arguments or functions to script".


It's because in gm8.1 they changed the arguments of the function. Try this:

sprite_create_from_screen(0,0,1,1,false,false,0,0);

  • 0

#11 classicgamelover1985

classicgamelover1985

    GMC Member

  • GMC:Member
  • 195 posts
  • Version:Unknown

Posted 20 October 2011 - 11:35 PM



I linked you to the script you'll need in the post. But here it is again: map_sprites . You need that script in your game for it to work.

-IMP


OH!!! I didn't see the link, i'm sorry. Thanks. Well that's weird, even the script has an error. its this:

no = sprite_create_from_screen(0,0,1,1,false,false,false, false,0,0);

so what now? The bottom says "Wrong number of arguments or functions to script".


It's because in gm8.1 they changed the arguments of the function. Try this:

sprite_create_from_screen(0,0,1,1,false,false,0,0);




map_sprites(spr_map);


Yet another error. This time its in the code. it says:

Error at line 3 pos 2 Unknown function or script: map_sprites

Now, I do have the script pasted and I named it "Black and White" so the script IS there. Any idea what else might be wrong? I feel like we're close though, I'm just really curious how this is going to look when its finished. I'll be very much appreciated of your response.

Edited by classicgamelover1985, 20 October 2011 - 11:38 PM.


#12 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9322 posts
  • Version:Unknown

Posted 21 October 2011 - 12:04 AM

You're supposed to name it "map_sprites" :lol: . If you call it "Black and White", then your game still doesn't know what map_sprites means...not to mention you can't have spaces in resource names anyway.

-IMP
  • 0

#13 classicgamelover1985

classicgamelover1985

    GMC Member

  • GMC:Member
  • 195 posts
  • Version:Unknown

Posted 21 October 2011 - 01:46 AM

You're supposed to name it "map_sprites" :lol: . If you call it "Black and White", then your game still doesn't know what map_sprites means...not to mention you can't have spaces in resource names anyway.

-IMP


lol yeah I admit it my game is a mess! I have some named with spaces, others have the _ in them to make the spaces. Some have same names, I can't back anything up cuz when I started, I HAD NO IDEA HOW ANYTHING WORKED!!! (Slap my forehead and say DER I should have known) Whoops! Too late now I already have a whole bunch done in the game to go back and rename everything. Oy. But anyways, I'm going to test it now, thanks.

Well everything else was a go, I clicked on the button to set the setting like I was hoping but yet another issue came up. How exactly DOES this code work and what is it suppose to do again? Am I missing something? Cuz the error I got was this:



___________________________________________
ERROR in
action number 3
of Step Event
for object setglobalvariables:

Trying to delete non-existing sprite.
____________________________________________

What does it mean by "Trying to DELETE non-existing sprite". Delete? I'm just not understanding this. I just started game maker 2 years ago, but have only become really good at drag and drop icons. Man, code is much more challenging though... thank you.

Well I looked back up at (I think) it was your first post. You said regenerating black and white ones with the color ones. I think I'm sort of understanding what you meant by that. Its making sense now. But still does this need to be placed into a different object? Do I have this in the wrong object? Should it be a step event? Or create event?

Edited by classicgamelover1985, 21 October 2011 - 01:55 AM.


#14 classicgamelover1985

classicgamelover1985

    GMC Member

  • GMC:Member
  • 195 posts
  • Version:Unknown

Posted 24 October 2011 - 09:50 PM

Still no reply, why not? I'm peddling up a creek without a paddle here. Can anyone else help me out here? This code that InfiniteIMPerfection provided, is anyone else familiar with it? I feel as though I'm real close here, but like i said in the post before this one, there is still yet another error. I did everything I was suppose to do as far as I know. And its been a little more than 48 hours after my reply. I still need help here though. Thanks.

#15 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9322 posts
  • Version:Unknown

Posted 25 October 2011 - 04:04 AM

It should definitely NOT be in the step event. It should be in some object's Game Start event, preferably a controller. This creates new copies of your sprites; doing this in the STEP event would try to double the amount of sprites your game has every 1/30 of a second! No wonder it ends up with that error; at some point (fairly quickly), your game just runs out of memory to make new sprites.

-IMP
  • 0

#16 classicgamelover1985

classicgamelover1985

    GMC Member

  • GMC:Member
  • 195 posts
  • Version:Unknown

Posted 25 October 2011 - 09:35 PM

It should definitely NOT be in the step event. It should be in some object's Game Start event, preferably a controller. This creates new copies of your sprites; doing this in the STEP event would try to double the amount of sprites your game has every 1/30 of a second! No wonder it ends up with that error; at some point (fairly quickly), your game just runs out of memory to make new sprites.

-IMP


Its funny, cuz in the past when I posted on forums, others always told me to put code in STEP event. So naturally, I've always thought this. This is the only code I have ever encountered that uses the create event. Thanks for clearing that up. Lets see what happens.

Well I tried it.
No error this time, this time absolutely nothing happened. Its a button a person presses while in the options menu. They press it, and doing so tells it to apply the code. I have in THE CREATE EVENT a test variable. The variable name is "graphics" if this variable is equal to 1 then its told to apply the code. See, pressing that button changes the variable to 1, cuz the variable starts at 0. See? I need it this way for the options to work right. I want it to be OPTIONAL to have all the graphics black and white if a player so chooses. I know I would choose this for fun, just to mix things up a bit and keep things somewhat new. Any more suggestions? Or is this idea totally trashed?

Tried a little test.
I took it outside the test variable of that create event and put it into its own object, its own create event of that object WITH NO TEST VARIABLE!! So it was the code by itself within that create event. I put the object into the main menu. and this error popped up saying:


___________________________________________
ERROR in
action number 1
of Create Event
for object Object_Black_And_White_Controller:

Trying to delete non-existing sprite.
___________________________________________

Notice the underscores? I took out all the spaces of all the objects, sprites, scripts, everything, and put underscores in instead. It IS okay to name the object this right? Object_Black_And_White_Controller is an okay name for this object right? Otherwise maybe its the name that's the problem. How the heck should I know???? Do I need to list the name of the sprite it needs to delete or something?

Edited by classicgamelover1985, 25 October 2011 - 09:59 PM.


#17 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9322 posts
  • Version:Unknown

Posted 25 October 2011 - 10:10 PM

That's an okay name. I don't know why it would be triggering that error; the only way would be if it's trying to duplicate a non-existent sprite, which shouldn't happen since it's taking its sprite indexes from the map created with map_sprites()...

However, the first time you used it (with the check) you said it worked, right? It doesn't automatically make everything black-and-white; it just creates black-and-white copies of all your sprites. You actually have to do something with those copies (i.e. set your objects to use those new sprites instead of the original, colorful sprites).

Like I said, it gives them names based on the original sprite names, so if some object uses a sprite called jump_spr, it would instead now need to use jump_spr_bnw as its sprite.

By the way, there's no specific event just for code. Anywhere you can put D&D you can put code (that is, code is just a more advanced version of D&D); so any event can have any code. Events just execute at different times, in different situations, so you put certain codes in different events because you only want that code to execute at certain times. The STEP events happen once every frame, so for a default room_speed of 30, they happen 30 times per second. You wouldn't want to create new sprites 30 times per second :) .

-IMP
  • 0

#18 classicgamelover1985

classicgamelover1985

    GMC Member

  • GMC:Member
  • 195 posts
  • Version:Unknown

Posted 25 October 2011 - 10:23 PM

So I must be doing something wrong. How do I do this then? This is really frustrating! All the sprites are in groups---would this trigger the issue? I have a group for all the player sprites, a group for all the wall sprites, a group for all the enemy sprites, and so on. And all I have to do is run the game right? And it will automatically create the sprites? How do I know when its done so I can return to the game editor and apply those sprites to objects? Also, it won't delete the color sprites will it? I want to use both. So many questions... Posted Image

spr_map appears BLACK in the code editor. Is this normal? Isn't it suppose to turn red or blue or purple to show that its recognized? Seems to me that game maker don't even know what this means.... I have two pictures I could share with you that shows the code exactly as it is in the code editor--one for the code that goes into the create event and another picture that shows the script for what it looks like. You want to see? Provide me your email I'll email them to you.Or maybe you could paste these into your own GMfile and see for yourself what's wrong. I'm sure something is up. If you don't mind, I really have need of your experience if you don't mind taking the time. Thank you very much.

Edited by classicgamelover1985, 25 October 2011 - 10:34 PM.


#19 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9322 posts
  • Version:Unknown

Posted 25 October 2011 - 10:39 PM

So I must be doing something wrong. How do I do this then? This is really frustrating! All the sprites are in groups---would this trigger the issue? I have a group for all the player sprites, a group for all the wall sprites, a group for all the enemy sprites, and so on. And all I have to do is run the game right? And it will automatically create the sprites? How do I know when its done so I can return to the game editor and apply those sprites to objects? Also, it won't delete the color sprites will it? I want to use both. So many questions... Posted Image

:lol: This creates the sprite at run-time. You won't be able to see or use the sprites in GM's editor. Once the script runs, when your game gets control again, all the sprites will have their duplicates in memory under the name scheme I mentioned. You have to set the sprites to the objects in GML or D&D, you can't use the normal object editor sprite field, since the black-and-white sprites don't exist when your game is not running.

spr_map appears BLACK in the code editor. Is this normal? Isn't it suppose to turn red or blue or purple to show that its recognized? Seems to me that game maker don't even know what this means.... I have two pictures I could share with you that shows the code exactly as it is in the code editor--one for the code that goes into the create event and another picture that shows the script for what it looks like. You want to see? Provide me your email I'll email them to you.Or maybe you could paste these into your own GMfile and see for yourself what's wrong. I'm sure something is up. If you don't mind, I really have need of your experience if you don't mind taking the time. Thank you very much.

It shouldn't be recognized at all. It's just a variable; I could call it superCaliVariableOfDeath and it would still work, but I thought I'd use a name that makes some kind of sense :lol: . GM only highlights resources, not variables.

-IMP
  • 0

#20 classicgamelover1985

classicgamelover1985

    GMC Member

  • GMC:Member
  • 195 posts
  • Version:Unknown

Posted 25 October 2011 - 10:54 PM

jump_spr_bnw is an example you provided. Um, I think I see where this is going, and holy crap on a stick is this going to be a headache for me to figure out. I think this might be a bit beyond my skills... So let me get this straight, I have to PRE-TELL it the names of the sprites to switch to, right? Every sprite and its new name? It'd probably be easier to use GML but i don't know. Gosh darn it, I suppose I might as well just manually create the sprites, geez-la-weez! You could explain this to me carving it into my skin with a rusted carving knife and I'd still never ever get it!!! Spell it out for me go ahead and just try it, its impossible!!! I have no choice but to manually create over 1000 sprites--son of a ^*&%*&%!!!! Oh boy. I really need to learn GML more fluently. On a scale of 1-10 my GML skill is probably a 2 or a 3? Maybe? Somewhere in there....I roll my eyes at this...


And just for the record since your the one who has this "READ THIS" option as your signature...

ERROR in
action number 1
of Step Event
for object Object_Drown:

Error in expression:Object_player.x
position 15: Unknown variable x

How in the world do I fix this then? WITHOUT that

TUVAZ
then this coordinates no longer works and I keep getting an error, see sometimes

TUVAZ
is a good thing. Cuz it takes the headache away. I suppose it IS tempting to use for this very reason. I already create a variable x and y but I thought those were already variables already made? Whatever, this is off topic though. anyways. So i'm going to re-tick the TUVAZ option and just get it out of my mind!!!! AAAAHHH I Hate all these errors!!!!!

Actually no, its still on topic cuz I'm talking about errors and maybe TUVAZ is causing this error with the map_sprite code... maybe... or not? I really can't say. Why exactly am I getting an error about x and y coordinates? Those use to work, but as the game got bigger, things started not working as well... I paid 40 dollars for this program and its got tons of issues--wish I would have only paid 25 dollars! That would have been more fair considering all the unnecessary issues i've been experiencing.

Edited by classicgamelover1985, 25 October 2011 - 11:50 PM.


#21 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9322 posts
  • Version:Unknown

Posted 25 October 2011 - 10:57 PM

jump_spr_bnw is an example you provided. Um, I think I see where this is going, and holy crap on a stick is this going to be a headache for me to figure out. I think this might be a bit beyond my skills... So let me get this straight, I have to PRE-TELL it the names of the sprites to switch to, right? Every sprite and its new name? It'd probably be easier to use GML but i don't know. Gosh darn it, I suppose I might as well just manually create the sprites, geez-la-weez! You could explain this to me carving it into my skin with a rusted carving knife and I'd still never ever get it!!! Spell it out for me go ahead and just try it, its impossible!!! I have no choice but to manually create over 1000 sprites--son of a ^*&%*&%!!!! Oh boy. I really need to learn GML more fluently. On a scale of 1-10 my GML skill is probably a 2 or a 3? Maybe? Somewhere in there....I roll my eyes at this...

Well, you're already pre-telling it the names when you create your original sprites. Like I said, the names will automatically be identical to the corresponding color sprites' names, just with a _bnw suffix added.

And yes, you'll have to change the sprites in code or in D&D (with the :GM028: action). How else is GM supposed to know you want to use the new sprites instead of the old ones? :P

-IMP
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users