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.

Page 1 of 2 12 LastLast
Results 1 to 25 of 37

Thread: As my player goes lower on-screen my tiles become smaller in height? D:

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy As my player goes lower on-screen my tiles become smaller in height? D:

    Pretty much that, the screen stays on the player, the player stays the same size :/

    I am new to Java so don't kill me :p

    I attached my files, please help!

    -Wolf
    Attached Files Attached Files


  2. #2
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    In the future, post code like using the [code=java][/code] tags. Next, the program won't run for me on Eclipse. It can't find the main method. Please, explain you program more fully.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    There is one, in Component.class. Here's some code then :

    Component.class
    package net.wolfgamingdev.minecraftplatformer;
     
    import java.applet.*;
    import java.awt.*;
    import javax.swing.*;
     
    public class Component extends Applet implements Runnable {
    	private static final long serialVersionUID = 1L;
     
    	private static int pixelSize = 2;
    	public static double sX = 0, sY = 0;
     
    	public static Dimension size = new Dimension(700,560);
    	public static Dimension pixel = new Dimension(size.width / pixelSize, size.height / pixelSize);	
     
    	public static String name = "Minecraft 2D!";
     
    	public static boolean isRunning = false;
     
    	private Image screen;
     
    	public static Level level;
    	public static Character character;
     
    	//BLERRRGH
    	public Component() {
    		setPreferredSize(size);
    	}
     
    	public void start() {
    		//Defining Objects
    		new Tile(); //Loading images
    		level = new Level();
    		character = new Character(Tile.tileSize, Tile.tileSize * 2);
     
    		//Starting Game Loop
    		isRunning = true;
    		new Thread(this).start();
    	}
     
    	public void stop() {
    		isRunning = false;
    	}
     
    	public static void main(String args[]) {
    		Component component = new Component();
     
    		JFrame frame = new JFrame();
    		frame.add(component);
    		frame.pack();
    		frame.setTitle(name);
    		frame.setResizable(false);
    		frame.setLocationRelativeTo(null);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setVisible(true);
     
    		component.start();
    	}
     
    	public void tick() {
    		level.tick();
    		character.tick();
    	}
     
    	public void render() {
    		Graphics g = screen.getGraphics();
     
    		//Drawing Things
    		g.setColor(new Color(100, 100, 255));
    		g.fillRect(0, 0, pixel.width, pixel.height);
     
    		level.render(g);
    		character.render(g);
     
    		g = getGraphics();
     
    		g.drawImage(screen, 0, 0, size.width, size.height, 0, 0, pixel.width, pixel.height, null);
    		g.dispose();
    	}
     
    	public void run() {
    		screen = createVolatileImage(pixel.width,pixel.height);
     
    		while(isRunning) {
    			tick();
    			render();
     
    			try {
    				Thread.sleep(5);
    			} catch(Exception e) { }
    		}
    	}
    }

    Level.class
    package net.wolfgamingdev.minecraftplatformer;
     
    import java.awt.*;
     
    public class Level {
    	public Block[][] block = new Block[50][50];
     
    	public Level() {
    		for (int x=0; x<block.length;x++) {
    			for (int y=0;y<block[0].length;y++) {
    				block[x][y] = new Block(new Rectangle(x * Tile.tileSize, y * Tile.tileSize, Tile.tileSize, Tile.tileSize), Tile.air);
    			}
    		}
    		generateLevel();
    	}
     
    	public void generateLevel() {
    		for (int x=0; x<block.length;x++) {
    			for (int y=0;y<block[0].length;y++) {
    				if(x == 0 || y == 0 || x == block.length-1 || y == block[0].length-1) {
    					block[x][y].id = Tile.earth;
    				}
    			}
    		}
    	}
     
    	public void tick() {
     
    	}
     
    	public void render(Graphics g) {
    		for (int x=0; x<block.length;x++) {
    			for (int y=0;y<block[0].length;y++) {
    				block[x][y].render(g);
    				}
    			}
    		}
    	}

    Block.class (This is where the blocks values are defined)
    package net.wolfgamingdev.minecraftplatformer;
     
    import java.awt.*;
     
    public class Block extends Rectangle {
    	private static final long serialVersionUID = 1L;
     
    	public int[] id = {-1, -1};
     
    	public Block(Rectangle size, int[] id) {
    		setBounds(size);
    		this.id = id;
    	}
     
    	public void render(Graphics g) {
    		if(id != Tile.air) {
    			g.drawImage(Tile.tileset_terrain, (int)x - (int)Component.sX, (int)y - (int)Component.sY, (int)x + width - (int)Component.sX, (int)y + height - (int)Component.sY, id[0] * Tile.tileSize - (int)Component.sX, id[1] * Tile.tileSize - (int)Component.sY, id[0] * Tile.tileSize + Tile.tileSize, id[1] * Tile.tileSize + Tile.tileSize, null);
    		}
    	}
     
    }

    Character.class (There is a tile.class as well but it just defines the tiles)
    package net.wolfgamingdev.minecraftplatformer;
     
    import java.awt.*;
     
    public class Character extends DoubleRectangle {
    	public double fallingSpeed = 1.3;
     
    	public Character(int width, int height) {
    		setBounds((Component.pixel.width/2) - (width / 2), (Component.pixel.height/2) - (height / 2), width, height);
    	}
     
    	public void tick() {
    		y += fallingSpeed;
    		Component.sY += fallingSpeed;
    	}
     
    	public void render(Graphics g) {
    		g.drawImage(Tile.tileset_terrain, (int)x - (int)Component.sX, (int)y - (int)Component.sY, (int)(x + width) - (int)Component.sX, (int)(y + height) - (int)Component.sY, Tile.character[0] * Tile.tileSize, Tile.character[1] * Tile.tileSize, Tile.character[0] * Tile.tileSize + (int)width, Tile.character[1] * Tile.tileSize + (int)height, null);
    	}
    }

    There is another class called doublerectangle but I think that is just defining the characters values.
    Sorry for all the trouble I'm just a newb following a tutorial :/
    Honestly I don't understand half of what's in there yet, but I have a theory that the bug has something to do with Component.sY getting bigger....

    --- Update ---

    It's definitely because of Component.Sy getting added in character.class, commented it out and it fixed it, (without the camera moving)

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    Several problems:
    Why does the Applet class have a main() method? Is this an Applet or an application?

    Component and Character are Java SE classes. You should NOT use the same name for your classes.

    Too many variables are static.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    It's both? That's what this tutorial said. None of my classes have the same name...
    Which variables shouldn't be static?

    My hasn't even been touched on yet :/

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    There shouldn't be any static variables.

    Rename the classes so their names are NOT the same as Java SE classes.

    Change the extends Applet to extends Panel
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    Doesn't static mean that they can be changed? (the point of variables? )

    Which class is the same as a Java SE class?

    Thanks for trying to help, I don't mean to be a bother :p

  8. #8
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    static means you don't have to create an object of that type to use it. for example in the Math class, not only do you not need to create a Math object, you can't.

    //try putting this into eclipse or something
    Math math = new Math();
    //it should say that the constructor is not visible
     
     
    //however
    double x = Math.sqrt(49);
    //works because sqrt(double arg) is a static method.

    Making a specific variable a 'static variable' allows static methods to use it and for that variable to be accessed in a static way.

  9. #9
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    When I take off the static variables the program breaks.

    --- Update ---

    No errors but Nothing shows on screen

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    the program breaks.
    How did you rewrite the program so it uses instances of a class instead of using static variables?

    Post the full text of the compiler error messages and the new source code.

    Which class is the same as a Java SE class?
    See post#4
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    Norm - I just...deleted the part that says static (god I'm such a newb) And I can change Component to Engine and Character to Player

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    Post the new code and your questions if you are still having a problem.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    Norm - I just...deleted the part that says static (god I'm such a newb) And I can change Component to Engine and Character to Player

    Just changed the classes didn't help

    --- Update ---

    Why do the Tile height decrease as my character falls

    --- Update ---

    The code didn't change with the exception of the class names. Nothing has changed

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    You need to get rid of the static variables and use instances of the class.

    Some classes are missing. The posted code can not be compiled for testing.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    I'll re-post all the code's, and can you tell e how I could do that? (instances of the class)

    Engine
    package net.wolfgamingdev.minecraftplatformer;
     
    import java.applet.*;
    import java.awt.*;
    import javax.swing.*;
     
    public class Engine extends Applet implements Runnable {
    	private static final long serialVersionUID = 1L;
     
    	private static int pixelSize = 2;
    	public static double sX = 0, sY = 0;
     
    	public static Dimension size = new Dimension(700,560);
    	public static Dimension pixel = new Dimension(size.width / pixelSize, size.height / pixelSize);	
     
    	public static String name = "Minecraft 2D!";
     
    	public static boolean isRunning = false;
     
    	private Image screen;
     
    	public static Level level;
    	public static Player player;
     
    	//BLERRRGH
    	public Engine() {
    		setPreferredSize(size);
    	}
     
    	public void start() {
    		//Defining Objects
    		new Tile(); //Loading images
    		level = new Level();
    		player = new Player(Tile.tileSize, Tile.tileSize * 2);
     
    		//Starting Game Loop
    		isRunning = true;
    		new Thread(this).start();
    	}
     
    	public void stop() {
    		isRunning = false;
    	}
     
    	public static void main(String args[]) {
    		Engine engine = new Engine();
     
    		JFrame frame = new JFrame();
    		frame.add(engine);
    		frame.pack();
    		frame.setTitle(name);
    		frame.setResizable(false);
    		frame.setLocationRelativeTo(null);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setVisible(true);
     
    		engine.start();
    	}
     
    	public void tick() {
    		level.tick();
    		player.tick();
    	}
     
    	public void render() {
    		Graphics g = screen.getGraphics();
     
    		//Drawing Things
    		g.setColor(new Color(100, 100, 255));
    		g.fillRect(0, 0, pixel.width, pixel.height);
     
    		level.render(g);
    		player.render(g);
     
    		g = getGraphics();
     
    		g.drawImage(screen, 0, 0, size.width, size.height, 0, 0, pixel.width, pixel.height, null);
    		g.dispose();
    	}
     
    	public void run() {
    		screen = createVolatileImage(pixel.width,pixel.height);
     
    		while(isRunning) {
    			tick();
    			render();
     
    			try {
    				Thread.sleep(5);
    			} catch(Exception e) { }
    		}
    	}
    }

    Level
    package net.wolfgamingdev.minecraftplatformer;
     
    import java.awt.*;
     
    public class Level {
    	public Block[][] block = new Block[50][50];
     
    	public Level() {
    		for (int x=0; x<block.length;x++) {
    			for (int y=0;y<block[0].length;y++) {
    				block[x][y] = new Block(new Rectangle(x * Tile.tileSize, y * Tile.tileSize, Tile.tileSize, Tile.tileSize), Tile.air);
    			}
    		}
    		generateLevel();
    	}
     
    	public void generateLevel() {
    		for (int x=0; x<block.length;x++) {
    			for (int y=0;y<block[0].length;y++) {
    				if(x == 0 || y == 0 || x == block.length-1 || y == block[0].length-1) {
    					block[x][y].id = Tile.earth;
    				}
    			}
    		}
    	}
     
    	public void tick() {
     
    	}
     
    	public void render(Graphics g) {
    		for (int x=0; x<block.length;x++) {
    			for (int y=0;y<block[0].length;y++) {
    				block[x][y].render(g);
    				}
    			}
    		}
    	}

    Block
    package net.wolfgamingdev.minecraftplatformer;
     
    import java.awt.*;
     
    public class Block extends Rectangle {
    	private static final long serialVersionUID = 1L;
     
    	public int[] id = {-1, -1};
     
    	public Block(Rectangle size, int[] id) {
    		setBounds(size);
    		this.id = id;
    	}
     
    	public void render(Graphics g) {
    		if(id != Tile.air) {
    			g.drawImage(Tile.tileset_terrain, (int)x - (int)Engine.sX, (int)y - (int)Engine.sY, (int)x + width - (int)Engine.sX, (int)y + height - (int)Engine.sY, id[0] * Tile.tileSize - (int)Engine.sX, id[1] * Tile.tileSize - (int)Engine.sY, id[0] * Tile.tileSize + Tile.tileSize, id[1] * Tile.tileSize + Tile.tileSize, null);
    		}
    	}
     
    }

    Tile
    package net.wolfgamingdev.minecraftplatformer;
     
    import java.awt.image.*;
    import javax.imageio.ImageIO;
    import java.io.*;
     
    public class Tile {
    	public static int tileSize = 20;
     
    	public static int[] air = {-1, -1};
    	public static int[] earth = {0, 0};
     
    	public static int[] character = {0, 18};
     
    	public static BufferedImage tileset_terrain;
     
    	public Tile() {
    		try {
    			Tile.tileset_terrain = ImageIO.read(new File("res/tileset_terrain.png"));
    		} catch(Exception e) { }
     
    	}
    }

    Player
    package net.wolfgamingdev.minecraftplatformer;
     
    import java.awt.*;
     
    public class Player extends DoubleRectangle {
    	public double fallingSpeed = 1.3;
     
    	public Player(int width, int height) {
    		setBounds((Engine.pixel.width/2) - (width / 2), (Engine.pixel.height/2) - (height / 2), width, height);
    	}
     
    	public void tick() {
    		y += fallingSpeed;
    		Engine.sY += fallingSpeed;
    	}
     
    	public void render(Graphics g) {
    		g.drawImage(Tile.tileset_terrain, (int)x - (int)Engine.sX, (int)y - (int)Engine.sY, (int)(x + width) - (int)Engine.sX, (int)(y + height) - (int)Engine.sY, Tile.character[0] * Tile.tileSize, Tile.character[1] * Tile.tileSize, Tile.character[0] * Tile.tileSize + (int)width, Tile.character[1] * Tile.tileSize + (int)height, null);
    	}
    }

    DoubleRectangle
    package net.wolfgamingdev.minecraftplatformer;
     
    public class DoubleRectangle {
    	public double x, y, width, height;
     
    	public DoubleRectangle() {
    		setBounds(0, 0, 0, 0);
    	}
     
    	public DoubleRectangle(double x, double y, double width, double height) {
    		setBounds(x, y, width, height);
    	}
     
    	public void setBounds(double x, double y, double width, double height) {
    		this.x = x;
    		this.y = y;
    		this.width = width;
    		this.height = height;
    	}
    }

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    I see lots of static variables. These need to changed.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    Yes but I don't know how, just removing the static part, it doesn't show anything when I try to run it.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    How did you change the code when you removed the static modifier?

    Just deleting "static" would cause compiler errors so the program would not execute.


    When I execute the code I do not see what you mean by a "tile".
    There are some very small shapes on the left that move up. They get smaller as they continue to move up.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    That is exactly my problem. And that's all I did was remove static .

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    The code is ugly in the way it uses static. I'll leave debugging to you.

    To debug the code, start by finding where the "tile" is drawn. Add some println statements there that print out the variables used to determine the size that the tile is drawn.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    Alright, how can I make it not use static?

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    That will require that there be instances of the classes and that those are used instead of the name of the class when referencing variables in the class.

    Have you tried adding some println statements to find how or where the size of the "tile" is being changed?
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    Yes and I'm having problems there too -__-

    Here's where I put the println (Because when I tried putting it in the original tick function, it wouldn't allow me to access the block variables because they weren't static... )

    Block.class
    package net.wolfgamingdev.minecraftplatformer;
     
    import java.awt.*;
     
    public class Block extends Rectangle {
    	private static final long serialVersionUID = 1L;
     
    	public int[] id = {-1, -1};
     
    	public Block(Rectangle size, int[] id) {
    		setBounds(size);
    		this.id = id;
    	}
     
    	public void tick() {
    		System.out.println(y + width - Engine.sY);
    	}
     
    	public void render(Graphics g) {
    		if(id != Tile.air) {
    			g.drawImage(Tile.tileset_terrain, (int)x - (int)Engine.sX, (int)y - (int)Engine.sY, (int)x + width - (int)Engine.sX, (int)y + height - (int)Engine.sY, id[0] * Tile.tileSize - (int)Engine.sX, id[1] * Tile.tileSize - (int)Engine.sY, id[0] * Tile.tileSize + Tile.tileSize, id[1] * Tile.tileSize + Tile.tileSize, null);
    		}
    	}
    }

    And Engine.class
    package net.wolfgamingdev.minecraftplatformer;
     
    import java.applet.*;
    import java.awt.*;
    import javax.swing.*;
     
    public class Engine extends Applet implements Runnable {
    	private static final long serialVersionUID = 1L;
     
    	private static int pixelSize = 2;
    	public static double sX = 0, sY = 0;
     
    	public static Dimension size = new Dimension(700,560);
    	public static Dimension pixel = new Dimension(size.width / pixelSize, size.height / pixelSize);	
     
    	public static String name = "Minecraft 2D!";
     
    	public static boolean isRunning = false;
     
    	private Image screen;
     
    	public static Level level;
    	public static Player player;
    	public static Block block;
     
    	//BLERRRGH
    	public Engine() {
    		setPreferredSize(size);
    	}
     
    	public void start() {
    		//Defining Objects
    		new Tile(); //Loading images
    		level = new Level();
    		player = new Player(Tile.tileSize, Tile.tileSize * 2);
     
    		//Starting Game Loop
    		isRunning = true;
    		new Thread(this).start();
    	}
     
    	public void stop() {
    		isRunning = false;
    	}
     
    	public static void main(String args[]) {
    		Engine engine = new Engine();
     
    		JFrame frame = new JFrame();
    		frame.add(engine);
    		frame.pack();
    		frame.setTitle(name);
    		frame.setResizable(false);
    		frame.setLocationRelativeTo(null);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setVisible(true);
     
    		engine.start();
     
    	}
     
     
    	public void tick() {
    		level.tick();
    		player.tick();
    		block.tick();
    	}
     
    	public void render() {
    		Graphics g = screen.getGraphics();
     
    		//Drawing Things
    		g.setColor(new Color(100, 100, 255));
    		g.fillRect(0, 0, pixel.width, pixel.height);
     
    		level.render(g);
    		player.render(g);
     
    		g = getGraphics();
     
    		g.drawImage(screen, 0, 0, size.width, size.height, 0, 0, pixel.width, pixel.height, null);
    		g.dispose();
    	}
     
    	public void run() {
    		screen = createVolatileImage(pixel.width,pixel.height);
     
    		while(isRunning) {
    			tick();
    			render();
     
    			try {
    				Thread.sleep(5);
    			} catch(Exception e) { }
    		}
    	}
    }

    My error :p

    Exception in thread "Thread-2" java.lang.NullPointerException
    at net.wolfgamingdev.minecraftplatformer.Engine.tick( Engine.java:66)
    at net.wolfgamingdev.minecraftplatformer.Engine.run(E ngine.java:89)
    at java.lang.Thread.run(Thread.java:722)


    I really do hate being such a bother :/

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    xception in thread "Thread-2" java.lang.NullPointerException
    at net.wolfgamingdev.minecraftplatformer.Engine.tick( Engine.java:66)
    There is a variable at line 66 that has a null value when that line is executed. Find that variable and then backtrack to find out why is doesn't have a valid value.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    public void tick() {
    System.out.println(y + height - Engine.sY);
    }
    this is the function line 66 is referring too..

Page 1 of 2 12 LastLast

Similar Threads

  1. Drawing many Tiles on screen
    By Gravity Games in forum Object Oriented Programming
    Replies: 12
    Last Post: November 20th, 2012, 08:49 PM
  2. How can i make my Player attack another Player?
    By Graser in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 31st, 2012, 05:01 PM
  3. how to ignore upper and lower case
    By mohamed_saleh2012 in forum Java Theory & Questions
    Replies: 1
    Last Post: March 10th, 2012, 03:49 PM
  4. java game bullets hit player 1 but not player 2
    By ajakking789 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 22nd, 2011, 08:19 AM
  5. java game, both players move for player 2 but not player 1
    By ajakking789 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 21st, 2011, 12:52 PM