Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

I need Help with my Game

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
No replies to this topic

#1 xStewieee   Members   

101
Like
0Likes
Like

Posted 23 January 2013 - 07:51 AM

Hey guys i'm encountering a problem with my code. I am following a youtube tutorial and i have all the correct code, in which is supposed to display lots of pixels when ran. 

My code is the exact same but when i run, all i get is a blank screen icon_sad.gif 

Please help and this is my Code; 

import java.awt.Canvas; 
import java.awt.Dimension; 
import java.awt.Graphics; 
import java.awt.image.BufferStrategy; 
import java.awt.image.BufferedImage; 
import java.awt.image.DataBufferInt; 
import java.util.Random; 

import javax.swing.JFrame; 


public class Game extends Canvas implements Runnable { 


private static final long serialVersionUID = 1L; 
public static final int HEIGHT = 120; 
public static final int WIDTH = 120; 
public static final int SCALE = 3; 

public static final String NAME = "My First Game!"; 

private BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); 
private int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData(); 

Random random = new Random(); 

private boolean running = false; 

public void start() { 
running = true; 
new Thread(this).start(); 



public void run() { 
while (running) { 
tick(); 
render(); 


public void stop(){ 

running = false; 


public void tick() { 
for(int i = 0; i < pixels.length; i++) { 
pixels[i] = random.nextInt();


public void render(){ 
BufferStrategy bs = getBufferStrategy(); 
if(bs == null) { 
createBufferStrategy(3); 
requestFocus(); 
return; 


Graphics g = bs.getDrawGraphics(); 
g.drawImage(image, 0 , 0, getWidth(), getHeight(), null); 
g.dispose(); 
bs.show(); 





public static void main(String[] args) { 

Game game = new Game(); 
game.setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE)); 
game.setMaximumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE)); 
game.setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE)); 

JFrame frame = new JFrame(NAME); 
frame.add(game); 
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
frame.pack(); 
frame.setResizable(true); 
frame.setVisible(true); 






Thank's in advance






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.