Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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
1  Game Development / Game Mechanics / Re: [Solved] Moving a masive 2D map instead of the character on: 2012-04-17 14:17:22
Quote
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.
2  Java Game APIs & Engines / Java 2D / Re: Repainting a transparent bufferimage on: 2012-04-17 14:14:38
no...    Grin

Let me try it.
3  Java Game APIs & Engines / Java 2D / Re: Repainting a transparent bufferimage on: 2012-04-17 13: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 10: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?
5  Game Development / Game Mechanics / Re: [Solved] Moving a masive 2D map instead of the character on: 2012-04-16 22:08:08
@ _al3x

Wow, thank you very much bro. I appreciate the gesture!!!

I use all my variables in spanish for the sake of consistency. I like to understand everything i do in my code once written. When i post something in the forums i change some of the variables, so ppl can understand a bit.
6  Game Development / Game Mechanics / Re: [Solved] Moving a masive 2D map instead of the character on: 2012-04-16 20:11:13
Hello Danny.

Im guessing it is because the numbers can be processed faster than strings. am i right?
7  Game Development / Game Mechanics / Re: [Solved] Moving a masive 2D map instead of the character on: 2012-04-16 19: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  
//Controls class
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 = "";
   }
   
   //Enviar la direccion de las teclas:
  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
8  Java Game APIs & Engines / Java 2D / Re: First small Java Game on: 2012-04-16 19:22:19
Great job indeed.
9  Java Game APIs & Engines / Java 2D / Repainting a transparent bufferimage on: 2012-04-16 18: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  
//Create a blank transparent buffered image:
BufferedImage grid = new BufferedImage(800, 600, BufferedImage.TRANSLUCENT);
Graphics2D pintor = grid.createGraphics();

//transfer a single prototipe tile on to  my bufferedimage
prototipo.paint(pintor);

//painting it
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...?
10  Game Development / Game Mechanics / [Solved] Moving a masive 2D map instead of the character on: 2012-04-06 15:18:32
*** Topic solved ***
11  Game Development / Newbie & Debugging Questions / Re: Moving around on a map? on: 2012-04-05 13: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...  Cry
12  Java Game APIs & Engines / Java 2D / Re: [SOLVED] Problem displaying an isometric map portion on: 2012-04-04 13:03:22
Hehehe, the yellow background and the green tiles are just placeholders Cheesy

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.
13  Java Game APIs & Engines / Java 2D / Re: [SOLVED] Problem displaying an isometric map portion on: 2012-04-03 02:01:11
Sure,
Sorry for the late response. Here is the pic:



14  Java Game APIs & Engines / Java 2D / Re: Problem displaying an isometric map portion on: 2012-03-17 23:58:44
Now it is perfect!!!

Thanks a lot.
15  Java Game APIs & Engines / Java 2D / Re: Problem displaying an isometric map portion on: 2012-03-17 23: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-17 23: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 22: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){
     
      //Applet padre
     padre = p;
     
      //Medidas del padre
     pantancho = ancho;
      pantalto = alto;
     
      //Creacion de mosaico modelo
     prototipo = new Mosaico(0, p);
     
      //Medidas de mosaico modelo
     mosancho = prototipo.ancho;
      mosalto = prototipo.alto;
     
      //Mitad de las medidas para puntos de referencia
     mosanchoMT = (mosancho/2)-1;
      mosaltoMT = mosalto/2;
     
      //Mosaicos visibles segun tamano de la pantalla
     mosavis = Math.round(pantancho*2/mosancho);
      //mosavisy = Math.round((pantalto*2)/mosaltoMT);
     
      //Referencia para centralizar mapa
     offsetH = Math.round(pantancho/2-mosanchoMT);
      //offsetV = Math.round((pantalto-(mosavisy*mosalto))/2);
     
      //Mitad de los mosaicos visibles
     mosavisMT = Math.round(mosavis/2);
      //mosavisyMT = Math.round(mosavisy/2);
     
      //Mosaicos de definicion de boundaries
     mosaX1 = mosx-mosavisMT;
      mosaX2 = mosx+mosavisMT;
      mosaY1 = mosy-mosavisMT;
      mosaY2 = mosy+mosavisMT;
     
      //Lienzo donde sera plasmado el mapa
     grid = new BufferedImage(ancho, alto, BufferedImage.TRANSLUCENT);
     
      //Creando interfaz grafica
     pintor = grid.createGraphics();
     
      //Buffer para registro de mosaico visible
     mosanum = 0;
     
      System.out.println("Eje de X: "+mosaX1+"-"+mosaX2);
      System.out.println("Eje de Y: "+mosaY1+"-"+mosaY2);
      //Bucle de construccion
     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));//+offsetV;
              mosagrid[mosanum].paint(pintor);
               mosanum++;
            }catch(Exception ex){}
         }
      }
   }
18  Game Development / Newbie & Debugging Questions / Re: RPG inventory on: 2012-02-03 18: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.
19  Game Development / Newbie & Debugging Questions / Re: Graphics2d Paint multiples problem on: 2012-02-02 17:25:39
One class Sprite has :
 
1  
2  
3  
4  
5  
6  
7  
public Graphics2D myColor(Graphics x){
   
    Graphics2D p= (Graphics2D)x;
     p.setColor(Color.RED;
   
    return p;
    }



Hello
")" is missing, but i guess you have already fixed that out.
20  Game Development / Newbie & Debugging Questions / Re: What am i doing wrong in here? on: 2012-02-02 16: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{
   //Declaracion de variables
  int i;
   BufferedImage backBuffer;
   Graphics2D painter;
   Thread t;
   int movilidadX;
   int movilidadY;
   
   //Metodos de clase
  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);
   }
}
21  Game Development / Newbie & Debugging Questions / Re: What am i doing wrong in here? on: 2012-02-01 12:24:06
Reread my post very carefully. It explains why you see what you see Stare

Don't get me wrong, I really appreciate your help, the issue is i didnt understand very well what you said...  Huh
22  Game Development / Newbie & Debugging Questions / Re: What am i doing wrong in here? on: 2012-02-01 11: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  Emo
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);
   }
}
23  Game Development / Newbie & Debugging Questions / Re: What am i doing wrong in here? on: 2012-02-01 11:02:47
Hi D

i still cant figure out why this is not working. i did what you told, but its like the t.start(); method is not doing anything.
24  Games Center / Archived Projects / Re: Cat Invaders on: 2012-02-01 03:33:11
- sfx, nyan is preferred

Nyam cat sfx sound? are you serius? I rather kill myself  Grin
25  Game Development / Newbie & Debugging Questions / What am i doing wrong in here? on: 2012-02-01 03: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);
   }
}
26  Game Development / Newbie & Debugging Questions / Re: Point me to some helpful newb Tutorial plz on: 2012-02-01 03:17:32
Thanks a lot Gabriel for your interest on the matter. Being honest, im diying to get full control of the great potential the java languaje has to give.

(Offtopic) I always dreamed with develop my own game project and who knows, maybe start a carrer out of it...
27  Game Development / Newbie & Debugging Questions / Re: Point me to some helpful newb Tutorial plz on: 2012-02-01 02:56:53
I guess i have found one interesting set of tutorials. Im posting here the link so you can learn from them too:

http://www.realapplets.com/tutorial/
28  Game Development / Newbie & Debugging Questions / Point me to some helpful newb Tutorial plz on: 2012-02-01 02:16:08
Hello.

Can someone point me to the a beginers tutorial? Some material where i can learn how to handle double buffering (or at least understand it), key and mouse listeners, thread handeling and states.

it will be much apreciated.

Excuse my bad english. It is not my native languaje...  Cry
29  Game Development / Newbie & Debugging Questions / Re: A simple basic question: calling a method return... on: 2012-01-31 10:52:45
Thank you all guys. Now it's working.
30  Game Development / Newbie & Debugging Questions / Re: A simple basic question: calling a method return... on: 2012-01-31 02: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) {;}
}
Pages: [1] 2
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (37 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (41 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (60 views)
2014-09-21 02:42:18

BurntPizza (30 views)
2014-09-21 01:30:30

moogie (36 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (52 views)
2014-09-19 03:14:18
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!