Results 1 to 2 of 2
  1. #1
    matevos is offline Member
    Join Date
    Aug 2012
    Rep Power

    Default Problem with drawImage

    Hi, I learning Java since 2 weeks, and today I decided to make a simply platform game.
    Its a code which getting the spritesheet.

    Java Code:
    import java.awt.image.*;
    import javax.imageio.*;
    public class LoadSprites {
            public static BufferedImage tiles;
            public LoadSprites(){
            public void LoadSprites2(){
                            tiles = File("res/tiles.png"));
                    }catch(Exception ex){}
    And this is a code which getting the 1 tile from the spritesheet and rendering this to the map.

    Java Code:
    public void render(Graphics g){
                    for(int x=0; x<15; x++){
                            for(int y=0; y<15; y++){
                                    if (Map[y].substring(x, x + 1).equals("G")){
                                            //g.fillRect(x * 32, y * 32, 32, 32);
                                            g.drawImage(LoadSprites.tiles, x * 32, y * 32, 32, 32, 32, 0, 0, 32, null);
    When I using the g.fillRect the map looks like this

    And it is fine.

    But when I use a drawImage and I importing from the big image 1 tile and rendering this to map it look like this:

    And as we see drawImage creating 3 big rectangles, and 1 big square. Instead of creating the tiled map like on this first image.

    What is wrong? Please help.

    Its my double buffering method. Also I using the canvas.

    Java Code:
    public void DoubleBuffering(){
                    BufferStrategy bs = getBufferStrategy();
                    if(bs == null){
                    Graphics g = bs.getDrawGraphics();
                    g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
    Attached Thumbnails Attached Thumbnails Problem with drawImage-74715233.png  

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Tucson, AZ
    Rep Power

    Default Re: Problem with drawImage

    It's hard to guess with so little code. Best thing I can tell you is put in some println statements to see what's actually getting painted.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Graphics.drawImage() question
    By sakratt in forum AWT / Swing
    Replies: 0
    Last Post: 03-28-2012, 11:52 PM
  2. Does not recognize drawImage method...
    By Koba in forum New To Java
    Replies: 13
    Last Post: 11-21-2011, 05:06 AM
  3. NullPointerException on Graphics.drawImage
    By Jaeela in forum New To Java
    Replies: 5
    Last Post: 10-05-2011, 03:36 AM
  4. DrawImage with transparency ?
    By mrhid6 in forum AWT / Swing
    Replies: 2
    Last Post: 10-02-2011, 12:58 AM
  5. drawImage im 13 plz help
    By pseudohawtcakes in forum New To Java
    Replies: 3
    Last Post: 05-17-2011, 09:07 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts