1 Reply Latest reply: Jan 28, 2013 8:35 AM by DarrylBurke RSS

    How do I code a scalable game (graphic wise, SVG) in java

    986865
      Hi - think I have tried all in order to merge in SVG scalable graphics into a small test app i Eclipse now, but without luck.
      JSR 226, Batik and Salamander are all roads I have gone down through. Right now I am also watching this: http://www.youtube.com/watch?v=F_sbusEUz5w

      Most recently I came close with Salamander (but if somebody knows a better apporach, please reply)

      Here is the latest Salamander topic/issue I have been struggling with:

      In the following link an SVG image is created by code before getting rendered. At http://svgsalamander.java.net/docs/exampleCode/SVGIODemo.html this compiles flawless:

      class IconPanel extends JPanel { public static final long serialVersionUID = 0;

      final SVGIcon icon;


      public IconPanel()
      {
      StringReader reader = new StringReader(makeDynamicSVG());
      URI uri = SVGCache.getSVGUniverse().loadSVG(reader, "myImage");
      icon = new SVGIcon();
      icon.setSvgURI(uri);

      setPreferredSize(new Dimension(400, 400));
      }

      public void paintComponent(Graphics g)
      {
      final int width = getWidth();
      final int height = getHeight();

      g.setColor(getBackground());
      g.fillRect(0, 0, width, height);

      icon.paintIcon(this, g, 0, 0);
      }

      private String makeDynamicSVG()
      {
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);

      pw.println("<svg width=\"400\" height=\"400\" style=\"fill:none;stroke-width:4\">");
      pw.println(" <circle cx=\"200\" cy=\"200\" r=\"200\" style=\"stroke:blue\"/>");
      pw.println(" <circle cx=\"140\" cy=\"140\" r=\"40\" style=\"stroke:red\"/>");
      pw.println(" <circle cx=\"260\" cy=\"140\" r=\"40\" style=\"stroke:red\"/>");
      pw.println(" <polyline points=\"100 300 150 340 250 240 300 300\" style=\"stroke:red\"/>");
      pw.println("</svg>");

      pw.close();
      return sw.toString();
      }

      }

      But I want to render an SVG image that is not being created on the fly. An SVG Image I have already made on beforehand. So instead of referring to "myImage" (as in above) I want to do something like this:

      class IconPanel extends JPanel { public static final long serialVersionUID = 0;

      final SVGIcon icon;


      public IconPanel()
      {

      SVGUniverse svgUni = new SVGUniverse();
      StringReader reader = new StringReader(null);
      URI pw = svgUni.loadSVG(reader, "C:/Users/TD_DS_IS/workspaceJuno/svgSalamander/res/SVG_til_Tattoo.svg");
      icon = new SVGIcon();
      icon.setSvgURI(pw);

      setPreferredSize(new Dimension(400, 400));
      }

      public void paintComponent(Graphics g)
      {
      final int width = getWidth();
      final int height = getHeight();

      g.setColor(getBackground());
      g.fillRect(0, 0, width, height);

      icon.paintIcon(this, g, 0, 0);
      }

      private String makeDynamicSVG()
      {
      SVGUniverse svgUni = new SVGUniverse();
      StringReader reader = new StringReader(null);
      URI pw = svgUni.loadSVG(reader, "/svgSalamander/res/SVG_til_Tattoo.svg");
      return pw.toString();
      }

      }

      I want to render my own premade SVG - so which methods under SVGUniverse (or just universe as the link claims) can be used to do this?

      Edited by: 983862 on 2013-01-24 01:07