Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Newbie learning java by writing simple game engine using Eclipse - help needed.  (Read 2303 times)
0 Members and 1 Guest are viewing this topic.
Offline zerodivisible

Junior Newbie





« Posted 2010-06-26 11:16:23 »

Hello,

Firstly, I would like to write that English is not my first language and I am sorry for all the mistakes.

I am trying to learn Java and I thought, that it would be great if I could write a rather simple game engine - nothing too fancy but on the other hand it would be great if this engine would be a reusable base for few simple games, just to polish my skills. Everything was working fine up to a point - and I don't know right now where I made a mistake.

The problem is, that the main frame is not updating nor redrawing - it shows up when I lanuch the project from eclipse but I can't kill or close it; only stoping the application with the red "Terminate" button in Ecplise.

This is my current eclipse project for this engine - I am using maven for dependency management so I think that this is the only requirement for launching it.

I know that the code is not of the highest quality and there are lots of logical flaws in design but as I had stated - I am just learning. If anyone would have time to check this, I would be very grateful.

Offline DavidX

Senior Newbie





« Reply #1 - Posted 2010-06-26 14:33:57 »

please, create games not game engines.
Offline zerodivisible

Junior Newbie





« Reply #2 - Posted 2010-06-26 15:57:52 »

Hello DavidX and thanks for suggestion, but if I would like to be honest, I think, that I should disagree with You;)

Firstly, when I thought about learning Java, I was thinking something similar to "Hey, I will use the slick engine and try to create some simple 2d game". But after trying to use it, I noticed that I am not understanding Java - I was trying to understand Slick and that was not my objective.

I am almost sure, that my first bigger project will be written in some of the existing frameworks / engines but for now I just keep slick sources as a reference.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DavidX

Senior Newbie





« Reply #3 - Posted 2010-06-26 16:25:09 »

in reply to your question - do you have an infinite loop anywhere? that is probably whats causing it
Offline zerodivisible

Junior Newbie





« Reply #4 - Posted 2010-06-26 16:42:31 »

Yes, there is an infinite loop in my Kernel class, which should fire all the tasks for the game engine - time updating, reading input, game state updating, etc.

The problem is, that the Swing frame is not rendering its contentPane. The sources which I posted are from the version which uses

Quote
1  
setIgnoreRepaint(true);
so I should manually repaint the components. Even if I call repaint() from the MainFrame, its contentPane (which is a class subclassing JPanel) are not updating/redrawing.

Offline DavidX

Senior Newbie





« Reply #5 - Posted 2010-06-26 17:20:39 »

add System.out.println("paintEvent") in your render method and see how often it gets called
Offline zoto

Senior Member


Medals: 4



« Reply #6 - Posted 2010-06-26 21:25:08 »

Just quickly looking at the Kernal class I saw a few problems. In the run method you have a local variable called loops that is set to 0 and never changed. In the execute function I'm pretty sure calling remove in the new for loop like that throws an Exception, the easiest solution is to use an old for loop and either iterate backwards or decrement i after you remove an item to compensate.

Refactoring is probably a good idea especially if you are going to show your code to other people.
I would recommend renaming all your variables to more standard names, at least rename the one letter variables.
In the execute function you are iterating over the loop twice, when you should be using an else.
In the run method remove everything except the contents of the inner run function. Then where you call Kernal.run() change it to something like:
1  
2  
Thread thread = new Thread( new Kernal() );
thread.start();

As DavidX said use System.out.println to give you feedback on whats happening, you can also use try/ catch blocks and tools built into your IDE like breakpoints and memory viewer.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (32 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (40 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (25 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
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!