Thread: [Galkon's refactored] Fixing sprite loading

Results 1 to 8 of 8
  1. #1 [Galkon's refactored] Fixing sprite loading 
    Registered Member

    Join Date
    Dec 2007
    Age
    29
    Posts
    551
    Thanks given
    0
    Thanks received
    2
    Rep Power
    503
    Just a short little snippet to fix the annoying Sprite loading.

    In sprite.java import the following package,

    Code:
    import javax.swing.ImageIcon;
    Now replace your
    Code:
    public Sprite(String img) {
    method with,

    Code:
        public Sprite(String img) {
    		try {
    			Image image = Toolkit.getDefaultToolkit().getImage(location + img + ".png");
    			ImageIcon icon = new ImageIcon(image);
    			myWidth = icon.getIconWidth();
    			myHeight = icon.getIconHeight();
    			anInt1444 = myWidth;
    			anInt1445 = myHeight;
    			anInt1442 = 0;
    			anInt1443 = 0;
    			myPixels = new int[myWidth * myHeight];
    			PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, myWidth, myHeight, myPixels, 0, myWidth);
    			pixelgrabber.grabPixels();
    			image = null;
    		} catch(Exception _ex) {
    			System.out.println(_ex);
    		}
    	}
    Now you don't have to add each individual sprite.
    Reply With Quote  
     

  2. #2  
    Member Market Banned Market Banned

    Robin Spud's Avatar
    Join Date
    Aug 2008
    Age
    28
    Posts
    2,338
    Thanks given
    46
    Thanks received
    73
    Rep Power
    1068
    also. they can replace there imageloader with

    Code:
    	private static Sprite imageLoader(String s) {
    		return new Sprite(s);
    	}
    ILY Stewie.
    Reply With Quote  
     

  3. #3  
    Registered Member

    Join Date
    Dec 2007
    Age
    29
    Posts
    551
    Thanks given
    0
    Thanks received
    2
    Rep Power
    503
    Quote Originally Posted by \-Deemed-/ View Post
    also. they can replace there imageloader with

    Code:
    	private static Sprite imageLoader(String s) {
    		return new Sprite(s);
    	}
    You would still have to do,

    Code:
    if (img.equalsIgnoreCase("new sprite")) {
        myWidth = 20;
        myHeight = 25;
    }
    To get the width and height of each image, mine grabs it automatically so you don't need to do that .
    Reply With Quote  
     

  4. #4  
    Member
    Join Date
    Dec 2009
    Age
    25
    Posts
    50
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Great tut mate, i had a 100 errors at first but fixed .
    Reply With Quote  
     

  5. #5  
    #Yuuuuuuup! DerekGoodrow's Avatar
    Join Date
    Dec 2010
    Age
    23
    Posts
    162
    Thanks given
    14
    Thanks received
    15
    Rep Power
    49
    thank you xD, i did get 100 errors too , easy to fix.

    If you're going to rage 'bout my username, send me a PM and we're going to share our opinions. Yes I'm going to change it once I can, don't worry I just didn't think before clicking 'Edit Profile', so calm down boys!

    Reply With Quote  
     

  6. #6  
    Registered Member
    Purple's Avatar
    Join Date
    Feb 2010
    Age
    26
    Posts
    2,799
    Thanks given
    467
    Thanks received
    260
    Rep Power
    312
    It was already released by him, It's on the download topic, the 2nd post.
    Reply With Quote  
     

  7. #7  
    Registered Member Santi Cazorla's Avatar
    Join Date
    Aug 2009
    Age
    24
    Posts
    1,137
    Thanks given
    258
    Thanks received
    55
    Rep Power
    7
    nice gravedig guys.
    Reply With Quote  
     

  8. #8  
    Registered Member
    Purple's Avatar
    Join Date
    Feb 2010
    Age
    26
    Posts
    2,799
    Thanks given
    467
    Thanks received
    260
    Rep Power
    312
    Oh lmao, i completely forgot about the time it was posted, luckily i wasn't the one gravedigging lol.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

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