• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Junilu Lacar
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst
  • Peter Rooke
  • Mikalai Zaikin
Bartenders:
  • Himai Minh

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 (Java Micro Edition), 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?
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic