Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (121)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2] 3
  ignore  |  Print  
  Dreamscape  (Read 12800 times)
0 Members and 1 Guest are viewing this topic.
Offline ML-Deluxe

Senior Newbie


Medals: 1



« Reply #30 - Posted 2012-12-26 00:43:42 »

You have to pass your Runnable to the Thread as parameter

Thread thread = new Thread(this);

and start it just like this

gameWindow.startThread();

without:

gameWindow.run();

EDIT:
better do like this
instead of
1  
2  
 gameWindow.startThread();
               gameWindow.run();


put

1  
new Thread(new TestRender).start();
Offline tyeeeee1
« Reply #31 - Posted 2012-12-26 00:53:33 »

You have to pass your Runnable to the Thread as parameter

Thread thread = new Thread(this);

and start it just like this

gameWindow.startThread();

without:

gameWindow.run();

EDIT:
better do like this
instead of
1  
2  
 gameWindow.startThread();
               gameWindow.run();


put

1  
new Thread(new TestRender).start();


Could you explain a bit about what
1  
new Thread(new TestRender).start();
does, I prefer not to use things that I don't understand when I can help it. Your first answer fixed the problem though.
Offline ML-Deluxe

Senior Newbie


Medals: 1



« Reply #32 - Posted 2012-12-26 00:57:31 »

Look at the code, its exactly the same as before, just that the Thread is started from your other class. I edited it because (without knowing your architecture), it just felt a little more right to me Wink
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tyeeeee1
« Reply #33 - Posted 2012-12-26 01:05:47 »

Look at the code, its exactly the same as before, just that the Thread is started from your other class. I edited it because (without knowing your architecture), it just felt a little more right to me Wink

Thanks for the help.  Grin

While I've been waiting a few minutes in between page refreshes for the answer which you've provided I came up with yet another question to ask anyone reading. I've seen that without double buffering there is very noticeable (I'll describe it as stutter I guess) when for example, moving a string by -10 pixels per few milliseconds on an applet. Because of this stutter I noticed when working with an applet awhile ago I decided to look up some information about buffering in Java; In my little google search I ran across http://c2.com/cgi/wiki?DoubleBufferedGraphicsInJava which, in my opinion, basically said that double buffering is a waste of memory and that you shouldn't use it.
The previously linked (article?) made me a bit unsure about using a double buffer. Is a double buffer the best way to get rid of 'stutter'? 
Offline LunaticEdit
« Reply #34 - Posted 2012-12-26 02:00:38 »

I honestly haven't read the most of the earlier posts, but what I do is make my rendering logic part of a class that implements Runnable and extends Canvas. Then at program startup I create a JFrame, attach my rendering class to it (as it's a canvas), pack, show the frame, then start the render control as a thread:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
        final JFrame frame = new JFrame(GAME_TITLE);
        final MainWindow window = new MainWindow();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.add(window);
        frame.pack();
        frame.setVisible(true);
        frame.requestFocus();

        window.start();


The run has a loop in it (well, at the BASIC level it's a loop :p) that looks like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
       final BufferStrategy bs = getBufferStrategy();
        if (bs == null) {
            createBufferStrategy(2);
            return;
        }

        final Graphics g = bs.getDrawGraphics();
        // DRAW LOGIC HERE

        g.dispose();
        bs.show();
        bs.dispose();


Please note that this is inside of a render() type function, not inside the run() directly, so the "return" only leaves the local render function, not the top level loop.

CreateBufferStrategy does the best it can to double buffer using your system's hardware acceleration, but hides the actual implementation from you. You simply draw what you want in the DRAW LOGIC HERE part, and the rest will be flicker free. There is no memory wasted because, at least with my (2), it only has a couple buffers.

You may want to read up more on threads, and in particular implementing classes as Runnable. With that and a global ExecutorService object, you can have worry-free threading where needed with minimal coding.

Offline tyeeeee1
« Reply #35 - Posted 2012-12-27 00:22:26 »

Just managed to get keyboard controls working perfectly, now to figure out how collision works...
Offline tyeeeee1
« Reply #36 - Posted 2012-12-29 07:55:38 »

Not too much has been done in the past two days; I've spent around 5 or so hours attempting to figure out/implement collision but so-far my attempts have failed, if anyone can give me a few pointers it will be appreciated. Although I've not done too much I did manage to get keyboard controls working as I've previously stated and I've just recently expanded them so that you can move with either WASD or the Arrow keys.

 Grin
Offline tyeeeee1
« Reply #37 - Posted 2013-01-05 03:02:06 »

It took a small chunk of my Christmas vacation but I finally managed to figure out a way to draw a map onto the JPanel. There are a few bugs to iron out and a lot to expand on but at least the basic idea worked.  Grin
Offline matheus23

JGO Kernel


Medals: 109
Projects: 3


You think about my Avatar right now!


« Reply #38 - Posted 2013-01-05 20:18:45 »

Not too much has been done in the past two days; I've spent around 5 or so hours attempting to figure out/implement collision but so-far my attempts have failed, if anyone can give me a few pointers it will be appreciated. Although I've not done too much I did manage to get keyboard controls working as I've previously stated and I've just recently expanded them so that you can move with either WASD or the Arrow keys.

 Grin

Pretty simple actually... If you don't want to have fancy stuff with Polygons and rotation and what-not, simply use java.awt.Rectangle. To test whether two rectangles collide use
rect0.intersects(rect1);
.

I guess this should help you Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline doos

Senior Duke


Medals: 2
Projects: 2


Here be random


« Reply #39 - Posted 2013-01-05 22:58:08 »

For collision, there is also checking the hypoteneuse for circle-circle collision.. Depends on what shapes are being collided with.

(radius circle A + radius circle B)^2 < (x1-x2)^2 + (y1-y2)^2

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tyeeeee1
« Reply #40 - Posted 2013-01-10 01:28:34 »

Thanks for the collision tips. Over the past few days I've been thinking about easy ways to create a map and load it, after a bit of thought I decided that creating a text document with numbers to reference specific tiles would be best; After that I took some time tonight and figured out how to read from a text document and sort the tiles quickly.
Now to write and test the actual tile loading!

Edit: It just occurred to me that loading a map this way, due to it's simplicity, would actually allow me to create a simple map editor very easily. I <3 Getting ideas from random places!
Offline tyeeeee1
« Reply #41 - Posted 2013-01-24 23:15:59 »

I'm back from my little two week long Java break. I'm more-or-less just throwing around random ideas of how to do things and that now. So-far tonight I've started writing a class to create and save JPanels and JButtons so they don't need to be re-created every time you move from menu to menu.
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #42 - Posted 2013-01-25 00:29:05 »

Why are you recreating them in the first place? Your JButtons/JPanels should be class fields, and you can just add/remove them at will.
Offline tyeeeee1
« Reply #43 - Posted 2013-01-25 16:46:48 »

Why are you recreating them in the first place? Your JButtons/JPanels should be class fields, and you can just add/remove them at will.

Someone told me that I should create every menu on a different JPanel because it's a better way to do it, that's why. It seems like everyone else thinks that it's a bit of a ridiculous idea so I'll drop it.
Offline Cero
« Reply #44 - Posted 2013-01-25 21:04:19 »

fyi I never ever used Panel/JPanels
not saying you shouldn't, but I never saw the point =>

Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #45 - Posted 2013-01-26 17:08:50 »

Its not much of a hassle for Java to create a JPanel a few times. You shouldn't spend time trying to optimize before you see a need to. If it's not lagging or slowing you down, don't try to optimize it.

I use the approach you're talking about, where I have each view/menu on separate JPanels. It works like a charm, and it is very easy to control. But you're removing buttons and such when certain buttons are clicked, like in the actionlistener on the continue-button.

Instead, you could try a very different approach. The menus could be on several JPanels, which you can switch between by simply changing the contentpane on your gameframe. Roll in the menu on its own panel, menuPanel, and then when a button is pressed and all the needed information to start the game is in order, you change the contentPane of your frame from menuPanel to a new gamePanel, which handles rendering of the game.

If you want, you can add even more panels on top of your gamePanel...the frame won't mind. So if you want in-game menus, you're free to use Swing for those, without having to kill the gamePanel. You can even spawn extra JPanels IN your gamePanel!


About your buttons, I think they look fine. Actually, they're spectacular for a Paint-job. They might benefit from a little blur on the edges, but what would REALLY help them, is if they weren't on a monotonous grey background. The surrounding colors make a huge difference to an image (which is why AmbiLight is popular for TVs).

I did some quick n' dirty image editing to put your button on a vibrant game, so you can see what I mean. When surrounded by colors and graphics that aren't as unnatural as a completely monotonous grey, the pixelated edges even seem to give the button a more realistic look, than if it were blurred. Maybe a mix of the two approaches would be more spot on?

- Jonas
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #46 - Posted 2013-01-26 17:22:42 »

I didn't mean not to use different JPanels, I meant there's no need to "save" GUI components, if that's the case you need to fix your scope/access problems.
@Ultroman: Tyrian Grin
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #47 - Posted 2013-01-26 18:26:17 »

I agree.

And yes...TYRIAN! With hotdog guns!

- Jonas
Offline tyeeeee1
« Reply #48 - Posted 2013-01-26 19:14:41 »

Hmm... I'll do a bit of messing around with JPanels and the button does look pretty good with more color, thanks!

Now for a small update; I've finally found out how to separate all my classes and have them in multiple files instead of having a 1000+ line file with multiple classes and stuff mashed together within. At the moment I'm separating the whole program into multiple files, I might end up doing a re-write but I'm not sure yet.
Offline Cero
« Reply #49 - Posted 2013-01-27 00:38:33 »

TYRIAN! With hotdog guns!
And carrots... now that doesnt fit =D

Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #50 - Posted 2013-01-27 01:45:27 »

Yeah, I got the Super Carrot right after taking that screen, but I couldn't be bothered to take another one. Still got the savegame, though Smiley

- Jonas
Offline tyeeeee1
« Reply #51 - Posted 2013-02-02 14:41:21 »

Finally figured out how to do collision detection, now to figure out how to apply it to a whole screen of tiles instead of just two squares.
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #52 - Posted 2013-02-05 18:36:09 »

Just check the immediate area around each entity against collisions. Don't check each tile on the map.

- Jonas
Offline tyeeeee1
« Reply #53 - Posted 2013-03-02 15:53:57 »

It's been awhile but here are a few updates:

Updates:
  • Created and implemented a map loader.
  • Sprites are now working with animations.
  • A Derby database has been created and set up for items, creatures, loot tables, etc...
  • Everything has been re-written and separated into packages and multiple class files instead of one huge and un-editable file.
Offline Cero
« Reply #54 - Posted 2013-03-02 17:55:27 »

You seem to be doing fine :D

Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #55 - Posted 2013-03-07 04:03:29 »

Going well, then Smiley

Any chance we can see some running application?

- Jonas
Offline tyeeeee1
« Reply #56 - Posted 2013-03-12 02:25:59 »

Going well, then Smiley

Any chance we can see some running application?

Maybe when I get a bit more done. There's not much to do other than move a sprite around the screen and click through menus atm.
Offline tyeeeee1
« Reply #57 - Posted 2013-03-21 18:47:28 »

Update:
  • Collision detection is now working but extremely buggy.
  • The code is being re-organized and partially re-written again as to separate the logic and rendering.
  • A few map tiles have been created by an acquaintance of mine. A few of them have been implemented and are working in the game.
  • The Derby database has been scrapped and I'm having to switch back to using text files to save data.

Because Ultroman wanted to see what's working at the moment, here you go (http://www.mediafire.com/download.php?zay8dt17vfdssit). All that you can do at the moment is to walk around on the map and get stuck on the pathway tiles because of bugs with the collision code.
Offline tyeeeee1
« Reply #58 - Posted 2013-03-23 22:57:54 »

Update:
  • The code has been re-written and is both working faster and easier to understand now.
  • Collision detection has been fixed and is working perfectly.

Offline matheus23

JGO Kernel


Medals: 109
Projects: 3


You think about my Avatar right now!


« Reply #59 - Posted 2013-03-24 10:59:21 »

Where can I download the new version? Grin

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Pages: 1 [2] 3
  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.

theagentd (18 views)
2014-10-25 15:46:29

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

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

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

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

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

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

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

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

BurntPizza (45 views)
2014-10-11 23:10:45
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!