problém s kódem

Místo pro dotazy a rady ohledně programovacích jazyků (C++, C#, PHP, ASP, Javascript, VBS..) a tvorby webových stránek

Moderátor: Mods_senior

Zamčeno
CallManyCZ
nováček
Příspěvky: 36
Registrován: 09 črc 2014 16:21

problém s kódem

Příspěvek od CallManyCZ »

Zdravím... potřebuju poradit..
Našel jsem si na YT tutorial na Java Hru ....

V tom tutoriálu mu jde všechno v pořádku, ale já když tu aplikaci spustím vypíše mi to do konzole : 3800 FPS a 60 TICKS ale potom se mi sekne počítač a když kliknu a křížek abych to vypnul tak musím čekat cca 5 min než se ta apka vypne :/


tady je ten kód



Třída Window:

Kód: Vybrat vše

package cz.CallManyCZ.neon.window;

import java.awt.Dimension;

import javax.swing.JFrame;

public class Window {
	
	public Window(int w, int h, String title, Game game){
		game.setPreferredSize(new Dimension(w,h));
		game.setMaximumSize(new Dimension(w,h));
		game.setMinimumSize(new Dimension(w,h));	
		
		JFrame frame = new JFrame(title);
		frame.add(game);
		frame.pack();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setResizable(false);
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
		
		
		game.start();
	}
	
}

Třída Game :

Kód: Vybrat vše

package cz.CallManyCZ.neon.window;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;

public class Game extends Canvas implements Runnable{

	private static final long serialVersionUID = 1L;
	
	private boolean running = false;
	private Thread thread;
	
	
	
	public synchronized void start(){
		if(running)
			return;
		running = true;
		thread = new Thread(this);
		thread.start();
	}
	
	public void run(){
		long lastTime = System.nanoTime();
		double amountOfTicks = 60.0;
		double ns = 1000000000 / amountOfTicks;
		double delta = 0;
		long timer = System.currentTimeMillis();
		int updates = 0;
		int frames = 0;
		while(running){
			long now = System.nanoTime();
			delta += (now - lastTime) / ns;
			lastTime = now;
			while(delta >= 1){
				tick();
				updates++;
				delta--;
			}
			render();
			frames++;
					
			if(System.currentTimeMillis() - timer > 1000){
				timer += 1000;
				System.out.println("FPS: " + frames + " TICKS: " + updates);
				frames = 0;
				updates = 0;
			}
		}
	}
	
	private void tick(){
		
		
	}
	
	private void render(){
		BufferStrategy bs = this.getBufferStrategy();
		
		if(bs == null){
			this.createBufferStrategy(3);
			return;
		}
		
		Graphics g = bs.getDrawGraphics();
		//////////////////////////////////
		
		
		
		
		g.setColor(Color.black);
		g.fillRect(0, 0, getWidth(), getHeight());
		
		//////////////////////////////////
		g.dispose();
		bs.show();
			
	}
	
	public static void main(String[] args){
		new Window(800, 600, "Neon Platform Game Prototype", new Game());
	}
	
}
nevím jestli to náhodou není nějaký bug BufferStrategy :/
Zamčeno
  • Podobná témata
    Odpovědi
    Zobrazení
    Poslední příspěvek
  • Problém s internetem
    od valama » » v Internet a internetové prohlížeče
    11 Odpovědi
    17145 Zobrazení
    Poslední příspěvek od RIKI22
  • Problém s mikrofonem
    od Shokata88 » » v Problémy s hardwarem
    4 Odpovědi
    9453 Zobrazení
    Poslední příspěvek od Shokata88
  • Problém s internetem
    od yakubb23 » » v Sítě - hardware
    1 Odpovědi
    12185 Zobrazení
    Poslední příspěvek od meda2016
  • Problém se spuštěním PC
    od Viroxx » » v Problémy s hardwarem
    1 Odpovědi
    7013 Zobrazení
    Poslední příspěvek od petr22
  • Problém s monitorom
    od sloliv » » v Problémy s hardwarem
    8 Odpovědi
    7591 Zobrazení
    Poslední příspěvek od sloliv

Zpět na „Programování a tvorba webu“