Jump to content

drawing on a tile?


Recommended Posts

Posted (edited)

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
Posted

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)

Posted

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);
   }
        }
 
}
Posted

 

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
Posted (edited)

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
Posted (edited)

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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