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
| 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; }
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; }
static public int[] grabPixels(BufferedImage img) { if(img.getRaster().getDataBuffer() instanceof DataBufferInt) return ((DataBufferInt) img.getRaster().getDataBuffer()).getData(); else return grabPixelsOld(img); }
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; 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.
|
|
|
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.
|
|
|
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.
|
|
|
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.
|
|
|
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.
|
|
|
|
|
nelsongames
(17 views)
2018-04-24 18:15:36
nelsongames
(13 views)
2018-04-24 18:14:32
ivj94
(587 views)
2018-03-24 14:47:39
ivj94
(49 views)
2018-03-24 14:46:31
ivj94
(400 views)
2018-03-24 14:43:53
Solater
(64 views)
2018-03-17 05:04:08
nelsongames
(110 views)
2018-03-05 17:56:34
Gornova
(175 views)
2018-03-02 22:15:33
buddyBro
(723 views)
2018-02-28 16:59:18
buddyBro
(93 views)
2018-02-28 16:45:17
|
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
|
|