Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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  Game Development / Newbie & Debugging Questions / Re: Starting to make a game on: 2010-04-14 19:00:29
Everyone I thank you from the bottom of my heart, you guys are awesome.
I used buffered image and changed the observer to null, and now it runs smoothly.
My brother sure will be happy ^^
THANK YOU ONCE AGAIN
Of course first I will give him the present once I finish designing the levels and then I will post a copy of the game here later on
THANK YOU ^^  Smiley
2  Game Development / Newbie & Debugging Questions / Re: Starting to make a game on: 2010-04-14 18:21:13
Well in the skeleton where I have *start drawing
right in between there I put this in

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
g.drawImage(sky.getImage(), 0, 0, this);
       
        for(int i=0; i<background.length; i++)
        {
           g.drawImage(background[i].getImage(), background[i].getX(), background[i].getY(), this);
        }
       
        for(int i=0; i<wall.length; i++)
        {
           g.drawImage(wall[i].getImage(), wall[i].getX(), wall[i].getY(), this);
        }
       
        for(int i=0; i<platform.length; i++)
        {
           g.drawImage(platform[i].getImage(), platform[i].getX(), platform[i].getY(), this);
        }
       
        g.drawImage(hero.getImage(), hero.getX(), hero.getY(), this);


Thanks to everyone for helping ^^
3  Game Development / Newbie & Debugging Questions / Re: Starting to make a game on: 2010-04-14 18:07:06
Ok I am very sorry about that  Undecided  Cry
Promise I won't do it again ><

As to answer your question teletubo I load png into ImageIcon and then load it into Image like so

1  
2  
ImageIcon ii = new ImageIcon(this.getClass().getResource("images/objects/"+sprite+".PNG"));
image = ii.getImage();


And everything including platforms, main character and monsters is loaded same way

For example this is my platform class

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  
package MediumFullScreen;
import java.awt.Image;

import javax.swing.ImageIcon;


public class Wall
{
   private Image image;
   private double x, y;
   private double leftOffset, rightOffset, topOffset, bottomOffset;
   private int width, height;
   private static int WIDTH, HEIGHT;
   
   // set the screen  parameters, if object goes out of screen it becomes null
   public static void setScreen(int width, int height)
   {
      WIDTH = width;
      HEIGHT = height;
   }
   
   public Wall(String sprite)
   {
      ImageIcon ii = new ImageIcon(this.getClass().getResource("images/objects/"+sprite+".PNG"));
      image = ii.getImage();

      width = image.getWidth(null);
      height = image.getHeight(null);
     
      x = 0;
      y = 0;
     
      leftOffset = 0;
      rightOffset = 0;
      topOffset = 0;
      bottomOffset = 0;
   }
   
   public Wall()
   {
      image = null;
     
      width = 0;
      height = 0;
     
      x = 0;
      y = 0;
     
      leftOffset = 0;
      rightOffset = 0;
      topOffset = 0;
      bottomOffset = 0;
   }
   
   public Wall(Image img)
   {
      image = img;
     
      width = image.getWidth(null);
      height = image.getHeight(null);
     
      x = 0;
      y = 0;
     
      leftOffset = 0;
      rightOffset = 0;
      topOffset = 0;
      bottomOffset = 0;
   }
   
   public Image getImage()
   {
      if(x<=WIDTH && x+width>=0 && y+height>=0 && y<=HEIGHT)
         return image;
      return null;
   }
   
   public void setOffset(int topOffset, int bottomOffset, int leftOffset, int rightOffset)
   {
      this.topOffset = topOffset;
      this.bottomOffset = bottomOffset;
      this.leftOffset = leftOffset;
      this.rightOffset = rightOffset;
   }
   
   public int getBottomY()
   {
      return (int)(y+height-bottomOffset);
   }

   public int getLeftX()
   {
      return (int)(x+leftOffset);
   }

   public int getRightX()
   {
      return (int)(x+width-rightOffset);
   }

   public int getTopY()
   {
      return (int)(y+topOffset);
   }

   public int getHeight()
   {
      return height;
   }

   public int getWidth()
   {
      return width;
   }

   public int getX()
   {
      return (int)x;
   }

   public int getY()
   {
      return (int)y;
   }

   public void setHeight(int height)
   {
      this.height = height;
   }

   public void setWidth(int width)
   {
      this.width = width;
   }

   public void setX(double x)
   {
      this.x = x;
   }

   public void setY(double y)
   {
      this.y = y;
   }
}


