Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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  
  Visible to current unit  (Read 1042 times)
0 Members and 1 Guest are viewing this topic.
Offline stef569

Junior Devvie





« Posted 2007-06-20 17:04:58 »

Hi, I got a game with a grid map, One Grid is 30-30 and is filled with images.

I loop trough the array and see what sort it is and then draw the images to the buffer.

Now I'm adding units and they all need tiles turned lighter when they can see them.

Do i need to create extra images for light and dark? or can an image be turned darker manualy with code?

Alsoo all the units combined have a terretory that is lighten up do i need some sort of frames to do that?

so i can quickly change view when it is the next player his turn?

or just different buffers.
Offline Coinerson

Junior Devvie




Introducing the world's cutest zombie, Timmy


« Reply #1 - Posted 2007-06-20 17:13:48 »

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  
public void drawBrighterImage(Graphics2D g2d, BufferedImage im, 
                                      int x, int y, float brightness)
  /* Draw the image with changed brightness, by using a RescaleOp.
     Any alpha channel is unaffected. */

  {
    if (im == null) {
      System.out.println("drawBrighterImage: input image is null");
      return;
    }

    if (brightness < 0.0f) {
      System.out.println("Brightness must be >= 0.0f; setting to 0.5f");
      brightness = 0.5f;
    }
    // brightness may be less than 1.0 to make the image dimmer

    RescaleOp brigherOp;
    if (hasAlpha(im)) {
       float[] scaleFactors = {brightness, brightness, brightness, 1.0f};
                // don't change alpha
                // without the 1.0f the RescaleOp fails, which is a bug (?)
       float[] offsets = {0.0f, 0.0f, 0.0f, 0.0f};
       brigherOp = new RescaleOp(scaleFactors, offsets, null);
    }
    else   // not transparent
      brigherOp = new RescaleOp(brightness, 0, null);

    g2d.drawImage(im, brigherOp, x, y);
  }  // end of drawBrighterImage()


  public void drawNegatedImage(Graphics2D g2d, BufferedImage im, int x, int y)
  /* Draw the image with 255-<colour value> applied to its RGB components.
     Any alpha channel is unaffected. */

  {
    if (im == null) {
      System.out.println("drawNegatedImage: input image is null");
      return;
    }

    if (hasAlpha(im))
      g2d.drawImage(im, negOpTrans, x, y);  // use predefined RescaleOp
    else
      g2d.drawImage(im, negOp, x, y);
  }



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  
public void drawFadedImage(Graphics2D g2d, BufferedImage im, 
                                   int x, int y, float alpha)
  /* The degree of fading is specified with the alpha value.
     alpha == 1 means fully visible, 0 mean invisible. */

  {
    if (im == null) {
      System.out.println("drawFadedImage: input image is null");
      return;
    }

    if (alpha < 0.0f) {
      System.out.println("Alpha must be >= 0.0f; setting to 0.0f");
      alpha = 0.0f;
    }
    else if (alpha > 1.0f) {
      System.out.println("Alpha must be <= 1.0f; setting to 1.0f");
      alpha = 1.0f;
    }

    Composite c = g2d.getComposite();  // backup the old composite

    g2d.setComposite( AlphaComposite.getInstance(
                           AlphaComposite.SRC_OVER, alpha));
    g2d.drawImage(im, x, y, null);

    g2d.setComposite(c);
      // restore the old composite so it doesn't mess up future rendering
  }


Offline stef569

Junior Devvie





« Reply #2 - Posted 2007-06-20 17:42:09 »

wow, your fast  Smiley i'll try that code.

And what about the units, I need differt players each represented by the same image(ie infantery, tanks,...) but different color.

and what base color should is choose then.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Coinerson

Junior Devvie




Introducing the world's cutest zombie, Timmy


« Reply #3 - Posted 2007-06-20 18:17:10 »

I think your better off just re coloring the sprites, thats what I do. Otherwise you would have to make a color that you go through and replace, which means you couldn't have that color on the sprite. If there is another way to do it I don't know it. I bet there is though.
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.

toopeicgaming1999 (21 views)
2014-11-26 15:22:04

toopeicgaming1999 (20 views)
2014-11-26 15:20:36

toopeicgaming1999 (7 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (24 views)
2014-11-25 11:26:43

Gibbo3771 (22 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (74 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!