Hi all,
I know there were already discussions about a fullscreen mode for greenfoot but I think a fullscreen mode would be realy great for creating good games with greenfoot.
So I tried a view things and came to a result:
I think the easyest way for good fullscreen games would be to create a fullscreen frame (not the greenfoot frame), then take the image from the greenfoot panel (the world), scale it the the right screensize using Toolkit and print the image onto the fullscreen frame.
After some search I found the a java tutorial for the fullscreen exclusive mode which would be the best way for doing the fullscreen frame I think. Also I used an undecorated frame so the frame itselves covers the whole screen just like in real computergames.
Now I just got the problem that for some reason I can't get the image from the world and copy it onto the fullscreen frame.
But maybe the greenfoot team can introduce this in one of the next greenfoot versions. That would be realy great.
If anyone knows what I am doing wrong with my try for fullscreening please tell me so I can try to fix it.
Here's the code I'm using:
The world class:
And the fullscreen frame:
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 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import greenfoot.core.WorldHandler; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JPanel; /** * Write a description of class FullScreenWorld here. * * @author (your name) * @version (a version number or a date) */ public class FullScreenWorld extends World { private JPanel panel; private FullScreenWindow fullScreenWindow = new FullScreenWindow(); public FullScreenWorld() { super ( 600 , 400 , 1 ); panel = WorldHandler.getInstance().getWorldCanvas(); Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); //panel.getParent().getParent().getParent().getParent().getParent().getParent().getParent().getParent().getParent().setVisible(false); } public void act() { Graphics2D graphics = (Graphics2D) panel.getGraphics(); Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); graphics.scale(screenSize.getWidth()- 4 , screenSize.getHeight()- 10 ); //fullScreenWindow.getContentPane().print(graphics); } } |
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 | import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; public class FullScreenWindow extends JFrame { private static final long serialVersionUID = 1L; private JPanel contentPane; public FullScreenWindow() { setUndecorated( true ); //setAlwaysOnTop(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds( 100 , 100 , 450 , 300 ); contentPane = new JPanel(); contentPane.setBorder( new EmptyBorder( 5 , 5 , 5 , 5 )); contentPane.setLayout( new BorderLayout( 0 , 0 )); setContentPane(contentPane); if (getGraphicsConfiguration().getDevice().isFullScreenSupported()) { getGraphicsConfiguration().getDevice().setFullScreenWindow( this ); } } public JPanel getContentPane() { return contentPane; } } |