Problem with color picker thing. [SOLVED :D]

So, in the tile based game I am working on, I wanted to make my sprites have 4 gray scale colors, and then have each tile or entity set the colors when the object is created. I then load the colors and set the pixels to reflect what entity is being drawn. I am doing this so that I can have multiple monsters use the same art, but just change the color. I also just wanted to see if I could do it.

As it turns out, everything was working perfectly, until I tried to make the zombie use the same art as the player, but with different colors. When I start the game with the zombies using the same art, it will not appear at all for the zombies (the zombies only have one image, while the player has a whole walk cycle) and when the player gets to that image in his walk cycle, it doesn’t show up at all, and looks like he is temporarily invisible.

I can’t pinpoint what is making this happen, so I am asking you guys for a bit of help. I will enclose a link to a .zip that contains two .jars (one without zombies that works and one with zombies that doesn’t work) and my eclipse work space with source.

I also should note that everything was rendering properly before I tried this out.

The only source files that should be needed are Zombie.java, Entity.java, Screen.java, Level.java, and maybe Player.java.

Thanks so much,

-Nathan

Download files here.

Intentional medal there…

I haven’t looked at the code (lazy), could you post some of the relevant drawing code?

What you want to do is get the pixels from the grey scale image and before drawing them adjust the colours.

I think the zombies and the first image of the player walk cycle don’t appear because you are setting it to invisible colors in your zombie class:

public Zombie(int x, int y) {
		super(x, y, 0, 3);
		newWaitTime();
		
		cols[0] = 255;
		cols[1] = 50;
		cols[2] = 100;
		cols[3] = 150;
	}

Change that to something like this and your zombies and player should appear.

cols[0] = 0xff000000;
cols[1] = 0xff000065;
cols[2] = 0xff705200;
cols[3] = 0xffD35100;

However since you are always using the same source image ( sheet.sprites ), the first draw2(…) call will overwrite the grey scale pixels permanently making your check for the grey colors useless. That’s why the first image of the players walk cycle disappeared when you added the zombies.

Ah, thanks.

Is there anyway to do this without overwriting the pixels on the actual image? I know this can be done, but I have no idea how.

-Nathan

Never mind, I fixed it.

When I compare the image that it has loaded to the default colors, since it sets the image to the colors of the last image it used, I simply change the colors it is comparing against to the ones it just got done setting the image to.

Thanks for the help.

-Nathan