2013-02-15 7 views
0

J'essaie de faire un jeu svg. Mais je ne peux pas obtenir un fichier svg (créé avec inkscape) dans mon jeu.Un fichier SVG dans un jeu SVG?

Je suis au courant et Embed l'utilisation d'objets et iframes:

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

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

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

Mais cela ne fonctionne pas, il saute en dehors du jeu svg.

Est-il possible de placer un fichier svg dans une autre balise svg? Ou devrais-je m'en tenir à des jeux de toile?

+1

fournir un lien vers le jeu et nous pouvons voir ce que le problème est. Sans cela, il y a très peu de choses à faire. –

+0

Je ne l'ai pas encore en ligne, mais la chose est que je ne sais pas par où commencer. Je ne sais pas comment ajouter un fichier .svg pour apparaître dans un jeu svg. – Slulego

Répondre

0

Voulez-vous charger dynamiquement un fichier SVG dans un fichier SVG existant ou voulez-vous plusieurs objets SVG dans un fichier SVG - comme ceci:

<?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

Ce presque ce que je cherchais, Seulement comment dirais-je, charger 'objects/spaceship.svg' sur l'écran à l'intérieur du svg principal? Ou est-ce possible? – Slulego

+0

Essayez cette question: http://stackoverflow.com/questions/7215009/how-to-reference-external-svg-file-in-svg-correctly – BigMac66

Questions connexes