Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problem with color picker thing. [SOLVED :D]  (Read 914 times)
0 Members and 1 Guest are viewing this topic.
Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Posted 2012-05-09 03:51:44 »

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.

Check out my website!
Offline jonjava

JGO Knight


Medals: 32



« Reply #1 - Posted 2012-05-09 11:31:34 »

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.

Offline Luckssmith

Junior Newbie


Medals: 1



« Reply #2 - Posted 2012-05-10 03:34:08 »

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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
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.
1  
2  
3  
4  
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.
Games published by our own members! Check 'em out!
Try the Free Demo of Revenge of the Titans
Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Reply #3 - Posted 2012-05-10 03:35:34 »

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

Check out my website!
Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Reply #4 - Posted 2012-05-15 01:43:51 »

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

Check out my website!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (77 views)
2013-05-17 21:29:12

alaslipknot (89 views)
2013-05-16 21:24:48

gouessej (119 views)
2013-05-16 00:53:38

gouessej (113 views)
2013-05-16 00:17:58

theagentd (126 views)
2013-05-15 15:01:13

theagentd (113 views)
2013-05-15 15:00:54

StreetDoggy (156 views)
2013-05-14 15:56:26

kutucuk (179 views)
2013-05-12 17:10:36

kutucuk (179 views)
2013-05-12 15:36:09

UnluckyDevil (186 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.105 seconds with 20 queries.