Show Posts
|
|
Pages: [1]
|
|
1
|
Game Development / Artificial Intelligence / Re: java area (outline) to polygon / array (x, y)
|
on: 2009-12-05 09:31:14
|
working  ty  1 2 3 4 5 6 7 8 9 10 11 12 13
| mask_tmp = new Polygon(); PathIterator path = a.getPathIterator(null); while (!path.isDone()) { toPolygon(path); path.next();}
return mask_tmp;} private static void toPolygon(PathIterator p_path) { double[] point = new double[2]; if(p_path.currentSegment(point) != PathIterator.SEG_CLOSE) mask_tmp.addPoint((int) point[0], (int) point[1]);} |
|
|
|
|
|
2
|
Game Development / Artificial Intelligence / Re: java area (outline) to polygon / array (x, y)
|
on: 2009-12-05 09:04:02
|
yepp, thank u v much. it's a simple algorithm. after defining your bg-colour (white or transparent) an observer is following the bounding-rect ( top_left to bottom_left, ...), checks for the 1st pix != bg-col (row/column) and stores the pos in an area. i repeat that cycle 4 times, varying the starting corner. after that i get the intersection of all areas  . (i also used a contrast filter) works fine for simple surfaces + it is quite fast because it is linear linked to my sprite-class i get a dynamic collision model (each frame gets it's mask).
|
|
|
|
|
3
|
Game Development / Artificial Intelligence / java area (outline) to polygon / array (x, y)
|
on: 2009-12-04 22:55:25
|
i wrote a program which traces an image's outline. therefore i used java area to use methods such as subtract, add, ... well, it wasn't that difficult to write an collision detection script but the matter is that i don't have any idea how to get an outline polygon (area to outlinepoly) -> x1,y1; x2,y2 .... is there any help? or shld i write my own subtract method / area script?  ty 
|
|
|
|
|
5
|
Java Game APIs & Engines / Java 2D / swing + doublebuffer
|
on: 2008-06-04 09:43:57
|
hey, i am quite new to java. prob is: java doesn't display swing button1 perhaps u know any gd solution thanks sQ 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| import java.awt.Color; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.image.VolatileImage; import java.util.HashMap; import java.util.Map; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame;
public class Window { private boolean run = true; public Window() { JFrame f = new JFrame("LevelCreator"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(800, 600); f.setVisible(true); f.setResizable(false); final Icon icon2 = new ImageIcon( Window.class.getResource( "/pattern/block.png" ) ); final JButton button1 = new JButton( icon2 ); button1.setLocation(200,200); button1.setDoubleBuffered(true); button1.setVisible(true); f.add( button1 ); Main main = new Main(f); Map<RenderingHints.Key, Object> config = new HashMap<RenderingHints.Key, Object>(); config.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); config.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED); config.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); config.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); config.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE); config.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED); config.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); config.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); config.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); f.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { run = false; System.exit(0); } }
public void keyReleased(KeyEvent arg0) {}
public void keyTyped(KeyEvent arg0) {} }); int fps_counter = 0; long t_start = System.currentTimeMillis(); long t_current = 0, fps = 0; Graphics2D buffered = (Graphics2D) f.getGraphics(); buffered.setRenderingHints(config); VolatileImage img = f.createVolatileImage(Statics.width, Statics.height); Graphics2D g = (Graphics2D) img.createGraphics(); g.setRenderingHints(config); while(run) { g.setColor(Color.BLACK); g.fillRect(0, 0, Statics.width, Statics.height);
if(t_current > t_start + 1000) { t_start = System.currentTimeMillis(); fps = fps_counter; fps_counter = 0; } ++ fps_counter; main.paint(g); g.setColor(Color.red); g.drawString("fps: " + fps, 100, 200); buffered.drawImage(img, 0, 10, f); t_current = System.currentTimeMillis(); } } public static void main(String[] args) { try { new Window(); } catch(Exception e ) {System.exit(0);} } } |
|
|
|
|
|
6
|
Game Development / Game Play & Game Design / Re: game menu
|
on: 2008-04-22 23:11:30
|
i suppose it is caused by using voliateImage...? but i am not that sure because i am a so called newbie - edit: maybe ur pc doesnt support 800x600 pix @brackeen - i set the config to 800x600pix i gonna fix that bug aswell  thanks btw: does anybody know how to get a list of supported video modes?
|
|
|
|
|
10
|
Java Game APIs & Engines / Java 2D / Re: java volatile img
|
on: 2008-04-17 16:33:38
|
i found this: VolatileImage: This image type was created in JDK 1.4 as a means of creating and managing accelerated image memory. One of the problems with hardware acceleration for images is that, on some platforms, accelerated memory can be deleted out from under you at any time. This is obviously not what you want for your typical image data. To work around that, the VolatileImage API was created to provide a notification mechanism so that you know when an image must be re-rendered due to data loss. VolatileImage objects are not loaded from image data, but are just created as empty pixel buffers (much as the initial BufferedImage objects were (see above)); to load image data into a VolatileImage, applications must load the image data through some non-Volatile means, get the Graphics object for the VolatileImage, and then copy the data into the Graphics
|
|
|
|
|
11
|
Java Game APIs & Engines / Java 2D / java volatile img
|
on: 2008-04-17 00:18:28
|
hey guys. just getting started with java. i have got a question: i coded a source-loader class and a sprite class using simple images (Image x). would i achieve to increase fps by using volatile images instead of simple images even if the back-buffer is of type volatile? my current game speed (100 sprites) @ 1280x1024 pix: 1003 fps thank you 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| import java.awt.Color; import java.awt.Dimension; import java.awt.DisplayMode; import java.awt.Frame; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.RenderingHints; import java.awt.Toolkit; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.image.ImageObserver; import java.awt.image.VolatileImage; import java.util.HashMap; import java.util.Map;
public class FullScreen { final GraphicsEnvironment gE = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice gDevice = gE.getScreenDevices()[0]; final GraphicsConfiguration gc = gDevice.getDefaultConfiguration(); final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); private Frame display = new Frame(gc); private Map<RenderingHints.Key, Object> config = new HashMap<RenderingHints.Key, Object>(); private Main main; public FullScreen() { display = new Frame(gc); display.setUndecorated(true); display.setIgnoreRepaint(true); display.setResizable(false); display.enableInputMethods(false); gDevice.setFullScreenWindow(display); main = new Main(display); config.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); config.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED); config.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); config.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); config.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE); config.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED); config.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); config.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); config.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); display.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { display.setVisible(false); display.dispose(); System.exit(0); } }
public void keyReleased(KeyEvent arg0) {}
public void keyTyped(KeyEvent arg0) {} }); int fps_counter = 0; long t_start = System.currentTimeMillis(); long t_current = 0, fps = 0; DisplayMode dm = new DisplayMode(screen.width, screen.height, 32, DisplayMode.REFRESH_RATE_UNKNOWN); gDevice.setDisplayMode(dm); Graphics2D buffered = (Graphics2D) display.getGraphics(); buffered.setRenderingHints(config); ImageObserver io = display; VolatileImage img = display.createVolatileImage(screen.width, screen.height); Graphics2D g = (Graphics2D) img.createGraphics(); g.setRenderingHints(config); while(true) { g.clearRect(0, 0, screen.width, screen.height);
if(t_current > t_start + 1000) { t_start = System.currentTimeMillis(); fps = fps_counter; fps_counter = 0; } ++ fps_counter; main.paint(g); g.setColor(Color.RED); g.drawString("fps: " + fps, 10, 20); buffered.drawImage(img, 0, 0, io); t_current = System.currentTimeMillis(); } } public static void main(String[] args) { new FullScreen(); } } |
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|