[messages] [Developers] Mapping piece position in draw()

djsullivan davidsullivan317 at gmail.com
Tue Aug 27 13:39:15 MST 2013


I'm building a custom component and would like to draw on the map
"above" a selected game piece. I've implemented the Drawable interface
and have everything wired up so I know what piece is selected and I can
draw to the map, but I'm struggling to figure out how to map the piece's
location to the Graphics context. I'll need to account for zooming, etc.


So what should Center be in the following code... 


Code:
        
GamePiece[] gamePieces = map.getPieces();
Point center;
        for (int i = 0; i < gamePieces.length; ++i) {
            if (gamePieces[i] instanceof Stack) {
                for (Iterator<GamePiece> it = ((Stack)
gamePieces[i]).getPiecesIterator();it.hasNext();) {
                    GamePiece child = it.next();
                   
if(child.getProperty(Properties.SELECTED).equals(Boolean.TRUE)) {
                        center = ???;
                    }
                }
            }
            else  {
               
if(gamePieces[i].getProperty(Properties.SELECTED).equals(Boolean.TRUE))
{
                    center = ???;
                }
            }
        }




... so when I draw my component "Center" is the center of the selected
piece in the graphics context. 


Code:
   
    public void draw(Graphics g, Map map) {

        if (center != null) {

            // draw a circle around the selected piece
            Graphics2D gg = (Graphics2D) g;
            g.setColor(Color.RED);
            gg.setStroke(new BasicStroke(3));
            gg.drawOval(center.x,center.y,100,100);
        }
    }




Thanks, David

_______________________________________________
Read this topic online here:
http://www.vassalengine.org/forum/viewtopic.php?p=41841#p41841


More information about the messages mailing list