Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Game rendering

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Game rendering

    here is the code that i have so far and it is not doing what it needs to do so far, this is not my code it is from a tutorial that i am following on youtube. i am just rebuilding it to learn how to make a game in java.

    this is the first class-----

    package com.ryan.doomed;

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

    import javax.swing.JFrame;

    import com.ryan.doomed.graphics.Screen;

    public class Doomed extends Canvas implements Runnable{
    private static final long serialVersionUID = 1L;

    public static int width = 300;
    public static int height = width / 16 * 9;
    public static int scale = 3;

    private Thread thread;
    private JFrame frame;
    private boolean running = false;

    private Screen screen;

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


    public Doomed(){
    Dimension size = new Dimension(width * scale, height * scale);
    setPreferredSize(size);

    screen = new Screen(width, height);
    frame = new JFrame();

    }//ends game

    public synchronized void start(){
    running = true;
    thread = new Thread(this, "Display");
    thread.start();
    }//ends start

    public synchronized void stop(){
    running = false;
    try{
    thread.join();
    }catch(InterruptedException e){
    e.printStackTrace();
    }
    }//ends stop

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

    }

    }//ends run


    public void update(){


    }//ends update



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

    screen.render();

    for (int i = 0; i > pixels.length; i++){
    pixels[i] = screen.pixels[i];

    }//ends for

    Graphics g = bs.getDrawGraphics();
    // g.setColor(Color.BLACK);
    // g.fillRect(0, 0, getWidth(), getHeight());
    g.drawImage(image, 0, 0, getHeight(), getWidth(), null);
    g.dispose();
    bs.show();
    }//ends render


    public static void main(String[] args){
    Doomed game = new Doomed();
    game.frame.setResizable(false);
    game.frame.setTitle("Doomed");
    game.frame.add(game);
    game.frame.pack();
    game.frame.setDefaultCloseOperation(JFrame.EXIT_ON _CLOSE);
    game.frame.setLocationRelativeTo(null);
    game.frame.setVisible(true);

    game.start();


    }//ends main


    }//ends Doomed

    this is the 2nd class---

    package com.ryan.doomed.graphics;

    public class Screen {

    private int width, height;
    public int pixels[];

    public Screen(int width, int height){
    this.width = width;
    this.height = height;
    pixels = new int [width * height];
    }//ends constructor

    public void render(){
    for (int y = 0; y < height; y++) {
    for (int x = 0; x < height; x++){
    pixels[x + y * width] = 0xfe34ab;
    }//ends second for
    }//ends first for

    }//ends render

    }//ends screen

    -----------------------------------
    the code is supposed to have the full size of the screen the color specified but it is all messed up. i think that it is in the screen class but i can't pin point the error.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,459
    My Mood
    Mellow
    Thanks
    148
    Thanked 607 Times in 594 Posts

    Default Re: Game rendering

    Post your code in code or highlight tags. You can read how in the Announcements at the top of the page.

    "it is not doing what it needs to do", and "it is all messed up" are not helpful. Please describe what it is supposed to do and what it is or is not doing. And if it still matters after that, describe what you mean by "all messed up."

Similar Threads

  1. Images not rendering?
    By deathman12e3 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: June 24th, 2013, 08:07 PM
  2. [SOLVED] 3D rendering?
    By kaskoepoes112 in forum Java Theory & Questions
    Replies: 7
    Last Post: June 10th, 2013, 07:59 AM
  3. [SOLVED] JSF? not rendering.
    By newbie in forum Web Frameworks
    Replies: 2
    Last Post: March 21st, 2011, 08:45 PM
  4. JMonkeyEngine 3 not rendering.
    By scribbleno1 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 13th, 2010, 02:29 AM
  5. Problem in JSP rendering
    By srkumarj2ee@gmail.com in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: September 13th, 2009, 02:26 PM

Tags for this Thread