Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Quellcode |
|
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 |
import java.awt.Color; import java.awt.DisplayMode; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Window; import java.awt.image.BufferStrategy; import javax.swing.ImageIcon; import javax.swing.JFrame; public class ImageTest{ private static final long DEMO_TIME = 5000; private ScreenManager sm; private Animation prototype; public static void main(String[] args){ DisplayMode dm = new DisplayMode(1600, 900, 16, 75); ImageTest imgt = new ImageTest(); imgt.run(dm); } private void run(DisplayMode dm) { sm = new ScreenManager(); try { dm = new DisplayMode( 1600, 900, 16, 75); sm.setFullscreen(dm, new JFrame()); loadImages(); animationLoop(); }finally { sm.restoreScreen(); } } private void animationLoop() { long startTime = System.currentTimeMillis(); long currTime = startTime; while ( currTime - startTime < DEMO_TIME ){ long elapsedTime = System.currentTimeMillis() - currTime ; currTime += elapsedTime; prototype.update(elapsedTime); BufferStrategy strategy = sm.getFullScreenWindow().getBufferStrategy(); Graphics g = strategy.getDrawGraphics(); draw(g); g.dispose(); strategy.show(); try { Thread.sleep(20); }catch (InterruptedException e){} } } private void draw(Graphics g) { g.drawImage(prototype.getImage(), 0, 0, null); } private void loadImages() { Image prototype1 = loadImage("images/prototype1.png"); Image prototype2 = loadImage("images/prototype2.png"); Image prototype3 = loadImage("images/prototype3.png"); prototype = new Animation(); prototype.addFrame(prototype1, 250); prototype.addFrame(prototype2, 250); prototype.addFrame(prototype3, 250); } private Image loadImage(String path) { return new ImageIcon(path).getImage(); } } |
Quellcode |
|
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 |
import java.awt.DisplayMode; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Toolkit; import java.awt.Window; import java.awt.image.BufferStrategy; import java.awt.image.BufferedImage; import javax.swing.JFrame; public class ScreenManager { GraphicsEnvironment environment; GraphicsDevice device; public ScreenManager(){ environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); device = environment.getDefaultScreenDevice(); } public void setFullscreen( DisplayMode mode, JFrame frame){ frame.setUndecorated(true); frame.setResizable(false); frame.setIgnoreRepaint(true); device.setFullScreenWindow(frame); if( mode != null && device.isDisplayChangeSupported()){ try { device.setDisplayMode(mode); } catch (IllegalArgumentException e ){} } } public Window getFullScreenWindow(){ return device.getFullScreenWindow(); } public void restoreScreen(){ Window w = getFullScreenWindow(); if ( w != null ){ w.dispose(); } device.setFullScreenWindow(null); } } |
Quellcode |
|
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 |
import java.awt.Image; import java.util.ArrayList; import javax.swing.ImageIcon; public class Animation { private ArrayList animation; int currPic; long endTime; long currentTime; public Animation(){ animation = new ArrayList(); endTime = 0; start(); } public void start(){ currentTime = 0; currPic = 0; } private AnimFrame getFrame( int index ){ return (AnimFrame)animation.get(index); } public synchronized void addFrame( Image img, long animTime ){ endTime += animTime; animation.add(new AnimFrame( endTime , img)); } private class AnimFrame { long animTime; Image img; private AnimFrame( long animTime, Image img ){ this.img = img; this.animTime = animTime; } } public synchronized Image getImage(){ if (animation.size() == 0){ return null; } return getFrame(currPic).img; } public synchronized void update(long elapsedTime){ if ( animation.size() > 1 ){ currentTime += elapsedTime; if ( currentTime > endTime ){ currentTime = currentTime % endTime; currPic = 0; } while ( currentTime > getFrame(currPic).animTime ){ currPic++; } } } } |
Treue Seele
Beruf: Student, Hardware- und Softwareentwicklung als wissenschaftliche Hilfskraft
Quellcode |
|
1 |
Graphics g = strategy.getDrawGraphics(); |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Es ist ja keine Schande etwas falsch zu machen, als Programmierer tu ich das täglich, [...].
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »BlueCobold« (06.02.2014, 15:47)
Weil es sich, wie bereits richtig vermutet, nicht auf deinen Beitrag bezieht.Wieso "Nein."? Das ist in langer Form genau meine Aussage.
Es ist ja keine Schande etwas falsch zu machen, als Programmierer tu ich das täglich, [...].
Werbeanzeige