简体   繁体   English

使用Kineticjs单击将图像旋转到角度

[英]Rotate image to angle on click with Kineticjs

I am creating a speedometer with with kineticjs and I need the ability to rotate the needle it to a specified angle when the user clicks a button. 我正在创建带有dynamicjs的速度计,并且我需要能够在用户单击按钮时将指针旋转到指定角度。 I also need to be able to set the rotation point as well since it is not in the center. 我还需要能够设置旋转点,因为它不在中心。

I am using jQuery 1.8.3 and kinetic 1.5.1 我正在使用jQuery 1.8.3和dynamic 1.5.1

Here is what I have so far: 这是我到目前为止的内容:

    var stage = new Kinetic.Stage({
        container: 'needle',
        width: 152,
        height: 152
      });
    var layer = new Kinetic.Layer();

    var imageObj = new Image();
    imageObj.onload = function() {
        var needle = new Kinetic.Image({
          x: 63,
          y: 65,
          image: imageObj,
          width: 83,
          height: 22
        });

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

        // add the layer to the stage
        stage.add(layer);
    };
    imageObj.src = 'http://example.com/assets/img/layout/dials/speedo_needle.png'); ?>';    

So taking this example how would I rotate the needle to whatever angle I want in an interval or click event? 因此,以该示例为例,如何在间隔或单击事件中将针旋转到所需的角度?

To rotate the image, use a function with imageObject.setRotation(45) where '45' is number of degrees. 要旋转图像,请使用带有imageObject.setRotation(45)的函数,其中“ 45”是度数。

To define the rotation point, set offset propertie for imageObject, or change it dynamically with imageObject.setOffsetX(100) and imageObject.setOffsetY(100) or any other number. 要定义旋转点,请为imageObject设置偏移属性,或使用imageObject.setOffsetX(100)和imageObject.setOffsetY(100)或任何其他数字动态更改它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM