Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (579)
games submitted by our members
Games in WIP (500)
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]
  ignore  |  Print  
  New to game programming  (Read 4054 times)
0 Members and 1 Guest are viewing this topic.
Offline biro

Junior Member


Medals: 1
Projects: 1



« Reply #30 - Posted 2011-04-26 18:40:59 »

Hello,
Hello,
my problem is not the animation, at the moment I have no real animation, I only need to update the field, when a user gives a command, that changes the world in some aspects. Then should the world be refreshed. And for that I don't need a loop if I'm not wrong, the problem is, that if I don't use a loop and draw the pictures on the screen I see them for a few milliseconds after these few milliseconds I see a gray window again, and I want to know why.
I know that when I want to add animations I need a constant loop, that refreshs my screen, but at the moment that is not needed Wink
But let's look a bit in the future, to a time when I add animations or some other feature that needs a graphic refresh loop, than how should I drossel it, so that it won't eat 100% of my CPU power? My guess is that I should use sleep() for that, but how do I calculate the right amount of milliseconds my thread should sleep, so that my cpu doesn't need to create such a high output and on the other hand, that my "animation" is still fluid?
Please don't forget to answer the question about doing it at first without a loop and why the correct screen is only shown for a split second.

Greetings
biro

use double buffering.
Please take a look at my code, if you do you'll see that I use the double buffer from canvas, so that is definitivly not the reason!

biro
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #31 - Posted 2011-04-26 22:51:58 »

That call to render only happens once. If you want it to redraw the screen based on an input event, like a mouse or key, then you just need to call render() in your listeners.

Offline biro

Junior Member


Medals: 1
Projects: 1



« Reply #32 - Posted 2011-04-26 23:08:38 »

hello,
like I said, I do that in my Listeners, each time someone draggs the screen, the render method is called, and this part works, the problem is the render tag after the startup in my construktor Gui() (see my posted code), this render invoking shows for a few milliseconds the desired screen, after these few milliseconds it get's gray agai, until I invoke the render() method throug my listener. Any Ideas?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #33 - Posted 2011-04-26 23:13:44 »

Oh then that sounds like something is refreshing your screen? Try calling "setIgnoreRepaint(true)" in your constructor so a system call to repaint() would be ignored.

Offline biro

Junior Member


Medals: 1
Projects: 1



« Reply #34 - Posted 2011-04-26 23:17:59 »

hello,
I will try that tomorrow!
One more question: if you add a render loop, how high do you set the framerate or fps, and how do you ensure, that the framerate is being kept.

Many Greetings biro
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #35 - Posted 2011-04-26 23:51:20 »

60 FPS is the norm these days as almost all monitors these days refresh at that rate.

Offline ReBirth
« Reply #36 - Posted 2011-04-27 04:14:19 »

@biro
I have created a kind of game that has no animation and only update on click, sudoku Cheesy Use JPanel instead canvas like I did. On my sudoku (it's working well):
1  
2  
3  
4  
5  
6  
7  
8  
9  
public class yourClass extends JPanel{
     public void paint(Graphics g){
          super.paint(g);
          Graphics2D g2d=(Graphics2D)g.create();
          //use g2d to draw everything
    Toolkit.getDefaultToolkit().sync();
     g2d.dispose();
     }
}

I use something like this before know about canvas.

Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #37 - Posted 2011-04-27 05:53:52 »

@Rebirth
No Canvas is always better to draw on than JPanel. Plus JComponent is more fit for painting than JPanel.
Also, you should never override the paint() method of any Swing component. paintComponent() is there for your painting needs instead.

Offline biro

Junior Member


Medals: 1
Projects: 1



« Reply #38 - Posted 2011-04-27 08:14:07 »

Hello,
@ReBirth: isn't it better to use only the normal swing components for a sudoku-game? In the past weeks I wrote one too as a gift for a family member and as practice, I only used JPanels for the blocks and JLabels and JTextFields for the single numbers. If they were given I use a JLabel and if not a JTextField with a validater behind it.

biro

Edit:
@ra4king: don't you mean setIgnoreRepaint(true)? because false is the standart value.... So it would be meaningles to set it false..
Should I setIgnoreRepaint on the canvas as well or only on the JFrame?
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #39 - Posted 2011-04-27 13:21:23 »

Hehe my bad, I didn't notice that typo. Yes it is supposed to be "true". And setting it on the JFrame will set it globally.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #40 - Posted 2011-04-28 06:13:26 »

@r4king
yeah, like I said I used it before know about canvas thing Cheesy

@biro
I only used JPanel. All number is on image so what I need just draw. The input come from popupmenu when you right click a grid/box. Of course, you shouldn't force it to use swing since answer for canvas still can't be found.

Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #41 - Posted 2011-04-28 08:48:30 »

Of course, you shouldn't force it to use swing since answer for canvas still can't be found.
@ReBirth
Which answer for canvas?

Offline ReBirth
« Reply #42 - Posted 2011-04-29 07:18:30 »

@r4king
his question hasn't been solved right?

Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #43 - Posted 2011-04-29 07:29:26 »

IDK Tongue

Offline ReBirth
« Reply #44 - Posted 2011-04-30 06:14:42 »

Haha if he can't do it on canvas, do it on swing Tongue

Pages: 1 [2]
  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.

xsi3rr4x (33 views)
2014-04-15 18:08:23

BurntPizza (30 views)
2014-04-15 03:46:01

UprightPath (45 views)
2014-04-14 17:39:50

UprightPath (28 views)
2014-04-14 17:35:47

Porlus (45 views)
2014-04-14 15:48:38

tom_mai78101 (66 views)
2014-04-10 04:04:31

BurntPizza (126 views)
2014-04-08 23:06:04

tom_mai78101 (226 views)
2014-04-05 13:34:39

trollwarrior1 (191 views)
2014-04-04 12:06:45

CJLetsGame (199 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!