Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (623)
Games in Android Showcase (176)
games submitted by our members
Games in WIP (676)
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  
  Changing colors or adding things in an image while running.Is it possible?  (Read 1454 times)
0 Members and 1 Guest are viewing this topic.
« Posted 2006-03-28 23:51:36 »

Hey all,
Me and a friend are trying to make a game , him with his drawings and photoshop knowledge and me with my amateur programming.What a duo ^_^ .

So anyway to my question.We wanted to make a character who will .. let's say equip weapons .... or wear new clothes for example.We are talking for 2D platform look.At first I thought of making lots of images holding various weapons .. and being dressed in various armors/clothes ... then I realized how hard that would be cause all these would need to be animated for walking , crouching jumping(not needed but nice for effect).

So I got this problem ... how can I do this?Can I change things in an image while the program is running?Or should I just make many many images as I suggested above?

Thanks in advance for any tips/advice Smiley
Offline oNyx

JGO Coder

Medals: 2

pixels! :x

« Reply #1 - Posted 2006-03-29 00:09:52 »

a) Weapons

You draw the character and the weapons seperately.

b) Tinting

Use a mask for tinting the spritesheet (only required when changing the color). You can tint in realtime if you're using opengl.

弾幕 ☆ @mahonnaiseblog
Offline moogie

JGO Ninja

Medals: 16
Projects: 6
Exp: 10 years

Java games rock!

« Reply #2 - Posted 2006-03-29 00:18:37 »

If you are using java 2D:

It really depends on your source graphics as to the best way.

If your graphaics are full 24bit (32?) then you can use the setRGB() of the the Buffered Image which holds the graphic.

If your graphic is 8bit and uses a palette such as GIF or 8bit PNG then you would want to create a new Buffered Image using a IndexColorModel set to your new palette. (i am not sure you can direclty swap in a new IndexColorModel.

Java4k RIP 2014
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
« Reply #3 - Posted 2006-03-29 00:29:40 »

Not even 30 minutes passed and already 2 replies.I expected no less from this friendly community Smiley Thanks Guys!

But ( there is always this but :/ ) as I said I am completely new to this thing and there are some words you said with which I am not familiar with.Or maybe it is cause english is not my mother language and I just don't know these words ^_^

So .. what is tinting?And what do you mean by using a mask.Here I should also say that it is 2D platform game , no 3D nothing Smiley ,cause I saw the word openGl in there :p

As for you moogie , again I sound as noobish as I can sound .... what do you mean by source graphics?Do you mean the image I am using?All the images are .png   or .gif  images scanned and then fixed and shaded following some tutorials I saw linked in Java2D forums.   

Going to sleep now , it is 3:30 here in Greece , got university tomorrow morning :/  .I will check again in the morning Smiley .Thanks again for the fast replies.
Offline moogie

JGO Ninja

Medals: 16
Projects: 6
Exp: 10 years

Java games rock!

« Reply #4 - Posted 2006-03-29 00:59:52 »

Yes, the source graphics are the files which you load. i.e. man.gif, sword.png.

If these graphics are the full 16million colors i.e 24bit then you will have a harder time changing the colours of items as no doubt you will have shaded the parts of the image you want changed.

One way is to make a mask image for each of the graphics which is a map of the parts of the image you want differently coloured where each pixel determines how to modify a base colour. e.g.

Original      Mask          New
000111000     000000000     000111000
000111000     000000000     000111000
000050000     000010000     000030000
011656110     000212000     011434110
000060000     000020000     000040000
000080000     000040000     000060000
000909000     000505000     000707000
001000100     000000000     001000100
010000010     000000000     010000010

In the above example the base colour changed from 4 to 2. In a RGB image you would want to have a mask for each colour component (or store the mask as a RGB image itself)

for an 8bit image you need only make a new palette reflecting the new colours you want changed, however this will mean that these colours cannot be used in the graphic in areas which you do not want the colour changed. e.g. a graphic of a car and the tires are black but the body is black also and they are currenttly using the same pallette index. thus to change the the body colour to yellow would also change the tires to yellow. You will need to have the tires and the body use different palette indecies which may or may not have the same colour.

Java4k RIP 2014
Offline woogley
« Reply #5 - Posted 2006-03-29 01:24:02 »

if you want to change the color in real time, you could change the hue of the overall image by passing it through an RGBImageFilter

I did this once with a bouncing balls application. basically, it took this image:

Click to Play

and turned it into multi-colored balls by changing the hue of the image (which modifies the entire image around the color wheel)

I wrote this code a few years ago, so you'll have to excuse the amateurity of it Wink - knock yourself out Tongue
« Reply #6 - Posted 2006-03-29 09:51:58 »

Hm ... because I barely understand what you say .. is there any tutorial regarding this I could look.Thanks for the source code woogley Smiley
And when I say I barely understand I mean all those mask things and the rest.Which I suppose are basics to do with images .. but he he I think I need more studying at this Smiley
Offline woogley
« Reply #7 - Posted 2006-03-29 13:59:17 »

uhhmm you probably might want to get comfortable with BufferedImage - you two will be tight friends in this project.

czech out:
Offline cylab

JGO Wizard

Medals: 90

« Reply #8 - Posted 2006-03-29 15:02:35 »

You might want to look at several of these tutorials: How can I learn the basics of Java imaging?

Mathias - I Know What [you] Did Last Summer!
« Reply #9 - Posted 2006-03-29 16:14:28 »

Thanks for the tutorials people Smiley  I know how to use buffered image to an extent , (aka double buffering) but from there and on nothing else Smiley SOOOOO I hope I can improve with those tutorials Wink

Thanks a lot Smiley , study time ^_^
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

basil_ (41 views)
2015-09-30 17:04:40

shadowstryker (21 views)
2015-09-29 15:55:06

TheSpaceHedgehog (27 views)
2015-09-29 01:58:48

GamerC4 (50 views)
2015-09-24 21:10:38

GamerC4 (69 views)
2015-09-24 21:09:48

htuy (24 views)
2015-09-24 04:57:24

htuy (34 views)
2015-09-24 04:56:35

htuy (25 views)
2015-09-24 04:56:09

htuy (25 views)
2015-09-24 04:47:33

Roquen (63 views)
2015-09-21 12:54:28
Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
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!