SVG sprite and alpha
Neogene

Hi, i created a simple sprite using an svg, but the alpha doesn't seem to work, i've tried with both fadeOpacity and alpha_ functions without success. I've triead too to setDirty after the following line without success.

  var dotSprite = new Sprite("filename.svg");  dotSprite.setSize(dotSize, dotSize);  dotSprite.setDrawFunction(wade.drawFunctions.fadeOpacity_(0, 1, 2, dotSprite.draw));
dotSprite.setDrawFunction(wade.drawFunctions.alpha_(0.4,dotSprite.draw));     

  wade.addSceneObject(new SceneObject(dotSprite, 0, 100, 100));

 

All 5 Comments
tumble

Hello

 

I had this problem too. I discovered that it was a bug in Chrome, but they fixed it recently. I dont know if it is the same problem for you if you are using Chrome.

 

http://code.google.com/p/chromium/issues/detail?id=261177

Gio

Hi

 

In general, browsers don't play nice with svg and canvas used together. Do you want to send us the specific svg that you are trying to use and can you tell us which browser you are using? So we can have a look here.

 

A possible workaround could be this (before changing the draw function). I don't know if it's going to solve your problem, it might do:

dotSprite.drawToImage('mySvg');dotSprite = new Sprite('mySvg');

Sprite.drawToImage draws to an off-screen canvas, so this will draw the initial unmodified svg to a new canvas object. Then you create a sprite that uses this canvas, and all alpha operations should work normally.

Neogene

Ok tests:

 

Mac: 

Firefox  latest ok.

Chrome latest ok.

 

Safari 7.1.3 - not working (using the fix you suggested yes)

Gio

Sorry just to make sure I understand: does it work correctly on Mac Safari when you draw the svg to an off-screen canvas first?

Neogene

yes this way works:

 

var dotSprite = new Sprite("lamp1.svg");
dotSprite.setSize(dotSize, dotSize);

dotSprite.drawToImage('mySvg');
dotSprite = new Sprite('mySvg');
dotSprite.setDrawFunction(wade.drawFunctions.alpha_(0.4,dotSprite.draw));
 

This not:

 

var dotSprite new Sprite("lamp1.svg");

dotSprite.setSize(dotSizedotSize);

dotSprite.setDrawFunction(wade.drawFunctions.alpha_(0.4,dotSprite.draw));

Post a reply
Add Attachment
Submit Reply
Login to Reply