Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript KineticJS:如何将SVG精灵与KineticJS精灵一起使用?_Javascript_Html_Canvas_Kineticjs - Fatal编程技术网

Javascript KineticJS:如何将SVG精灵与KineticJS精灵一起使用?

Javascript KineticJS:如何将SVG精灵与KineticJS精灵一起使用?,javascript,html,canvas,kineticjs,Javascript,Html,Canvas,Kineticjs,我有一个SVG精灵,看起来像以下模式: Image Image Image Image Image Image Image Image Image 其中图像是一个图像,所有九个图像都是精灵。它们都在同一层上 有一个关于带有PNG文件的精灵的教程,但我找不到如何使SVG文件工作 使用SVG精灵时,如何设置帧的坐标?如何使用SVG精灵? 编辑:以下是教程的代码 <!DOCTYPE HTML> <html> <head> <style&g

我有一个SVG精灵,看起来像以下模式:

Image Image Image  
Image Image Image  
Image Image Image
其中图像是一个图像,所有九个图像都是精灵。它们都在同一层上

有一个关于带有PNG文件的精灵的教程,但我找不到如何使SVG文件工作

使用SVG精灵时,如何设置帧的坐标?如何使用SVG精灵?

编辑:以下是教程的代码

<!DOCTYPE HTML>
<html>
  <head>
    <style>
      body {
        margin: 0px;
        padding: 0px;
      }
      #container {
        background-color: #222;
        display: inline-block;
        width: 580px;
        height: 202px;
      }
      #buttons {
        position: absolute;
        top: 5px;
        left: 10px;
      }
      #buttons > input {
        padding: 10px;
        display: block;
        margin-top: 5px;
      }
    </style>
  </head>
  <body>
    <div id="container"></div>
    <div id="buttons">
      <input type="button" id="punch" value="Punch">
    </div>
    <script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v5.0.2.min.js"></script>
    <script defer="defer">
      var stage = new Kinetic.Stage({
        container: 'container',
        width: 578,
        height: 200
      });
      var layer = new Kinetic.Layer();

      var imageObj = new Image();
      imageObj.onload = function() {
        var blob = new Kinetic.Sprite({
          x: 250,
          y: 40,
          image: imageObj,
          animation: 'idle',
          animations: {
            idle: [
              // x, y, width, height (4 frames)
              2,2,70,119,
              71,2,74,119,
              146,2,81,119,
              226,2,76,119
            ],
            punch: [
              // x, y, width, height (3 frames)
              2,138,74,122,
              76,138,84,122,
              346,138,120,122
            ]
          },
          frameRate: 7,
          frameIndex: 0
        });

        // add the shape to the layer
        layer.add(blob);

        // add the layer to the stage
        stage.add(layer);

        // start sprite animation
        blob.start();

        var frameCount = 0;

        blob.on('frameIndexChange', function(evt) {
          if (blob.animation() === 'punch' && ++frameCount > 3) {
            blob.animation('idle');
            frameCount = 0;
          }
        });

        document.getElementById('punch').addEventListener('click', function() {
          blob.animation('punch');
        }, false);
      };
      imageObj.src = 'http://www.html5canvastutorials.com/demos/assets/blob-sprite.png';
    </script>
  </body>
</html>    

身体{
边际:0px;
填充:0px;
}
#容器{
背景色:#222;
显示:内联块;
宽度:580px;
高度:202px;
}
#钮扣{
位置:绝对位置;
顶部:5px;
左:10px;
}
#按钮>输入{
填充:10px;
显示:块;
边缘顶部:5px;
}
var阶段=新的动力学阶段({
容器:'容器',
宽度:578,
身高:200
});
var layer=新的动能层();
var imageObj=新图像();
imageObj.onload=函数(){
var blob=新的动能精灵({
x:250,
y:40,
图片:imageObj,
动画:“空闲”,
动画:{
闲置:[
//x、y、宽度和高度(4帧)
2,2,70,119,
71,2,74,119,
146,2,81,119,
226,2,76,119
],
冲孔:[
//x、y、宽度和高度(3帧)
2,138,74,122,
76,138,84,122,
346,138,120,122
]
},
帧率:7,
框架索引:0
});
//将形状添加到层中
图层添加(blob);
//将层添加到舞台
阶段。添加(层);
//开始精灵动画
blob.start();
var frameCount=0;
blob.on('frameIndexChange',函数(evt){
如果(blob.animation()==='punch'&&++frameCount>3){
blob.animation('idle');
帧数=0;
}
});
document.getElementById('punch')。addEventListener('click',function(){
blob.animation('punch');
},假);
};
imageObj.src=http://www.html5canvastutorials.com/demos/assets/blob-sprite.png';

由于您没有提供任何代码,请单击此处了解想法,并提供一些关于SVG逐帧动画的精彩教程。但我从不推荐它,因为在每个帧上都有一个基于向量的元素,其锚定点、曲线等彼此独立。因此,对于一小部分动画来说,它必须一次又一次地加载所有的点和颜色。您可以创建一个可以设置动画的SVG