And the problem is that once I reach 30 images, then the whole game lags out. So is there a better way to load them? Maybe using something else?
4  Game Development / Newbie & Debugging Questions / Starting to make a game on: 2010-04-14 17:15:23
Ok I know I have been pretty much spamming all the forums asking for help lately and I am very sorry for that.
The problem is that my younger bros birthday is on may 7th and for the last 2 months I have been hell bent into making him a game (he had some health implications so I wanna cheer him up). If you want proof of what I did for the last 2 months I will gladly provide it. Anyways the problem is that I have hit a brick wall. My engine works, and all the mechanics are there. But I can not find a single tutorial anywhere that will teach me how to draw png(I already made a huge library of them) images to the screen without them lagging crazily.
Now I do not want to use pre build engines or anything like that. I want this to be my own work made by me from ground up, otherwise the present will not feel as good.
Anyways if someone could please redirect me or show me some kind of tutorial where I can draw images onto the screen efficiently I will be forever grateful to you.

Currently in the last 2 months I came up with these 4 skeletons on where everything is located

Skeleton 1 http://pastebin.com/RjRDfU9V
Skeleton 2 http://pastebin.com/kpxGZA0z
Skeleton 3 http://pastebin.com/V6Jy9470
Skeleton 4 http://pastebin.com/6eWf0fzG

I tried using g.drawImage but the game starts lagging, if I replace everyimage with fillRect it works super fast and smooth, so I know the issue is drawing.

Thanks to anyone who will help ^^
5  Game Development / Newbie & Debugging Questions / Please help me with slick on: 2010-04-14 16:18:28
Sorry if I sound raged but I spent the last 3 hours trying to fix

Version mismatch: jar version is '22', native libary version is '16'

If anyone has ever used slick please do tell me what to do, I am going nuts here
6  Java Game APIs & Engines / Java 2D / Re: How to draw png images to the screen efficiently? on: 2010-04-14 14:43:44
Thank you very much for your help. I looked at slick, and it looks pretty good, but being the noob that I am, I was wondering if there were any tutorials on how to work with it?
Also is slick the only alternative I am faced with?
7  Java Game APIs & Engines / Java 2D / How to draw png images to the screen efficiently? on: 2010-04-14 13:58:55
Hello everyone, sorry if this question sounds too nooby, but how would you draw png images in the game without it lagging. I tried to use drawImage, but it caused HUGE lag when number of pctures increased.

This is my code skeleton here

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  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
package attempt1;

import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.DisplayMode;
import java.awt.Graphics2D;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.image.BufferStrategy;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main implements Runnable
{
   private int WIDTH = 1000;
   private int HEIGHT = 500;
   private long desiredFPS = 60;
   
   private String title = "Maple Story";
   
   private long desiredDeltaLoop = (1000*1000*1000)/desiredFPS;
   private boolean running = true;
   
   private JFrame frame;
   private Canvas canvas;
   private BufferStrategy bufferStrategy;
   
   private GraphicsDevice graphicsDevice;
   private DisplayMode originalDisplayMode;
   
   public Main()
   {
      GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
      graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();
      originalDisplayMode = graphicsDevice.getDisplayMode();
     
      // create new Frame
      frame = new JFrame(title);
      frame.setUndecorated(true);

      graphicsDevice.setFullScreenWindow(frame);
      if (graphicsDevice.isDisplayChangeSupported())
      {
         graphicsDevice.setDisplayMode(getBestDisplayMode(graphicsDevice));
      }
     
      Rectangle bounds = frame.getBounds();
      WIDTH = (int)bounds.getWidth();
      HEIGHT = (int)bounds.getHeight();      
     
      // create new JPanel with specified width and height
      JPanel panel = (JPanel) frame.getContentPane();
      panel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
      panel.setLayout(null);
      // create a canvas inside the JPanel with specified width and height
      canvas = new Canvas();
      //canvas.setBounds(0, 0, WIDTH, HEIGHT);
      canvas.setBounds(bounds);
      canvas.setIgnoreRepaint(true);
     
      panel.add(canvas);
      // Add Mouse and Key Listeners
      canvas.addMouseListener(new MouseControl());
      canvas.addKeyListener(new KeyInputHandler());
      // initialize the window
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.pack();
      frame.setResizable(false);
      frame.setVisible(true);
     
      setup();
      // set graphics device
      canvas.createBufferStrategy(2);
      bufferStrategy = canvas.getBufferStrategy();
      // focus on the window
      canvas.requestFocus();
   }
   /*
    * Main game loop
    */

   public void run()
   {
      long beginLoopTime;
      long endLoopTime;
      long currentUpdateTime = System.nanoTime();
      long lastUpdateTime;
      long deltaLoop;
     
      while(running)
      {
         beginLoopTime = System.nanoTime();
         
         render();
         
         lastUpdateTime = currentUpdateTime;
         currentUpdateTime = System.nanoTime();
         update((int) ((currentUpdateTime - lastUpdateTime)/(1000*1000)));
         
         endLoopTime = System.nanoTime();
         deltaLoop = endLoopTime - beginLoopTime;
           
           if(deltaLoop > desiredDeltaLoop)
           {
               //Do nothing. We are already late.
           }
           else
           {
               try
               {
                   Thread.sleep((desiredDeltaLoop - deltaLoop)/(1000*1000));
               }
               catch(InterruptedException e)
               {
                   //Do nothing
               }
           }
      }
   }
   /*
    * Method to initialise graphics that are going to be painted to the screen
    */

   private void render()
   {
      Graphics2D g = (Graphics2D) bufferStrategy.getDrawGraphics();
      g.clearRect(0, 0, WIDTH, HEIGHT);
      render(g);
      g.dispose();
      bufferStrategy.show();
   }
   /*
    * Initialise all of your Objects in here
    */

   public void setup()
   {
     
   }
   /*
    * Method that handles all the movements that are supposed to happen
    * So initialise all the x and y changes here
    * deltaTime tells you how many nanoseconds have passed by since this function
    * was last called
    */

   protected void update(int deltaTime)
   {
     
   }
   /*
    * Method where you paint to the screen
    */

   protected void render(Graphics2D g)
   {
      /*
       * START PAINTING
       * START PAINTING
       * START PAINTING
       * START PAINTING
       * START PAINTING
       * START PAINTING
       */


     
     
      /*
         * STOP PAINTING
         * STOP PAINTING
         * STOP PAINTING
         * STOP PAINTING
         * STOP PAINTING
         * STOP PAINTING
         */

   }
   /*
    * Keyboard Action listeners
    * Key esc closes the program by default
    */

   private class KeyInputHandler extends KeyAdapter
   {
      public void keyPressed(KeyEvent e)
      {
         if(e.getKeyCode()==27)
           {
            graphicsDevice.setDisplayMode(originalDisplayMode);
            graphicsDevice.setFullScreenWindow(null);
              System.exit(0);
           }
      }
     
      public void keyReleased(KeyEvent e)
      {
         
      }
   }
   /*
    * Mouse Action Listeners
    */

   private class MouseControl extends MouseAdapter
   {
     
   }
   /*
    * public static void main
    * I do not even have to explain this
    */

   public static void main(String [] args)
   {
      Main ex = new Main();
      new Thread(ex).start();
   }
   
   private static DisplayMode MODES[] = new DisplayMode[]
   {
      new DisplayMode(640, 480, 32, 0), new DisplayMode(640, 480, 16, 0),
       new DisplayMode(640, 480, 8, 0)
   };

   private static DisplayMode getBestDisplayMode(GraphicsDevice device)
   {
      for (int x = 0, xn = MODES.length; x < xn; x++)
      {
         DisplayMode[] modes = device.getDisplayModes();
         for (int i = 0, in = modes.length; i < in; i++)
         {
            if (modes[i].getWidth() == MODES[x].getWidth() && modes[i].getHeight() == MODES[x].getHeight() && modes[i].getBitDepth() == MODES[x].getBitDepth())
            {
               return MODES[x];
            }
         }
      }
      return null;
   }
}


So what would you suggest I use to draw png images?
I heard that BufferedImage is good, but I have failed miserably at using it, because it does not seem to have same properties as Image, especially when it comes to getWidht and getHeight commands.
Thanks to everyone for help in advance ^^
8  Game Development / Game Mechanics / Re: Only checking for 2D collision that matters on: 2010-04-13 03:11:03
So which rendering method should I use?
I kinda threw it together, but having had no classes in my university that deal with drawing to screen, I do not know anything.
Thanks a lot to everyone's help, my brother will be very happy
9  Game Development / Game Mechanics / Re: Only checking for 2D collision that matters on: 2010-04-12 16:52:52
Ok so this is my main character class

http://pastebin.com/1pzgGTVq

And this is my main class where I draw all the images, and as soon as I get more than 30 lag begins.

http://pastebin.com/0yvS3Nhs

And this is my Wall class just in case you were wondering

http://pastebin.com/mz6ra3Kd

Sorry I am off to write exam on java, so I will read this once I get back home in about 7 hours.

But thank you very much for all of your help Orangy Tang, you are awesome.
The only reason why I tried to tackle this project is  because I want to make a mario based game for my younger brother's birthday, but I hit a brick wall.
Thanks a lot again
10  Game Development / Game Mechanics / Re: Only checking for 2D collision that matters on: 2010-04-12 16:16:11
Yeah I meant 30 walls pretty much, anything beyond that shows a great slowdown. My wall is just an object which has an image, and x and y and width and height, and from there I get the rest. Also they are located freely, so I will probably end up using Quad trees.
By any chance would happen to have an example code or some explanation of how that might speed up things? Because I looked at it, and got the idea but I am still not understanding how its going to speed up the process. Because how I see it, is that quad tree would first check everything to see where I am located and then check the objects in that vicinity for collision, which still pretty much does what my for loop does. I mean probably by employing it, I will be able to go from 30 walls to maybe 60 walls without a slowdown, but is that the limit I will have to face? I mean how in the world do games like maple story (sorry for bad example) or mario have so many objects working all at once. I am pretty sure they got more than 60 objects.
Or would you suggest that I switch to the array method to speed things up.
11  Game Development / Game Mechanics / Re: Only checking for 2D collision that matters on: 2010-04-12 15:58:43
This is my code
Its probably pretty crazy, hope you guys will understand it.
But yeah pretty much my for loop is too long

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  
   public void move(Wall walls[]])
   {
      standing = false;
      for(int i = 0; i<walls.length; i++)
      {
         // sideways collision
         if(walls[i].getTopY()<this.getBottomY()-6 && walls[i].getBottomY()>this.getTopY())
         {
            if(walls[i].getRightX()>=this.getLeftX() && walls[i].getRightX()<=this.getLeftX()-dx)
            {
               //System.out.println("Hit from right (object to your left) on a wall");
               x = walls[i].getRightX()+5-leftOffset;
               dx = 0;
            }
            else if(walls[i].getLeftX()<=this.getRightX() && walls[i].getLeftX()>this.getRightX()-dx)
            {
               //System.out.println("Hit from left (object to your right) on a wall");
               x = walls[i].getLeftX()-5-image.getWidth(null)+rightOffset;
               dx = 0;
            }
         }
         //if statement for falling down and detecting collision from top or bottom of object
         if(walls[i].getLeftX()<this.getRightX() && walls[i].getRightX()>this.getLeftX())
         {
            // hitting a wall from top
            if(walls[i].getTopY()<this.getBottomY() && walls[i].getTopY()>this.getBottomY()-dy && dy>=0)
            {
               //System.out.println("Landed on a wall");
               standing = true;
               hit = false;
               y = walls[i].getTopY()-this.getHeight()+1+bottomOffset;
               dy = 0;
            }
            else if(walls[i].getBottomY()>=this.getTopY() && walls[i].getBottomY()<this.getTopY()-dy && dy<=0)
            {
               //System.out.println("Hitting head on ceiling of a wall");
               y = walls[i].getBottomY()-topOffset;
               dy = 0;
            }
            else if(walls[i].getTopY()<this.getBottomY() && walls[i].getTopY()>this.getTopY() && dy>=0)
            {
               //System.out.println("Standing");
               standing = true;
               hit = false;
               y = walls[i].getTopY()-this.getHeight()+1+bottomOffset;
               dy = 0;
            }
         }
      }
     
      if(!standing)
      {
         //System.out.println("Falling");
         dy = dy+GRAVITY;
      }
      y += dy;
      x += dx;
   }



And what did you mean by buckets SimonH?
12  Game Development / Game Mechanics / Only checking for 2D collision that matters on: 2010-04-12 15:31:54
Hello, I am a complete newb in this forum and in java gaming in general. Reason why I started java gaming is because JAVA IS THE FUTURE
ok so with that out of the way I have a question.
I have made simple 2D java game, and for collision detection I use AABB(bounding box) method, and it was working just fine, as long as the amount of objects I used was below 30. But now that my map got bigger, the method checks for collision of every single object with main character and its slowing down the gameplay greatly.
So I was wondering how to do collision detection with objects that are in close proximity of main character rather than all the objects on map.
If someone could guide me to a great collision detection tutorial, I would be ever so thankful.
All my collision detection knowledge came only from http://www.metanetsoftware.com/technique/tutorialA.html

Thanks in advance to all who help ^^
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.

Longarmx (42 views)
2014-10-17 03:59:02

Norakomi (33 views)
2014-10-16 15:22:06

Norakomi (26 views)
2014-10-16 15:20:20

lcass (30 views)
2014-10-15 16:18:58

TehJavaDev (60 views)
2014-10-14 00:39:48

TehJavaDev (60 views)
2014-10-14 00:35:47

TehJavaDev (50 views)
2014-10-14 00:32:37

BurntPizza (66 views)
2014-10-11 23:24:42

BurntPizza (38 views)
2014-10-11 23:10:45

BurntPizza (80 views)
2014-10-11 22:30:10
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!