Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (526)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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]
1  Java Game APIs & Engines / Java 2D / Re: ram ever better than vram? + accing drawString on: 2005-04-18 22:31:43
I would like to use a small number of reusable tiles for constructing my maps, like CaptainJester mentioned; however, pre-splitting that image into 32*32px pngs might be REALLY tedious... I like that idea, linux.. i'm just trying to think of a way i might do that programatically.
Actually, after all is said and done I might HAVE to do something to that effect anyway, because I really want to make a gui for making my own maps with which i can select from 32*32 portions of a tile template to drag and drop onto the saveable map canvas.  When I'm done creating that map and want to play my game, the game could load the created map in portions, which maybe I'll have SAVED in portions when i save the map that i'm working on.  
Hmm... what do you think?  Do you think there's a way to split the map into portions like you'd mentioned,  prior to loading it, but without doing that manually through mspaint?
BTW linux, good job for english not being your native language, and sorry about my horrible grammar... i do a terrible job at conveying my messages (i'm pretty scatterbrained... Sad ).  Thanks guys
2  Java Game APIs & Engines / Java 2D / Re: ram ever better than vram? + accing drawString on: 2005-04-18 04:51:37
aha! brilliant!  that would actually work great based on how i'm doing things, thanks!
ps, intelligent caching algorythms... like besides the ol'
1  
2  
3  
4  
5  
6  
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
            bimage = gc.createCompatibleImage(width, height,Transparency.TRANSLUCENT);
            Graphics2D gTile = (Graphics2D) bimage.getGraphics();
            gTile.setComposite(AlphaComposite.Src);
            gTile.drawImage(subImage, 0, 0, null);
            gTile.dispose();

?  If so, do you by chance have any links or good search keywords on such a topic?  thanks again for all the help.
3  Java Game APIs & Engines / Java 2D / Re: ram ever better than vram? + accing drawString on: 2005-04-18 02:32:25
Quote
Why in hell do you need 10000*100000 pics that are accerlated. Many cards are'nt even able to handle 4096 textures, like ATI, their chips are limited to 2048. Again, its a really bad design if you need to draw such big images!

That's what i mean, the graphics card might not be able to handle it.
my regular ol' 1,000*1,000 is puney!  I want fields and towns that mmoers can walk through, and really the 1k*1k is only able to sport 2 houses and look alright.  10k isnt' all that unreasonable, at least from my experience with every 2d rpg i've every played.  I guess I could make a million rooms and be unique... :s
Quote
It really depends where you are rendering to. DrawString is optimized using the OGL pipeline, and the whole shape-operations should be optimized nearly everywhere as long as you do not use AA or alpha blending.
But when painting to Surface or VolatileImage you should get pretty good performane anyway

What's Surface?  Presently I'm painting to the bufferStrategy graphics context, without AA or alpha (though bufferedimages painted to this context do contain both, will that cancel out the optimization?)
Thanks for the advice on loading the images w/o accing them, i'll change that.
4  Java Game APIs & Engines / Java 2D / ram ever better than vram? + accing drawString? on: 2005-04-17 14:32:48
I'm making a 2d mmorpg, and when I load the map, i have to load to sets of tiles: the first layer and the second (obstructions) layer.  These each are 1000*1000 now and will vary later (i hope to have really realy big maps! this one is tiny).  Anyway, I immediately load it into vram, break it into tiles, and throw it away.  the accelerated tiles are drawn on the fly, and work great, but the loading process takes FOREVER on systems with low vram.  Then while the display process is so-so with lowvram systems (since the tiles are only displayed within the viewable camera portion), it's TOO fast on systems with high vram.  I know i can make my render loops based on time to even it out, but I'm thinking, since this isn't 3d (and therefore people might want to play it for the sole reason that they don't have a graphics card) might it be better to load everything into ram?  after all, when i start doing 10,000*10,000 pics, that won't even load into most cards anyway?
Also, while the normal displaying process is so-so, when I Graphics.drawString() or Graphics.fillRoundRect(), it gets REALLY slow (since it's mmo, you press enter to talk and it shows the string in a word bubble above your sprite, hence round rect).  is there a way to accelerate strings and shapes?  or does that mean hoppin the ogl bandwagon?
5  Game Development / Networking & Multiplayer / Re: checking ServerSocket.accept() in passing? on: 2005-04-15 14:16:16
well here's my problem with the multithreading part... presently i have the server only accepting and then handing off to middleman serverthreads that have the socket for each client.  The server holds all of the information (namely the Sprite instance for the main character of every client) and distributes those througout the clients by a method within the server, accessed by the middleman, that sends out the arraylist to each client.
so far so good... just like every tutorial on the subject:
1. client connects to server and server receives the Hero (the character being controlled) and adds him to the heros arraylist.
2. server passes the received socket off to middleman(serverthread) that loops through receiving from and sending to the client via the socket.
3. in the client's send to, it accesses the server's heros arraylist and sends that to it's client to paint.

The problem is that via this method, the whole class is sent every time.  I tried it to see if it would be that big of a deal, and indeed it brought me from 60fps to less than 1fps.  I tried thinking of a way that each client only sends its x,y coords after having sent it's whole class to the server on construct to be added to the arraylist.  that way, the server can deal each Hero instance to each client everytime a new one shows up (a new person logs on) and then distribute only coords every time after that.
I've been mapping this for days, trying to figure out the best relationship between server, client, and serverthread and i still can't figure out a way to effectively pull this off.  The closest i got was that the server can tag a byte on before every Hero sent to each client.  that byte will say whether it's a new hero to be added to the client' repertoire, or an existing Hero of which to update coords.  My problem with that is, how can i, from within the server, figure out whether every client has the new Hero's content so as to change that byte back from newHero to justCoords?  
It's a big mess... and I'm very new to java, but I've been told that UDP might be more effective in this regards.  If the server had a way of skipping ServerSocket::accept() if there's nothing to be accepted, that would work perfectly because then the server could cycle through clients with a for loop and set any newHeros back to justCoords at the end of the loop, ensuring that everyone gets the new hero without overhead.
Oy!
6  Game Development / Networking & Multiplayer / Re: checking ServerSocket.accept() in passing? on: 2005-04-15 03:53:16
*gulp* *backs away slowly*
7  Game Development / Networking & Multiplayer / checking ServerSocket.accept() in passing? on: 2005-04-14 02:28:47
InputStreamReader.ready() checks if there is information to be read on the socket, and it's really useful for me because I update information based on information fed over the socket, but if any info isn't written, then I pass by the updates and the game continues.  Otherwise, DataInputStream would wait until something was sent to it before continuing.

is there anything similar to that for a server?  I'd like to have my server check if anyone is trying to connect to it.  If so, addt the client, if not, update everyone else and check again.  There a way to do this?
8  Java Game APIs & Engines / Java 2D / Re: bufferstrategy or opengl? on: 2005-04-06 15:22:47
whooo!  1.1 celeron, that's telling!
well, if there isn't that big of a difference when you do things properly, i'll probably just stick to java 2d then.  the reason i asked is because i figured that one is just as easy to get used to as the other, and if one is even slightly better than another, i'll stick with that. (i'm making a mmorpg, so i was hoping for peak efficiency.)  it sounds though, from what i've seen, that opengl is a little harder to get used to than java2d (especially after what i've learned about 2d up until this point) so i'll just stick to the wiley bufferstragegy.  Thanks for the advice guys!
9  Java Game APIs & Engines / Java 2D / bufferstrategy or opengl? on: 2005-04-05 18:24:27
so i spent days and days learning how to make a background with interactible sprites and a hero that moves through a scrollable map (i probably should have learned java before learning how to make java games :s) and came to find out that i was doing everything wrong (the performance was terrible!).  so i learned the basics of double buffering and bufferedimages, tiles, etc. and found out after hours and hours of that that I should be using bufferstrategy.

So I looked on google and this forum and saw that opengl is an option for peak performance, but I can't seem to find a comparison.  before i jump into one concept or another, i think it might save me some time to get some pros and cons on the two, or maybe even advice on any other 2d apis that will give me some good performance (such as volatile image, but I understand that to be used anyway via bufferstrategy?).  Thanks in advance.
10  Java Game APIs & Engines / Java 2D / Re: drawImage() ... i can't get subimage on: 2005-04-04 04:43:08
so should i save the bimage data into a 2d array of images?
11  Java Game APIs & Engines / Java Sound & OpenAL / can't play 2 audioclips at same time? on: 2005-04-04 02:13:51
AudioClip music=getAudioClip(getCodeBase(), "Music/song.midi");
AudioClip sound=getAudioClip(getCodeBase(), "Sounds/sound.wav");

sound.play(); //works, used when I press enter

music.play(); //works

but when I play them together, only music.play() gives me any sound. When I press enter, nothing happens most of the time and every so often sound.play() plays maybe half of the sound file. Any ideas?
12  Java Game APIs & Engines / Java 2D / drawImage() ... i can't get subimage on: 2005-04-03 21:13:11
every time i try drawImage(img, dx, dy...), when I move my character it scales the map in and out, up and down, rather than moving that portion of the map.
I want to have a camera that follows the hero, and it works via bufferedimage.subImage, but that is freakishly slow.  So in my main loop I have
offscreen.drawImage(map.paint(subImage), 0,0, this)
and my paint method should return a subimage of the big image.  

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
      public Image paint(Image subImage)
      {      // Set the viewable portion of the canvas to the hero's coords
           
            if (cameraFollow){
            clipX=hero.x-320; clipY=hero.y-240; clipWidth=640; clipHeight=480;
            if (hero.x-320<=0)             clipX=0;
            else if (hero.x+320>=width)    clipX=width-640;
            if (hero.y-240<=0)             clipY=0;
            else if (hero.y+240>=height)   clipY=height-480;
          }
           
            canvas.setClip(clipX, clipY, clipWidth, clipHeight);;      
            canvas.drawImage(chip1,0,0, null);
            canvas.drawImage(hero.image,hero.x, hero.y, null);
            for (int i=0; i<sprites.size(); i++)
                  {thisSprite=(Sprite)sprites.get(i);
                   canvas.drawImage(thisSprite.image,thisSprite.x, thisSprite.y, null);}
            canvas.drawImage(chip2, 0,0,null);
            canvas.drawImage(subImage, 0,0,appWidth, appHeight, clipX, clipY, clipWidth, clipHeight, applet);
            return subImage;
           
      }
13  Java Game APIs & Engines / Java 2D / Re: any ideas on RPG map scrolling? on: 2005-04-03 02:46:42
success!  if anyone's interested in doing this, here's my code:

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  
import java.awt.*;
import java.awt.image.*;
import java.applet.Applet;
import java.util.ArrayList;

public class Room
{
      int width, height, appWidth, appHeight;
      String music="Music/Tsz_02.mid";
      boolean[][] grid;
      Applet applet; Graphics g;
      ArrayList sprites=new ArrayList();
      Sprite thisSprite;
      Hero hero;
      BufferedImage bimage; Graphics2D canvas, g2d;
      Image layer1;
     
      public Room(Image tile, Applet applet, Graphics g)
      {
            this.applet=applet;
            layer1=tile;
            width=layer1.getWidth(applet); height=layer1.getHeight(applet);
            appWidth=applet.bounds().width; appHeight=applet.bounds().height;
           
            this.g=g;
            g2d = (Graphics2D)g;
            bimage = g2d.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.BITMASK);
            canvas = bimage.createGraphics();
           
            grid=new boolean[width][height];
            for (int j=0; j<width-1; j++) //set the borders as obstructions
                {grid[j][0]=true; grid[j][height-1]=true;}
          for (int j=0; j<height-1; j++)
                {grid[0][j]=true; grid[width-1][j]=true;}
           
      }
     
      public void update(int spriteNumber)
      {
            for (int i=0; i<sprites.size(); i++)
            {
                  thisSprite=(Sprite)sprites.get(i);
                  if (spriteNumber!=i)
                        thisSprite.move(sprites, i);
            }
           
      }      
     
      boolean cameraFollow=true;
      int clipX, clipY, clipWidth, clipHeight;
      public BufferedImage paint()
      {
            canvas.drawImage(layer1,0,0, null);
            canvas.drawImage(hero.image,hero.x, hero.y, null);
            for (int i=0; i<sprites.size(); i++)
                  {thisSprite=(Sprite)sprites.get(i);
                   canvas.drawImage(thisSprite.image,thisSprite.x, thisSprite.y, null);}
           
            // Set the viewable portion of the canvas to the hero's coords
        if (cameraFollow){
            clipX=hero.x-320; clipY=hero.y-240; clipWidth=640; clipHeight=480;
            if (hero.x-320<=0)             clipX=0;
            else if (hero.x+320>=width)    clipX=width-640;
            if (hero.y-240<=0)             clipY=0;
            else if (hero.y+240>=height)   clipY=height-480;
          }
         
          return bimage.getSubimage(clipX, clipY, clipWidth, clipHeight);
      }
                 
}      


