caleb531 / jcanvas

A jQuery plugin that makes the HTML5 canvas easy to work with.
https://projects.calebevans.me/jcanvas/
MIT License
626 stars 192 forks source link

Issue with rotate in function addLayer #334

Closed Ikes72000 closed 6 years ago

Ikes72000 commented 6 years ago

Hi,

I have create a function which allows me to display an image on which is made a rotation, from an angle passed in parameter. But I have a problem, the angle of rotation is not although taken into account, but the angle value received by the function is correct.

function drawAzimutPlan(_angle = '0')
{
  console.log('angle => ' + _angle);
  console.log('test => ' + parseInt(_angle, 10));
    $('#azimutPlan').addLayer({
        type: 'image',
        name: 'wall2',
        source: 'plugins/shutters/resources/images/window.png',
        x: 0, y: 0,
        fromCenter: false,

      rotate: parseInt(_angle, 10)
   })
        .drawLayers();  
}

If i add a setLayer function between addLayer() and drawLayers(), like this, i work.

function drawAzimutPlan(_angle = '0')
{
  console.log('angle => ' + _angle);
  console.log('test => ' + parseInt(_angle, 10));
    $('#azimutPlan').addLayer({
        type: 'image',
        name: 'wall2',
        source: 'plugins/shutters/resources/images/window.png',
        x: 0, y: 0,
        fromCenter: false,

      rotate: parseInt(_angle, 10)
   })
      .setLayer('wall2', {
       rotate: parseInt(_angle, 10)
        })
        .drawLayers();  
}

Why?

It also works if I force the value of the variable _angle in my function and without using setLayer().

function drawAzimutPlan(_angle = '0')
{
  _angle = '45';
  console.log('angle => ' + _angle);
  console.log('test => ' + parseInt(_angle, 10));
    $('#azimutPlan').addLayer({
        type: 'image',
        name: 'wall2',
        source: 'plugins/shutters/resources/images/window.png',
        x: 0, y: 0,
        fromCenter: false,

      rotate: parseInt(_angle, 10)
   })
        .drawLayers();  

Thanks.

Ikes72000 commented 6 years ago

I find the problem, not from jCanvas.