Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
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  
  [solved] How to get gradients do their job  (Read 349 times)
0 Members and 1 Guest are viewing this topic.
Offline Sethir

Senior Newbie


Exp: 3 years



« Posted 2013-07-22 12:46:03 »

Hey guys,
I try to create a final fantasy 7-ish combat without any library, I want to make a game from scratch before I use any of them.
My problem lies in the gradient. I want something like that:


But in the end it looks like:


They don't look that diferent but the problem is, there are two bars (one for the player and one for the enemy/npc). The second bar doesn't get any gradient at all:


Here is the code of the paint class:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
int barWidth = 220;
int barHeight = 30;
int barInitiativeHeight = 6;
   
Graphics2D g2 = (Graphics2D) g;
     
// Background Color new Color(73,73,73)
// Border Color new Color(91,91,91)
     
     
g2.setColor(new Color(73,73,73));
g2.fillRect(63, 450, barWidth-1, barHeight-1);//Stam Player
g2.fillRect(523, 450, barWidth-1, barHeight-1);
g2.setColor(new Color(91,91,91));
g2.drawRect(62, 449, barWidth, barHeight);//Stam
g2.drawRect(522, 449, barWidth, barHeight);


//Stamina Color TODO: Gradient -> dark 234;158;15   light 251;181;15
g2.setPaint(new GradientPaint(0,0,new Color(234, 158,15),100, 0,new Color(251,181,15)));
g2.fillRect(63, 450, (int) (barWidth*(player.getCharacters().get(0).getStamina()/(float)player.getCharacters().get(0).getMaxStamina())-1), barHeight-1);
g2.setPaint(new GradientPaint(0,0,new Color(251,181,15),100, 0,new Color(234, 158,15)));
g2.fillRect(523+(barWidth-(int)(barWidth*(enemies.get(0).getStamina()/(float)enemies.get(0).getMaxStamina()))), 450, (int) (barWidth*(enemies.get(0).getStamina()/(float)enemies.get(0).getMaxStamina())-1), barHeight-1);//HP
     
g2.setColor(new Color(73,73,73));
g2.fillRect(26, 434, barWidth-1, barHeight-1);//HP
g2.fillRect(63, 482, barWidth-1, barInitiativeHeight-1);//Init
     
g2.fillRect(558, 434, barWidth-1, barHeight-1);//HP
g2.fillRect(523, 482, barWidth-1, barInitiativeHeight-1);//Init
     
g2.setColor(new Color(91,91,91));
g2.drawRect(25, 433, barWidth, barHeight);//HP
g2.drawRect(62, 481, barWidth, barInitiativeHeight);//Init
 
g2.drawRect(557, 433, barWidth, barHeight);//HP
g2.drawRect(522, 481, barWidth, barInitiativeHeight);//Init
           
//HealthPoint Color TODO: Gradient -> dark 17,118,0      light 57,160,40
g2.setPaint(new GradientPaint(0,0,new Color(17,118,0),100, 0,new Color(57,160,40)));
g2.fillRect(25, 433, (int) (barWidth*(player.getCharacters().get(0).getHealthPoint()/(float)player.getCharacters().get(0).getMaxHealthPoint())), barHeight);//HP
g2.setPaint(new GradientPaint(0,0,new Color(57,160,40),100, 0,new Color(17,118,0)));
g2.fillRect(557+(int) (barWidth-(barWidth*(enemies.get(0).getHealthPoint()/(float)enemies.get(0).getMaxHealthPoint()))),433, (int) (barWidth*(enemies.get(0).getHealthPoint()/(float)enemies.get(0).getMaxHealthPoint())), barHeight);
     
//Init Color new Color(255,93,25)
g2.setColor(new Color(255,93,25));
g2.fillRect(63, 482, (int) (barWidth*(player.getCharacters().get(0).getTurnTimer() / (float)CombatState.MAX_TURN_TIMER )-1), barInitiativeHeight-1);//Init
g2.fillRect(523+(int) (barWidth-(barWidth*(enemies.get(0).getTurnTimer() / (float)CombatState.MAX_TURN_TIMER ))),482, (int) (barWidth*(enemies.get(0).getTurnTimer() / (float)CombatState.MAX_TURN_TIMER )), barInitiativeHeight-1);


Any Idea?
Offline jonjava
« Reply #1 - Posted 2013-07-22 13:18:47 »

Hmm, what? The screenshots look good to me, what seems to be wrong and what do you mean by gradient? :V

Offline Sethir

Senior Newbie


Exp: 3 years



« Reply #2 - Posted 2013-07-22 14:41:04 »

The bar should be light green on the left and dark green on the right side. While the first one has a gradient in that way, even if it is not the way I want it, does the second not have any light green.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online philfrei
« Reply #3 - Posted 2013-07-22 17:47:28 »

Are the X locations of the bars properly matching up with the gradient's X locs?

I think you are filling rects that are outside the area where the gradient is happening.

If the gradient goes from x = 0 to x = 100, and you paint at 500, only the second color will be used. Or, if you fill a rect at 20 and go to 120, only the portion from 20-to-100 will have the defined gradient.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline Sethir

Senior Newbie


Exp: 3 years



« Reply #4 - Posted 2013-07-22 20:45:44 »

Thanks, that did the magic.
I thought x and y of each color was percentage, at least the java tutorials of oracle suggested it.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Nickropheliac (16 views)
2014-08-31 22:59:12

TehJavaDev (24 views)
2014-08-28 18:26:30

CopyableCougar4 (33 views)
2014-08-22 19:31:30

atombrot (42 views)
2014-08-19 09:29:53

Tekkerue (41 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (26 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (73 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!