Show Posts
|
|
Pages: [1] 2
|
|
1
|
Game Development / Game Mechanics / Re: [Solved] Moving a masive 2D map instead of the character
|
on: 2012-04-17 16:17:22
|
Yeah I speak from experience too. I used to manually loop through all the Entity's on the screen and modify their location when the player was moved. There were major problems with some maths later on. Using an offset cleanly separates data and view i'm only worried about the changes i have to make to the calculations of positioning the character (and other elements) in the grid.
|
|
|
|
|
3
|
Java Game APIs & Engines / Java 2D / Re: Repainting a transparent bufferimage
|
on: 2012-04-17 15:24:47
|
Use AlphaComposite.CLEAR like you do now or just use AlphaComposite.SRC to paint your new image stuff - if I understand your issue correct.
Hello 65k This way i can clear nicely my transparent bufferimage, but im having a problem. I cannot redraw anything on my image. It keeps blank. Any ideas?
|
|
|
|
|
4
|
Java Game APIs & Engines / Java 2D / Re: Repainting a transparent bufferimage
|
on: 2012-04-17 12:53:56
|
|
Firstly, thanks for your concern.
I have a blank bufferedimage (transparent) on the stage, where i am painting directly using a graphics2D object "pintor".
I need to clear that image to it's original state, to repaint the next frame of animation, not leaving a trace of what was there previuosly.
In Java creating a new BufferedImage for each frame of an animation is slow, but reusing images with transparency from frame to frame is tricky as BufferedImage doesn't have an obvious way to set all of it's pixels to completely transparent.
Unlike other colors we can't just paint a transparent color over the image because, well, it's transparent and won't affect the pixels already in the image.
How can i clear or create a bufferedimage to hold new graphics assets in my repaint method?
|
|
|
|
|
7
|
Game Development / Game Mechanics / Re: [Solved] Moving a masive 2D map instead of the character
|
on: 2012-04-16 21:55:25
|
Hello _Al3x Sure, here is how i managed to solve this: 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
| public class Controles implements KeyListener { protected Applet padre; protected String direccion; public Controles(Applet a){ direccion = ""; a.addKeyListener(this); } public void keyTyped(KeyEvent e){} public void keyPressed(KeyEvent e) { int id = e.getKeyCode(); switch(id){ case KeyEvent.VK_UP: direccion = "Ar"; break; case KeyEvent.VK_DOWN: direccion = "Ab"; break; case KeyEvent.VK_LEFT: direccion = "Iz"; break; case KeyEvent.VK_RIGHT: direccion = "De"; break; } } public void keyReleased(KeyEvent e) { direccion = ""; } public String getDireccion(){ return direccion; } } |
And then the update implementation: 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
| public void movimientoGrid(String b){ b = controls.getDireccion(); switch(b){ case "Ar": for(int i=0; i<mosagrid.size(); i++){ mosagrid.get(i).posY += velocidad; mosagrid.get(i).paint(pintor); } break; case "Ab": for(int i=0; i<mosagrid.size(); i++){ mosagrid.get(i).posY -= velocidad; mosagrid.get(i).paint(pintor); } break; case "Iz": for(int i=0; i<mosagrid.size(); i++){ mosagrid.get(i).posX += velocidad; mosagrid.get(i).paint(pintor); } break; case "De": for(int i=0; i<mosagrid.size(); i++){ mosagrid.get(i).posX -= velocidad; mosagrid.get(i).paint(pintor); } break; } } |
salutations
|
|
|
|
|
9
|
Java Game APIs & Engines / Java 2D / Repainting a transparent bufferimage
|
on: 2012-04-16 20:53:54
|
Hello JGO im triying to diaplay a grid on a transparent bufferimage, but i can't find a viable way to repaint it to the screen without clearing the previous transparent bufferimage effectively. here is what i have: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| BufferedImage grid = new BufferedImage(800, 600, BufferedImage.TRANSLUCENT); Graphics2D pintor = grid.createGraphics();
prototipo.paint(pintor);
public void printMapa(Graphics2D g){ Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, pantancho, pantalto); pintor.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f)); pintor.fill(rect); g.drawImage(grid, 0, 0, padre); pintor = grid.createGraphics(); } |
Any ideas...?
|
|
|
|
|
11
|
Game Development / Newbie & Debugging Questions / Re: Moving around on a map?
|
on: 2012-04-05 15:14:40
|
Hello, There is something i am not still getting, and its the fact that moving the map instead of the character represents making iterations over all the visible tiles (something that has been imposible for me to achieve personally because my game loop has a 12 fps rate and the calculations for moving each individually tile gets truncated). i tried attatching all the tiles on a blank bufferedimage, and just move that image, and it worked. The problem i had with this was when it came the time to draw new tiles to the composition and dispose old ones... plz, help me a little... 
|
|
|
|
|
12
|
Java Game APIs & Engines / Java 2D / Re: [SOLVED] Problem displaying an isometric map portion
|
on: 2012-04-04 15:03:22
|
Hehehe, the yellow background and the green tiles are just placeholders  Just like Fokusas said, the map used to be a diamon shapped thing, but then, i realized that the tiles that go offscreen were adding some innecesary cpu cicles to the whole composition process. i decided just to show the tiles that fit on the screen, based on a current character position (in this case, the gray tile (10,10)). What you can see now (looks like a little house indeed :p) is the top roof of the map, because the starting position tile (10, 10) is nearer (0,0). What im working right now, is the movement. Im developing some kind of engine that draws new tiles in position as they appear, and erase old tiles as they go offscreen.
|
|
|
|
|
15
|
Java Game APIs & Engines / Java 2D / Re: Problem displaying an isometric map portion
|
on: 2012-03-18 00:44:32
|
|
You are right my friend. i decided to get "mosagrid = new Mosaico[mosavis*2];" out of the "for" loops (it had to be that way from the begining).
For the error number two maybe "mosagrid" is not the problem, cause it only counts the iterations ocurred. But thanks of you pointing that out, i think i discovered what went wrong with my code.
If i declare the "mosagrid" length to be "mosavis*2", im saying that mosagrid“s length is 24 (12*2). But it doesnt. The total number of iterations will be (12*12).
Im applying those changes, and see if i can fix it. Ill let you know.
|
|
|
|
|
16
|
Java Game APIs & Engines / Java 2D / Re: Problem displaying an isometric map portion
|
on: 2012-03-18 00:12:52
|
|
Hi and thanks for the answer.
the exception is: java.lang.ArrayIndexOutOfBoundsException: -12
what im hoping to achieve is measure the diamond shape of the map that sorrounds the screen and display it taking as the center the "mosx" and "mosy" tile. The bidimentional iteration is passing the array of the map negative values, because i set my starting tile as (0,0).
|
|
|
|
|
17
|
Java Game APIs & Engines / Java 2D / [SOLVED] Problem displaying an isometric map portion
|
on: 2012-03-17 23:42:09
|
Hello Im having touble trying to display an isometric map portion (The diamond that covers all the visible screen) on the screen. I dont really know why is wrong with my code. Can somebody help, please. This is the code im using for the map builder: 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
| public pruebaGM(int ancho, int alto, int mosx, int mosy, int a[][], Applet p){ padre = p; pantancho = ancho; pantalto = alto; prototipo = new Mosaico(0, p); mosancho = prototipo.ancho; mosalto = prototipo.alto; mosanchoMT = (mosancho/2)-1; mosaltoMT = mosalto/2; mosavis = Math.round(pantancho*2/mosancho); offsetH = Math.round(pantancho/2-mosanchoMT); mosavisMT = Math.round(mosavis/2); mosaX1 = mosx-mosavisMT; mosaX2 = mosx+mosavisMT; mosaY1 = mosy-mosavisMT; mosaY2 = mosy+mosavisMT; grid = new BufferedImage(ancho, alto, BufferedImage.TRANSLUCENT); pintor = grid.createGraphics(); mosanum = 0; System.out.println("Eje de X: "+mosaX1+"-"+mosaX2); System.out.println("Eje de Y: "+mosaY1+"-"+mosaY2); for(int i=mosaX1; i<mosaX2; i++){ for(int j=mosaY1; j<mosaY2; j++){ try{ System.out.println(i); mosagrid = new Mosaico[mosavis*2]; mosagrid[mosanum] = new Mosaico(a[i][j], p); mosagrid[mosanum].posX = ((j*mosanchoMT)-(i*mosanchoMT))+offsetH; mosagrid[mosanum].posY = ((j*mosaltoMT)+(i*mosaltoMT)); mosagrid[mosanum].paint(pintor); mosanum++; }catch(Exception ex){} } } } |
|
|
|
|
|
18
|
Game Development / Newbie & Debugging Questions / Re: RPG inventory
|
on: 2012-02-03 19:32:47
|
|
Hello
You can assign each item with an unique id, and make an item array. Visually make all the elements of your inventory draggable, and with the "snap to its box container" ability. Make sure you have a thumbnail for each of your elements in a library, and name them with the id assigned. That way, you can make a "for" loop to place all the pieces of elements on each container, just as your array is organized.
Good luck.
|
|
|
|
|
20
|
Game Development / Newbie & Debugging Questions / Re: What am i doing wrong in here?
|
on: 2012-02-02 17:47:41
|
Im back, just to post the code with some minor changes, and this time, working as i wanted. I still have in consideration to put my applet extension class apart from the runnable ones. (thanks for the tips). 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
| import java.applet.*; import java.awt.*; import java.awt.image.*;
public class Prueba extends Applet implements Runnable{ int i; BufferedImage backBuffer; Graphics2D painter; Thread t; int movilidadX; int movilidadY; public void init(){ t = new Thread(this); backBuffer = new BufferedImage(600, 400, BufferedImage.TYPE_INT_RGB); painter = backBuffer.createGraphics(); i = 0; movilidadX = 0; movilidadY = 0; t.start(); } public void run(){ while(true){ i++; movilidadX++; movilidadY++; repaint(); try{ t.sleep(1000/30); }catch(InterruptedException ex){ ex.printStackTrace(); } } } public void paint(Graphics g){ painter.setColor(Color.GRAY); painter.fillRect(0, 0, 600, 400); painter.setColor(Color.BLACK); painter.fillRect(movilidadX, movilidadY, 10, 10); painter.drawString("El valor de i es: " + i, 20, 20); g.drawImage(backBuffer, 0, 0, this); paint(g); } } |
|
|
|
|
|
22
|
Game Development / Newbie & Debugging Questions / Re: What am i doing wrong in here?
|
on: 2012-02-01 12:54:16
|
1
| backBufferG.drawString("i = "+i, 10, 20); |
This is rather odd. You *overwrite* your image with text. You probably will end up with something that looks like 'i=8', 'i=88', 'i=888' (as time goes by) Also, make 'int i' volatile, as you're reading it from a thread that is not writing to it. Hello Riven it just works as i intend. i use it to make some kind of counter... I dont know if you can recomend another way... Any ways, i applied some changes to the code and finally get it to work. But now, all the numbers on my counter keeps splattered on the screen  no matter the "repaint()" refresh the whole thing... 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
| import java.applet.*; import java.awt.*;
public class Prueba extends Applet implements Runnable{ Thread t; int i; Graphics backBufferG; Image backBufferI; public void init(){ t = new Thread(this); t.start(); i = 0; backBufferI = createImage(600, 600); backBufferG = backBufferI.getGraphics(); } public void run(){ while(true){ i++; repaint(); try{ t.sleep(1000/29); }catch(Exception ex){;} } } public void paint(Graphics g){ backBufferG.drawString("i = "+i, 10, 20); g.drawImage(backBufferI, 0, 0, this); } public void update(Graphics g){ paint(g); } } |
|
|
|
|
|
25
|
Game Development / Newbie & Debugging Questions / What am i doing wrong in here?
|
on: 2012-02-01 04:21:06
|
Can someone help me to get this running? 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
| import java.applet.*; import java.awt.*;
public class Prueba extends Applet implements Runnable{ Thread t; int i; Graphics backBufferG; Image backBufferI; Dimension Dim; public void init(){ t = new Thread(this); t.start(); i = 0; Dim.getSize(); backBufferI = createImage(600, 600); backBufferG = backBufferI.getGraphics(); } public void run(){ while(true){ i++; repaint(); try{ t.sleep(1000/30); }catch(Exception ex){;} } } public void paint(Graphics g){ backBufferG.drawString("i = "+i, 10, 20); g.drawImage(backBufferI, 0, 0, this); } } |
|
|
|
|
|
30
|
Game Development / Newbie & Debugging Questions / Re: A simple basic question: calling a method return...
|
on: 2012-01-31 03:23:50
|
Thanks for the response. For some reason i cannot see the message of the key being pressed. I get this error: at java.awt.EventDispatchThread.pumpEvents(Unknown Source) Here is my code with modifications: 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
| import java.applet.*; import java.awt.*; import java.awt.event.*;
public class Prueba extends Applet implements Runnable, KeyListener{ String message; Thread t; int i; public void init(){ addKeyListener(this); t = new Thread(this); t.start(); i = 0; } public void run(){ while(true){ i++; repaint(); try{ t.sleep(1000/30); }catch(Exception ex){;} } } public void paint(Graphics g){ g.drawString("i = "+i, 10, 20); g.drawString(message, 50, 80); } public void keyPressed(KeyEvent e) { message = "KEY PRESSED: " + e; } public void keyTyped(KeyEvent e) {;} public void keyReleased(KeyEvent e) {;} } |
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|