Jump to content

drawing on a tile?


roguehippo

Recommended Posts

what is the best way to highlight a tile. im trying to iterate through a list of positions but when i try to use g.drawPolygon (as suggested by other threads on the forum) it just gives me a red underline and sys drawpolygon is undefined. did they change how tiles are highlighted? thanks!

edit for visibility of the real problem i need help with still :(

---------------------------------------------------

my gui class seems to not be able to use myPlayer().getlocation effectively because i always just get a null pointer when the code executes.

this is the snippet of code

 

JButton SetSpotButton = new JButton("Set Safe Spot");
SetSpotButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(CustomSpotButton.isSelected())
{
SafeSpot = m.myPlayer().getPosition();
}
}
});
if the button is pressed and a checkbox is checked to use the method then it tries to save the tile i am standing on.
 
also my "m" is a global in my gui so i dont know why its not working sad.png
MethodProvider m;
public Gui(MethodProvider m){
       this.m = m;
   } 
 

 

Edited by roguehippo
Link to comment
Share on other sites

i have no idea

 

hey frost, thanks for the help, but it still says that "graphics" cannot be resolved do i have to import a source into my script?

public class GodWarsDungeon extends Script { 
private Position position = new Position(0,0,0); // obviously have the correct co-ordinates
//in your onPaint do this
 
@[member='Override']
public void onPaint(Graphics2D g) {
g.draw(position.getPolygon(bot));



}

Do you have to give it a name or something?

 

 

The reason why graphics did not resolve was because by default your onPaint(Graphics2D g) is set at g so you can change that to whatever you want :P (the g part)

Link to comment
Share on other sites

facep.gif facep.gif facep.gif facep.gif  i forgot about onPaint... i havent coded in like all summer. my b


public class GodWarsDungeon extends Script { 
private Position position = new Position(0,0,0); // obviously have the correct co-ordinates
//in your onPaint do this
 
@[member='Override']
public void onPaint(Graphics2D g) {
g.draw(position.getPolygon(bot));



}

The reason why graphics did not resolve was because by default your onPaint(Graphics2D g) is set at g so you can change that to whatever you want :P (the g part)

 

this is a function i made to color the tiles of an area. im wondering if this is going to work, the only thing im worried about is it had me automatically set g2 = null. does it have to be something else? i havent tested it yet 

 

public void drawArea()
{
 
 
if(gui.ShowOverlay == true )
        {
Graphics2D g2 = null;
      
g2.setColor(Color.WHITE);
log("drawing tiles");
for(int i = 0;i < FightArea.getPositions().size(); i++ )
   {
    Polygon poly = FightArea.getPositions().get(i).getPolygon(bot);
    g2.draw(poly);
   }
        }
 
}
Link to comment
Share on other sites

 

facep.gif facep.gif facep.gif facep.gif  i forgot about onPaint... i havent coded in like all summer. my b

this is a function i made to color the tiles of an area. im wondering if this is going to work, the only thing im worried about is it had me automatically set g2 = null. does it have to be something else? i havent tested it yet 

 

public void drawArea()
{
 
 
if(gui.ShowOverlay == true )
        {
Graphics2D g2 = null;
      
g2.setColor(Color.WHITE);
log("drawing tiles");
for(int i = 0;i < FightArea.getPositions().size(); i++ )
   {
    Polygon poly = FightArea.getPositions().get(i).getPolygon(bot);
    g2.draw(poly);
   }
        }
 
}

 

 

:s

 

  • Like 1
Link to comment
Share on other sites

I'm using this fellow's "Drawing Tiles" useful snippet: http://osbot.org/forum/topic/80826-useful-methods/?hl=fill and it works perfectly. smile.png

 

My snippet iterating through Positions:

for (Position p : fishingArea.getPositions() ) {
    drawTile(script, g, p, Color.pink, Color.white, "");
}

With drawTile() slightly modified from the link's example, looking like this:

/**
 * 
 * @param script	Most likely: client.getBot().getScriptExecutor().getCurrent()
 * @param g			The Graphics2D object passed into the onPaint() method
 * @param position	The Position for the tile you are wishing to draw on
 * @param tileColor	The color that will be drawn around the border of the tile
 * @param textColor	The color of the text for the "s" parameter
 * @param s			The text you wish to display next to the tile, if any.
 */
public void drawTile(Script script, Graphics g, Position position, Color tileColor, Color textColor, String s) {
	Polygon polygon;
	    if (position != null && (polygon = position.getPolygon(script.getBot(), position.getTileHeight(script.getBot()))) != null) {
	        g.setColor(tileColor);
	        for (int i = 0; i < polygon.npoints; i++) {
	            g.setColor(new Color(0, 0, 0, 20));
	            g.fillPolygon(polygon);
	            g.setColor(tileColor);
	            g.drawPolygon(polygon);
	        }
	        g.setColor(textColor);
	        g.drawString(s, (int) polygon.getBounds().getX(), (int) polygon.getBounds().getY());
	    }
	}
Edited by jython
  • Like 1
Link to comment
Share on other sites

my gui class seems to not be able to use myPlayer().getlocation effectively because i always just get a null pointer when the code executes.

this is the snippet of code

 

JButton SetSpotButton = new JButton("Set Safe Spot");
SetSpotButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(CustomSpotButton.isSelected())
{
SafeSpot = m.myPlayer().getPosition();
}
}
});
if the button is pressed and a checkbox is checked to use the method then it tries to save the tile i am standing on.
 
also my "m" is a global in my gui so i dont know why its not working :(
MethodProvider m;
public Gui(MethodProvider m){
       this.m = m;
   } 

 

Edited by roguehippo
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...