for some reason this code is freakishly slow, but that might be in one of my other classes... otherwise, if someone sees some inefficiencies, please feel free to tell!

the boolean[][] grid sets up the obstructable regions.  I do my collision testing by first checking sprite bounding boxes to see if they intersect (which isn't too tough on the cpu) then checking boolean values on the map.  Layer2 goes through and sets all pixels that aren't transparent to true, leaving transprent pixels as false.  
14  Java Game APIs & Engines / Java 2D / Re: any ideas on RPG map scrolling? on: 2005-04-02 20:38:20
or what about instead of shifting your images relative to the screenx/y, drawing all of your images to the main layer1 image and displaying a portion of that.
ex., all the characters and your main hero have free reign as far as x,y coords are concerned.  you actually move x, y coords when you walk, but the camera follows you.  So how would I be able to draw everything to one image (draw my sprites, trees etc, and hero to the tileLayer image)?  If i could do that, then I could just throw in a boolean cameraFollows and have it always set to hero.x-screen.width/2, hero.y-screen.height/2.  I would only paint one Image, the main image, which would be modified in the Map class by adding its own images.
15  Java Game APIs & Engines / Java 2D / any ideas on RPG map scrolling? on: 2005-04-02 00:32:35
presently when a key is pressed my character changes x/y coords based on vx/vy.  I'm sure this has been discussed before, so what's the word on having a map that's larger than the viewable region (640*480 in my case) that scrolls opposite the direction that the hero walks?
ex., when i walk left, the screen scrolls right while i stay in the middle.  When I hit the edge of the map, however, my character finishes the distance by actually moving left instead of the screen moving right.

I could do something like:
if (hero.x >= image.getWidth()-viewableWidth/2)
  hero.x+=vx;
else
  image.x-=vx;

but that seems iffy, and i suck at java and consistenly find other ideas better than my own.  I'm thinking this wont' be too great because I do a lot of comparing x,y coords between my sprites and hero, as well as checking for obstructions.  If my hero's x,y coords are always in the middle except when he reaches the edge of the map, then that comparison won't do.  Any takers?

or how about this: can i check and modify the hero's x,y coords relative to the map rather than the applet?
16  Java Game APIs & Engines / Java 2D / Compatibility issue on: 2005-04-02 00:23:09
I made a rudimentary "game" that seems to be only working on some computers.  Newer computers run it, older computers give me the "class not found" error when I try to load the applet.  Here's my code:
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  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.io.*;
import java.awt.image.*;


public class VideoGame extends Applet implements Runnable, KeyListener {

  Thread animation;
  Graphics offscreen;
  static final int REFRESH_RATE = 35; // in ms
  int width, height;
  AudioClip music;
 
  MediaTracker t;
 
  Image image,images[][];
  boolean[][] grid;
 
  Layer2 layer2;
  Hero hero;
  int amtSprites=8;
  Sprite[] sprite=new Sprite[amtSprites];  
 
  public String debugString;
  int spriteNumber;
 

//INHERITED METHODS
  public void init() {
              this.addKeyListener(this);
          showStatus("Loading Images");
          width=bounds().width; height=bounds().height;
          setBackground(Color.black);        // applet background
          image = createImage(width,height); // make offscreen buffer
          offscreen = image.getGraphics();
          Font timesNew = new Font("TimesRoman",Font.PLAIN,18);
          offscreen.setFont(timesNew);
          grid=new boolean[width][height];
          music = getAudioClip(getDocumentBase(),"Music/Tsz_02.mid");
         
          loadImages();
          music.play();
         
          for (int j=0; j<width-1; j++) //set the borders as obstructions
                {grid[j][0]=true; grid[j][height-1]=true;}
          for (int j=0; j<height-1; j++)
                {grid[0][j]=true; grid[width-1][j]=true;}
               
          for (int i=0; i<amtSprites; i++){
                sprite[i].updateMap(grid, amtSprites);
                sprite[i].updatePosition();}
          hero.updateMap(grid, amtSprites);
         
          layer2.setObstruction(grid);
             }

  public void start() {
          showStatus("Starting Game!");
          animation = new Thread(this);
           if (animation != null) {
                   animation.start();
                 }
              }
             
  public void update(Graphics g) {// override update so it doesn't erase screen
          paint(g);
              }

  public void paint(Graphics g) {
          offscreen.setColor(Color.black);
          offscreen.fillRect(0,0,width,height);  // clear buffer
          updateImages();
          layer2.paint();
          hero.paint(offscreen);
          for (int i=0; i<amtSprites; i++){
                  sprite[i].paint();
                  if (sprite[i].messageNumber!=-4)
                        spriteNumber=i;
                  }
            sprite[spriteNumber].say(" The completed argument to the end method tells whether or not the I/O operation actually completed, that is, whether it had any effect that would be visible to the invoker. In the case of an operation that reads bytes, for example, this argument should be true if, and only if, some bytes were actually transferred into the invoker's target buffer.A concrete channel class must also implement the implCloseChannel method in such a way that if it is invoked while another thread is blocked in a native I/O operation upon the channel then that operation will immediately return, either by throwing an exception or by returning normally. If a thread is interrupted or the channel upon which it is blocked is asynchronously closed then the channel's end method will throw the appropriate exception. ");
          g.drawImage(image,0,0,this);
              }

  public void run() {
          while (true) {
                  repaint();
                  try {
                   Thread.sleep (REFRESH_RATE);
                  } catch (Exception exc) { };
                }
              }
             
  public void stop() {
          showStatus("Game Stopped");
          if (animation != null) {
                  animation.stop();
                  animation = null;
                }
              }


//HANDLE IMAGES
  public void updateImages(){

              for (int i=0; i<amtSprites; i++)
              {
                    if(sprite[i].messageNumber==-4)
                          sprite[i].update(sprite, i);
                    sprite[i].updatePosition();
              }
              hero.update(sprite);
   }

  public void extractImages(Image strip,Image images[][],int num_images,int croppedWidth,int croppedHeight, int spriteSet)
  {
        ImageProducer producer;
    ImageProducer source = strip.getSource();
    int startingY=0;
    if (spriteSet>4){
          spriteSet=spriteSet%4; startingY=4*croppedHeight;}
    int startingX=(spriteSet*(3*croppedWidth))-(3*croppedWidth);
    for (int i = 0; i<num_images/4; i++) {
          for (int j=0;j<num_images/3; j++){
                  ImageFilter extractFilter = new CropImageFilter(startingX+(i*croppedWidth),startingY+(j*croppedHeight),croppedWidth,croppedHeight);
                  producer = new FilteredImageSource(source,extractFilter);
                  // extract the subimage
                  images[i][j] = createImage(producer);
                  t.addImage(images[i][j], 0);
          }
    }
   
  }
 
 
  public void loadImages() {
    t = new MediaTracker(this);
         Image strip;
    int num_images=12;
   
    //Load Layer1
          strip=getImage(getCodeBase(), "sprites/layer.png");
          t.addImage(strip, 0);
          layer2=new Layer2(this, strip, offscreen);
         
         
   
   
    //Load Hero
          strip = getImage(getCodeBase(),"sprites/Chara1.png");
          t.addImage(strip, 0);
          // define array of constituent images
          images = new Image[num_images/4][num_images/3];
          extractImages(strip,images,num_images,24,32, 1);
          hero = new Hero(600,400,images,this);
         
    //Load Enemies
                 
    //Load NPCs
     for (int i=0; i<amtSprites; i++){
            strip = getImage(getCodeBase(),"sprites/Chara1.png");
          t.addImage(strip, 0);
          images = new Image[num_images/4][num_images/3];
          extractImages(strip,images,num_images,24,32, (int)(Math.random()*7+1));
          sprite[i] = new Sprite(10,300,images,this, offscreen, hero);
         
         
         
         
         
         
         
          Image face=getImage(getCodeBase(), "Faces/hero1.png");
           
            ImageProducer producer;
          ImageProducer source = face.getSource();
         
                  ImageFilter extractFilter = new CropImageFilter(0,0,47,47);
                  producer = new FilteredImageSource(source,extractFilter);
                  // extract the subimage
                  face = createImage(producer);
                  t.addImage(face, 0);
          sprite[i].face=face;
           
           
           
           
           
           
           
           
           
           
           
           
           
           
            }
                 
      //Wait for all images to finish loading
          try {
                  t.waitForAll();
                }  catch (InterruptedException e) {}
            if (t.isErrorAny()) {
                  showStatus("Error Loading Images!");
                }
          else if (t.checkAll()) {
                  showStatus("Images successfully loaded");
                    }
        }
             
        public int[] spritex=new int[amtSprites];
        public int[] spritey=new int[amtSprites];
         
//HANDLE INPUT  
    public void keyTyped(KeyEvent e)  {}
    public void keyReleased(KeyEvent e)
          {
                hero.key[e.getKeyCode()]=false;
                hero.enableActionKey=true;
          }
      public void keyPressed(KeyEvent e)
            {hero.key[e.getKeyCode()]=true;}
           
}


for the main game loop.  If you need me to list my sprite and hero class code, please say so.. I figured this class is my problem since the error is "error finding class VideoGame".
Any ideas as to what I should change to make this more compatible with other machines?  I've tried downloading the latest JRE in all instances, and again, it works sometimes and not other times.  I hear that bufferedimage causes some compatilibity issue and that you need to get a screen context, do you need to do something similar with images?
Also, I've implemented obstructions based on boolean values that are set in layer2 if the region is not transparent.  This works perfectly on my computer, but when I save it to a jump drive it doesn't work on any other computer on which the game DOES work (including my own, actually).  Do I need to set bufferedImage up in some way to ensure compatibility?  here is my layer2 code for setting up the 2d boolean array for true/false regions (on the true regions, the characters can't walk):

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  
import java.awt.*;
import java.applet.Applet;
import java.awt.image.BufferedImage;

public class Layer2
{
      Applet applet;
      BufferedImage bimage;
      int width, height;
      int alpha;
      Graphics g;
      Image image;
      String debugString;
     
      public Layer2(Applet a, Image i, Graphics g)
      {      this.g=g;
            this.applet=a;
            width=a.getWidth(); height=a.getHeight();
            bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
            image=i;
            g = bimage.createGraphics();
            g.drawImage(image, 0, 0, applet);
           
           
      }
     
      public void setObstruction(boolean[][] grid)
            {for (int i=0; i<width; i++)
            {for (int j=0; j<height; j++)
            {alpha = (bimage.getRGB(i,j) >>> 24);
            if (alpha==255)
                  grid[i][j]=true;
      }}}
           
      public void paint()
      {
            g.drawImage(image, 0,0, applet);
    }
}


Long post, cootos to whoever has the patience to bear through this one.
17  Java Game APIs & Engines / Java 2D / Re: Get pixel color from Image *resolved* on: 2005-03-31 18:12:15
me too, thanks a lot bro!
18  Java Game APIs & Engines / Java 2D / Re: Get pixel color from Image on: 2005-03-30 22:37:24
getRGB returns an int... how can you determine whether or not that int represents transparentcy? do you have to use bitwise operators to extract byte values into individual ints?  

I'm new to bufferedImage, and for how long I've been trying to figure it out in the API docs, i've had to put it off while I work on another feature in hopes that I'll understand a bit more about java so as to use bufferedImage when I return to it.
So how exactly can one determine if an x,y coord is transparent on a bi?
19  Java Game APIs & Engines / Java 2D / what does pixelgrabber return? on: 2005-03-26 15:31:03
Newb question #3
Right now I have a 2d array of booleans for obstructions, grid[][].  Every x/y that's true is obstructed (can't walk there), and so far it's working great, but I have to manually set it each time.  I'm trying to figure out how to use pixelgrabber, but the tutorials expect you to know bitwise operations.  I read some tutorials on bitwise operations, and still couldn't understand it.
Anyway, what I want to do is draw a 2nd layer, on that has trees, walls, tables, etc... obstructable tiles.  Then I want pixelgrabber to tell me which pixels have a color (anything other than translucent) and set that pixel in grid[][] to true.

after I do this jazz:
public void handlesinglepixel(int x, int y, int pixel) {
       int alpha = (pixel >> 24) & 0xff;
       int red   = (pixel >> 16) & 0xff;
       int green = (pixel >>  Cool & 0xff;
       int blue  = (pixel      ) & 0xff;

i'm lost.  How, for example, can I test if the present pixel has alpha?  Am I dealing with ints that have separated the byte value for each pixel int? wh... i.... i guess i just don't... confused!
20  Java Game APIs & Engines / Java 2D / Re: a gui game engine that saves your files? on: 2005-03-24 19:50:51
it still sounds ropey, eh?  Well, let me try one more time to explain exactly what I'm trying to do.  Don't feel obligated to find out how to do it, you answered the question exactly with that last link, and thank you very much.
Anyway, as an example if I wanted to create an applet with hundreds of components (myriads of different buttons, images, sliders, etc) then it would be MUCH easier and time saving to do that through a gui like borland Jbuilder, instead of programatically.  Similarly, I want to make a game that reuses certain classes (sprites, background, tiles, etc).  If i wanted to make a full game, it would take FOREVER to do the whole thing programatically, and it would be a tedius copy/paste/modify exercise.  So I want to make a "borland Jbuilder" so to speak, a gui that makes a separate program.  When you save your java file in jbuilder, it doesn't save it as part of jbuilder, but a completely separate .java.  Similarly, I want to use my gui.java to save a project that I could later modify called game.java.
An example is RPGMaker 2000 (http://www.gfxartist.com/features/articles/279).  in rm2k you select a sprite and drop it onto a canvas, then you select a portion of the canvas to fill with a certain tile, etc.  you specify where you're main character will start, what certain events are invoked by certain actions, etc... finally, you save your project and run it.  It's more work to begin with to actually MAKE rpgmaker 2000 than it would be to simply program a small game, but when the games start getting bigger it saves time this way.  Does that make more sense?
21  Java Game APIs & Engines / Java 2D / Re: a gui game engine that saves your files? on: 2005-03-24 19:17:23
Kev, may the hair on your feet never fall out.  That answered my question exactly.
22  Java Game APIs & Engines / Java 2D / Re: a gui game engine that saves your files? on: 2005-03-23 17:09:02
That would be great if I could do that!
for the life of me i can't find info on the subject dumbed down enough for me to understand (the tools.jar that is, i couldn't figure out how to use it to save files, only to archive them).
Basically my gui will be a .java that creates a different .java (and hopefully, like you said, compiles and runs it too).  I'll use the gui to modify variables, then once the user hits "save" those variables will be inserted into a template, and that now modified template is saved as its own .java, without saving any of the gui information (except of course the modified info used in the template).
if that is indeed what tools.jar does, know of any sites or documentation on the subject?
Thanks once again kev, you are being most helpful!
23  Java Game APIs & Engines / Java 2D / a gui game engine that saves your files? on: 2005-03-22 20:16:04
I asked this in another post, but I don't think I expressed it very well... so now that I have time I'll try again.

I'm using borland to create a gui that will be something like RPGMaker2000.  Via widgets I will manipulate how the game looks, where sprites go, what tilesets go in which rooms, etc.  When I'm done creating my game, I want to save it as a game class that extends applet, implements runnable, etc.  I was thinking, the "save" button could save a text file that writes out all the stuff that's not varialble, like:
out.println("import java.awt.*; import java.applet.*;... public class videoGame extends...")
then I'd concatonate variables in that I changed in the gui.  When all is done, it would be saved as a text that I could just change the extension to .java and compile and go.

Anyway, the idea is stupid, but hopefully that will give you a better idea of what exactly I'm trying to do. Basically I'm trying to either save a complete java project (not just text or object data binaries) that ISN'T the java project I'm presently in (which is the gui), or manipulate a template that would have all the stuff i need for this game and I could just change the variables.  I'm dumb, and all I know about regarding template manipulation is random access, which wouldn't work because it requires that the input be the exact same length in terms of letters as the template.

Any ideas?
24  Java Game APIs & Engines / Java 2D / Re: Holding the arrowkey down? on: 2005-03-22 19:49:33
alright, next question:

I figured out 2key, obstructions, good sprite anim and battle system.  Now I want to make a gui engine to build my game.  I was thinking of using PrintWriter and making a text file with every bit of info (info being modified in the gui), but that was stupid because within the out.println("blablabla"); is bound to be plenty of "s and \s and stuff that will ruin everything.

Any ideas or quick references to sites/tutorials/threads on the making a game engine?
25  Java Game APIs & Engines / Java 2D / Re: Sprite Sheet on: 2005-03-21 17:34:28
how do you chop up peices of an image and store them as separate images anyway?
26  Java Game APIs & Engines / Java 2D / Re: Holding the arrowkey down? on: 2005-03-21 12:41:23
You're the man Kev.  and that link you just gave me answers my second question about pushing 2 buttons at once!
27  Java Game APIs & Engines / Java 2D / Holding the arrowkey down? on: 2005-03-21 02:15:42
I deserve burning for my newbness, but I figure for the time I spend searching through the different tutorials, each with its pros and cons, I'd rather be flamed for the stupid questions I ask on forums.  So I think I'll start a thread of stupid questions for those of you kind enough to answer.

My first question is about holding the key down to move my char (in an rpg).  You know how in windows when you hold the key down it kinda has a slow start then it goes really fast?  how can i overcome that?
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (71 views)
2014-11-26 15:22:04

toopeicgaming1999 (60 views)
2014-11-26 15:20:36

toopeicgaming1999 (14 views)
2014-11-26 15:20:08

SHC (27 views)
2014-11-25 12:00:59

SHC (25 views)
2014-11-25 11:53:45

Norakomi (31 views)
2014-11-25 11:26:43

Gibbo3771 (25 views)
2014-11-24 19:59:16

trollwarrior1 (38 views)
2014-11-22 12:13:56

xFryIx (77 views)
2014-11-13 12:34:49

digdugdiggy (55 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!