2013-02-15 47 views
0

我正在尝试制作一个svg游戏。 但我无法获得一个svg文件(用inkscape制作)在我的游戏中发生。SVG游戏中的SVG文件?

我知道嵌入和使用对象和iframe中的:

<embed src="spaceship.svg" type="image/svg+xml" /> 

<object data="spaceship.svg" type="image/svg+xml"></object> 

<iframe src="spaceship.svg"></iframe> 

但是,这并不工作,它跳SVG游戏之外。

是否可以将svg文件放入另一个svg标签中? 或者我应该坚持帆布游戏?

+1

提供一个链接到游戏中,我们可以看到什么问题是。没有这一点,就没有多少进展。 – 2013-02-15 08:45:06

+0

我还没有在线,但事情是我不知道从哪里开始。我不知道如何添加一个.svg文件在svg游戏中显示。 – Slulego 2013-02-15 14:23:57

回答

0

你想一个SVG文件动态加载到现有的SVG文件或者你想在SVG文件中的多个SVG对象 - 就像这样:

<?xml version="1.0" standalone="no"?> 
<!DOCTYPE svg PUBLIC "-//W3E//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> 

<svg preserveAspectRatio="none" viewBox="0 0 10000 10000" version="1.1" xmlns="http://www.w3.org/2000/svg" onload="init();"> 
    <script type="text/ecmascript"><![CDATA[ 
     function init() 
     { 
     alert(document.getElementById("map_line")); 
     } 
    ]]></script> 

    <svg id="map" x="0" y="0" width="7500" height="10000" preserveAspectRatio="none" viewBox="0 0 10000 10000" cursor="crosshair" version="1.1" xmlns="http://www.w3.org/2000/svg"> 
     <rect x="0" y="0" width="10000" height="10000" fill="black" /> 
     <line id="map_line" x1="0" y1="0" x2="10000" y2="10000" stroke="red" stroke-width="25" /> 
    </svg> 

    <svg id="mini_map" x="7500" y="0" width="2500" height="2500" preserveAspectRatio="none" viewBox="0 0 10000 10000" cursor="crosshair" version="1.1" xmlns="http://www.w3.org/2000/svg"> 
     <rect x="0" y="0" width="10000" height="10000" stroke-width="10" stroke="silver" fill="black" /> 
     <line x1="0" y1="0" x2="10000" y2="10000" stroke="red" stroke-width="25" /> 
    </svg> 

    <svg id="info" x="7500" y="2500" width="2500" height="7500" preserveAspectRatio="none" viewBox="0 0 1000 1000" cursor="default" version="1.1" xmlns="http://www.w3.org/2000/svg"> 
    <rect x="0" y="0" width="1000" height="1000" fill="#333333" /> 
    <line x1="0" y1="0" x2="1000" y2="1000" stroke="red" stroke-width="25" /> 
    </svg> 
</svg> 
+0

这几乎是我正在寻找的,只是我会怎么说,加载'objects/spaceship.svg'到主svg的屏幕上?或者可能呢? – Slulego 2013-02-15 18:00:26

+0

试试这个问题:http://stackoverflow.com/questions/7215009/how-to-reference-external-svg-file-in-svg-correctly – BigMac66 2013-02-15 18:13:22