Thread: Sprite class add-on: Sprite GetSubImage

Results 1 to 8 of 8
  1. #1 Sprite class add-on: Sprite GetSubImage 
    Member Market Banned Market Banned

    Zee Best's Avatar
    Join Date
    Feb 2007
    Age
    29
    Posts
    3,036
    Thanks given
    24
    Thanks received
    210
    Rep Power
    1171
    Basically, if you have ever used a BufferedImage you will notice that it's possible to use this method;

    getSubimage(int x, int y, int w, int h)
    Returns a subimage defined by a specified rectangular region.
    So i decided to make one for the sprite class.

    Here it is;

    Code:
    public Sprite getSubImage(Sprite sprite, int sX, int sY, int w, int h)
        {
    	try {
    		int[] pixels = new int[w * h];
    		int pixOn = 0;
    		for (int i = sX; i < w; i++)
    		{
    			for (int i1 = sY; i1 < h; i1++)
    			{
    				int i2 = i - sX;
    				int i3 = i1 - sY;
    				pixels[i2 + i3 * w] = sprite.myPixels[i + i1 * sprite.myWidth];
    			}
    		}		
    		sprite.myHeight = h - sY;
    		sprite.myWidth = w - sX;
    		sprite.myPixels = pixels;
    		return sprite;
    	} catch(Exception e) {
    		e.printStackTrace();
    	}
    	return null;
        }
    Basically the usage is;

    Code:
    mySprite = mySprite.getSubImage(mySprite, startX, startY, pixelWidth, pixelHeight);
    You could also do;

    Code:
    Sprite newSprite = mySprite.getSubImage(mySprite, startX, startY, pixelWidth, pixelHeight);
    Which would create a new sprite from the previous one.

    Here is an example of using it for the hitpoints bar;

    Code:
    	
    
    	if(((Entity) (obj)).loopCycleStatus > loopCycle)
            {
    		try {
                    	npcScreenPos(((Entity) (obj)), ((Entity) (obj)).height + 15);
                    	if(spriteDrawX > -1)
                    	{
                        		int i1 = (((Entity) (obj)).currentHealth * 30) / ((Entity) (obj)).maxHealth;
                        		if(i1 > 30)
                            		i1 = 30;
                        		Sprite emptyBar = new Sprite("empty.png");
    				Sprite fullBar = new Sprite("full.png");
    				fullBar.drawSprite(spriteDrawX - 15, spriteDrawY - 3);
    				emptyBar = emptyBar.getSubImage(emptyBar, 0, 0, (30 - i1), emptyBar.myHeight);
    				emptyBar.drawSprite(spriteDrawX - 15, spriteDrawY - 3);
                        	}
                    } catch(Exception e) {
    			e.printStackTrace();
    		}
    	}
    Using these 2 sprites;

    FULL:


    EMPTY:


    I get this output;



    But the images don't have to be simple, you could do this for loading bar's etc aswell.

    Have fun.

    It also works with transparency from method drawSprite1.


    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Nov 2008
    Age
    26
    Posts
    994
    Thanks given
    1
    Thanks received
    3
    Rep Power
    104
    im assuming this is renamed =/

    good job, i gotta rename my client =/
    Develop VR games in Unity now
    Reply With Quote  
     

  3. #3  
    Retired. Stop PMing me.

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    14
    Posts
    7,528
    Thanks given
    1,783
    Thanks received
    2,822
    Discord
    View profile
    Rep Power
    5000
    I've been looking for this lmao.

    I saw Telenubby use this like a year ago for a custom loading bar, nice Zee, thanks.
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  4. #4  
    Rukin1


    Rukin1's Avatar
    Join Date
    Apr 2007
    Age
    28
    Posts
    5,003
    Thanks given
    228
    Thanks received
    229
    Discord
    View profile
    Rep Power
    4179
    lel sweetness thanks Zee
    Spoiler for large sig:


    Reply With Quote  
     

  5. #5  
    Tariq
    Guest
    DAMN. i wanted this also. thanks alot zee and why not just replace stuff from the cache? or is this easier
    Reply With Quote  
     

  6. #6  
    35518
    Guest
    This is the best way to draw the health and prayer orbs.
    Reply With Quote  
     

  7. #7  
    Member Market Banned Market Banned

    Zee Best's Avatar
    Join Date
    Feb 2007
    Age
    29
    Posts
    3,036
    Thanks given
    24
    Thanks received
    210
    Rep Power
    1171
    Quote Originally Posted by that one arab View Post
    DAMN. i wanted this also. thanks alot zee and why not just replace stuff from the cache? or is this easier
    Basically, this can be used for things like loading bar's, the status orbs etc, this is better than using BufferedImage to draw it since it's using the normal pixel array sprite class.


    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  8. #8  
    Renown Programmer

    Sean's Avatar
    Join Date
    May 2007
    Age
    29
    Posts
    2,758
    Thanks given
    264
    Thanks received
    1,089
    Rep Power
    4393
    Quote Originally Posted by Zee best View Post
    Basically, this can be used for things like loading bar's, the status orbs etc, this is better than using BufferedImage to draw it since it's using the normal pixel array sprite class.

    i was just goiung to say that, it be good for orbs, its a nice release dean
    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
  •