Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2 3 ... 8
1  Java Game APIs & Engines / Java 2D / Re: Coloring gray image on: 2011-10-31 00:34:24
Here is some code I have used before, I beleive you could also use a BufferedImageFilter.
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  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
   /**
    * Create a new BufferedImage from the information provided.
    *
    * @param pixels The color information stored as an integer. The 4 bytes of the integer are used for each color attribute, the first byte is the alpha information and the last 3 are the RGB(Red Green Blue) values.
    * @param width The width in pixels of the image.
    * @param height The height in pixels of the image.
    * @return A new image created from the information.
    */

   static public BufferedImage makeImage(int[] pixels, int width, int height) {
      BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
      img.setRGB(0,0,width, height, pixels, 0, width);
      return img;
   }

   /**
    * This function creates an integer array from the pixel colors of the image passed into it.
    *
    * @param img The source image.
    * @return An integer array containing the color information. The 4 bytes of the integer are used for each color attribute, the first byte is the alpha information and the last 3 are the RGB(Red Green Blue) values.
    */

   static public int[] grabPixelsOld(BufferedImage img) {
      int w = img.getWidth();
      int h = img.getHeight();
      int[] pixels = new int[w * h];
      try {
         img.getRGB(0,0,w,h,pixels, 0, w);
      } catch (Exception e) {
         System.err.println("interrupted waiting for pixels!");
         return null;
      }
      return pixels;
   }

   /**
    * This function creates an integer array from the pixel colors of the image passed into it.
    *
    * @param img The source image.
    * @return An integer array containing the color information. The 4 bytes of the integer are used for each color attribute, the first byte is the alpha information and the last 3 are the RGB(Red Green Blue) values.
    */

   static public int[] grabPixels(BufferedImage img) {
      if(img.getRaster().getDataBuffer() instanceof DataBufferInt)
         return ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
      else
         return grabPixelsOld(img);
   }


   /**
    * Create a new BufferedImage that is a color version of the original grayscale image.
    *
    * @param grayscaleImg The source image to be colored.
    * @param newColor The color to use for the coloring of the image.
    * @return The new color image.
    */

   static public BufferedImage colorImage(BufferedImage grayscaleImg, Color newColor){
      int [] pixels = grabPixels(grayscaleImg);
      if (pixels==null || newColor == null)
         return grayscaleImg;
      int r, g, b, a, shade, red, green, blue, color;
      red = (0x00FF0000 & newColor.getRGB()) >> 16;
      green = (0x0000FF00 & newColor.getRGB()) >> 8;
      blue = (0x000000FF & newColor.getRGB());
      for (int i=0; i<pixels.length;i++){
         a = pixels[i] >> 24;
      if(a!=0){
         shade = (0x000000FF & pixels[i]);
         r = (red*shade/255);
         g = (green*shade/255);
         b = (blue*shade/255);
         a <<= 24;
         r <<= 16;
         g <<= 8;
         //b <<= 0;
        color = a|r|g|b;
         pixels[i] = color;
      }
      }
      return makeImage(pixels, grayscaleImg.getWidth(), grayscaleImg.getHeight());
   }
2  Game Development / Newbie & Debugging Questions / Re: application to applet on: 2011-10-18 22:29:42
This is what I was trying to explain, Frame and Applet extend Container they serve the same basic purpose so you only need 1 or the other depending on your distribution method.

You could still use a canvas with either just have 2 classes one that extends applet and 1 that extends canvas and use applet.add(canvas).

it would probably be a good idea to read up on some basic OOP ideas before you get too much further in.
3  Game Development / Newbie & Debugging Questions / Re: application to applet on: 2011-10-18 03:31:32
Applet and Frame both extend Container so will add your Canvas in a similar way. You could start refactoring by creating a class that extends  JFrame and moving the jframe code out of your canvas. Once your frame is creating an instance of your canvas and drawing it successfully try creating a class that extends Applet to run it.

Once the applet is created you will need the webpage where you want to see it add html like:

<APPLET height="570" width="760" codebase="java/" code="GameApplet">
You are missing <a href=http://www.java.com/download>java</a>.
</APPLET>

where GameApplet is the name of your class that extends applet and codebase is a folder path to the GameApplet.class file.

There is still a lot to learn but hopefully this will get you started.
4  Game Development / Newbie & Debugging Questions / Re: Multiple Timers on: 2011-10-15 20:03:32
A solution that tracked elapsed time using the game loops update method would probably be a much better way to do timers in a game.

If you want to use javax.swing.Timer anyway then don't have Player implement ActionListener but instead make a separate class that does and then pass a new instance of it to your Timer instead.
5  Game Development / Newbie & Debugging Questions / Re: Java applet error on: 2011-08-30 01:51:56
You would need to include the classes from your other package or us the FQN. This link should clear all that stuff up for you. http://download.oracle.com/javase/tutorial/java/package/packages.html

I was wondering if your html applet tag had something like this in it
1  
code="ultrapong.Applet.GameApplet"


6  Game Development / Newbie & Debugging Questions / Re: Java applet error on: 2011-08-29 22:56:21
It just looks like the class isn't found.
Can't really tell anything else without seeing the code, can you link a page with the applet?
7  Game Development / Networking & Multiplayer / Re: KryoNet - Suppress multiple connections from same user? on: 2011-08-03 22:05:39
IP and Mac filtering wont work as already pointed out it will result in way too many false positives.

To combat this you will need to have the users install some kind of spyware like Punk Buster. Even spyware wont protect you if the user simply uses 2 different computers so it's probably better to just accept it.
8  Java Game APIs & Engines / Java 2D / Re: JApplet unable to regain focus on: 2011-07-29 22:53:05
Did you already setFocusable(true)? Maybe try to make a stripped down JApplet that displays this behavior.
9  Game Development / Newbie & Debugging Questions / Re: Storing player data on: 2011-07-20 22:35:42
You can decompile any program but someone cheating in a single player game is much more likely to use a memory editor like cheat engine.
10  Game Development / Performance Tuning / Re: Fastest method of referencing all pixels in a line? on: 2011-07-16 23:27:24
1  
int error = deltax >>>1;

http://en.wikipedia.org/wiki/Arithmetic_shift
http://en.wikipedia.org/wiki/Logical_shift
11  Game Development / Newbie & Debugging Questions / Re: Clever animation design? on: 2011-07-16 20:22:11
Keep the static data how you have it and separate out the dynamic data into another class that points to the static data.

So the frames that represent that animation would still be handled the same as it currently is but the things that point to it would keep track of stuff like current frame and the animation timers.
12  Game Development / Game Play & Game Design / Re: Requesting your feedback :) on: 2011-06-29 22:33:15
Those Facebook pages are very outdated. The REST API was deprecated a year ago, use the GRAPH API now.
Just get your game to run in an applet and use the iframe method.
I found the JS and PHP lib easier to work with than the Java ones.
The widest you can make the applet is 760px, height is unlimited.
Hope that helps.
13  Game Development / Game Play & Game Design / Re: Use of Scripting Languages ? on: 2011-06-25 03:01:56
You are supposed to be able to use the javax.tools package. But ToolProvider.getSystemJavaCompiler() keeps returning null for me. Anyone know how to fix that?
14  Game Development / Game Play & Game Design / Re: Use of Scripting Languages ? on: 2011-06-24 23:12:53
Is there a way to compile Java source like that in an applet without breaking out of the sandbox?
15  Java Game APIs & Engines / Tools Discussion / Re: Exporting Jar in eclipse with images on: 2011-06-23 06:58:37
The code I posted above will load images from any jars in the classpath/archive tag. It also doesn't create ToolkitImages or trip the SecurityManager.
16  Game Development / Networking & Multiplayer / Re: Protection from Data Tampering Client Side on: 2011-06-22 01:36:13
Yeah sorry I left that part off. You verify the score by running the moves on the server using the same physics code as the client did, then compare the scores.

This is much easier on deterministic games like physics puzzles.
 
17  Java Game APIs & Engines / Tools Discussion / Re: Exporting Jar in eclipse with images on: 2011-06-22 00:57:21
I use code like this to load images.
1  
2  
3  
4  
5  
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

String fileName = "Images/cannon.png";
BufferedImage image = ImageIO.read( Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName) );
18  Game Development / Networking & Multiplayer / Re: Protection from Data Tampering Client Side on: 2011-06-22 00:22:28
You can't guarantee anything from the client is legit but you can raise the bar.

For a physics based puzzle you could send what moves the player did to get that score as "proof" they know how to solve it.
19  Game Development / Newbie & Debugging Questions / Re: How to get mouse events. on: 2011-06-21 00:08:46
Cool, glad to help.
20  Game Development / Newbie & Debugging Questions / Re: How to get mouse events. on: 2011-06-20 23:57:10
What are you drawing on if not a JComponent?
21  Game Development / Newbie & Debugging Questions / Re: Running a JApplet in a browser on: 2011-06-19 21:50:40
Did you change the file loading code like cylab suggested?

If you post the relevant code here someone will probably know how to fix it.
22  Game Development / Shared Code / Re: Strip animation class on: 2011-06-18 20:57:39
I just meant turn
1  
GameGFX.gfx().drawImage(getAnimatedFrame(currentFrameIndex).getImage(), xL, yL, null);

into
1  
GameGFX.gfx().drawImage(getImage(), xL, yL, null);


I would advise keeping the getImage function, it will create a nice function to overwrite if you ever want to expand on your animations later, like supporting layered animations for example.
23  Game Development / Shared Code / Re: Strip animation class on: 2011-06-18 02:04:32
@ra4king
It's a static function, not necessarily a singleton, I don't see the relevant code to say one way or the other. I agree it looks a lot uglier than having the graphics object passed in tho.

@aazimon
You declared the getImage() function but didn't use it in your draw, this function will help make the draw more readable.

There is no reason to typecast your frames.get calls to an AnimatedFrame because they already are AnimatedFrame's.

24  Java Game APIs & Engines / Java 2D / Re: Palette drawing on: 2011-06-16 21:25:04
I'm guessing you don't always need all the images available, if you do then just preload them all.

Have 1 class that's responsible for getting the recolored images. In the class keep some type of list(HashMap maybe) of the images you have loaded to act as your cache. If you have already loaded this image return your cached version. If you haven't yet loaded it then load it, add it to your list and then return it.
25  Java Game APIs & Engines / Tools Discussion / Re: Spritesheet animator! on: 2011-06-15 20:57:38
Coloring in grayscale images, this is very useful if you allow a way for the player to pick a hair color or recoloring clothes etc.
26  Game Development / Newbie & Debugging Questions / Re: Playing music in java on: 2011-06-13 23:24:11
My guess it it's something simple like your not properly pointing to the file.
Try System.out.println(myRoot + "./sounds/jump.wav"); to see if it's what you were expecting.
Just creating the File object doesn't test anything, try calling exists() or canRead() on it.
Why don't you use pass that file to getAudioInputStream, otherwise your test is irrelevant.
27  Java Game APIs & Engines / Java 2D / Re: BufferStrategy doesn't work in Applet on: 2011-06-09 05:39:56
1  
canvas.setSize(getWidth(), getHeight());
28  Game Development / Newbie & Debugging Questions / Re: Java Applet Download Progress Bar - Web Start, JOGL on: 2011-06-09 00:40:15
Is this what your looking for?
http://download.oracle.com/javase/tutorial/deployment/applet/customProgressIndicatorForApplet.html
29  Game Development / Newbie & Debugging Questions / Re: lacking return type?! on: 2011-06-06 11:46:25
In a conditional statement like if, the statement "((x>= this.boxX)&&(x<= (this.boxX +this.boxW))&& (y>= this.boxY)&&(y<=this.boxY + this.boxH))" would be evaluated to a boolean. So if its true it will run the statement "return true", but you are not telling the compiler what to do if the statement is false, returning false seems like the obvious solution.

Because all your doing then is returning whatever the the condition evaluates to, then just skip the if all together and return the evaluation like Cas pointed out.
30  Game Development / Newbie & Debugging Questions / Re: Level Editor on: 2011-06-03 13:09:10
The block thingy is called Tile based games.
Pages: [1] 2 3 ... 8
 

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 (9 views)
2014-08-31 22:59:12

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

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

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

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

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

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

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

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

BurntPizza (47 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!