alpha field does not work well in children

Bug #924051 reported by Robert
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
jeash
Incomplete
Medium
Unassigned

Bug Description

The solution is to modify the DisplayObject.hx by adding this:

       public var alpha(jeashGetAlpha, jeashSetAlpha):Float;
       var _alpha:Float;
       .
       .
       .
       function jeashGetAlpha():Float
 {
  if (parent != null)
   return _alpha * parent.alpha;

  return _alpha;
 }

 function jeashSetAlpha(a:Float):Float
 {
  _alpha = a;
  return a;
 }

I have tested by myself and seems to work fine.

PD: I'm not using NME, just jeash.

Revision history for this message
Niel Drummond (niel-drummond) wrote :

Hey,

I think I need to test this a little, because alpha already pre-multiplies if you are a child of a container that is drawn through a Bitmap.draw op.. Do you have a small example where you know this works ?

Changed in jeash:
status: New → Fix Committed
milestone: none → 0.8.8
Revision history for this message
deep (system-grand) wrote :

Incorrect fix, a

simple demo

var a:Sprite = new Sprite();
a.alpha = 0.5;
stage.addChild(a);

var b = new Sprite();
b.alpha = 0.5;
a.addChild(b);

trace(b.alpha);
trace(b.transform.colorTransform);
trace(b.transform.concatenatedColorTransform);

--flash trace

Main.hx:34: 0.5
Main.hx:35: (redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=0.5, redOffset=0, greenOffset=0, blueOffset=0, alphaOffset=0)
Main.hx:36: (redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=0.25, redOffset=0, greenOffset=0, blueOffset=0, alphaOffset=0) // tada 0.25 alpha

--js trace

Main.hx:34: 0.5
Main.hx:35: { redMultiplier : 1, greenMultiplier : 1, blueMultiplier : 1, alphaMultiplier : 1, redOffset : 0, greenOffset : 0, blueOffset : 0, alphaOffset : 0, color : 0 }
// in jeash expected concatenatedColorTransform

-- cpp trace (nme)

Main.hx:34: 0.5
Main.hx:35: 0.25 // alphaMultiplier // strange behaviour, but more correct
Main.hx:36: 0.5 // concatenatedColorTransform.alphaMultiplier

Revision history for this message
deep (system-grand) wrote :

Look at this help page

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/geom/Transform.html#concatenatedColorTransform

A ColorTransform object representing the combined color transformations applied to the display object and all of its parent objects, back to the root level. If different color transformations have been applied at different levels, all of those transformations are concatenated into one ColorTransform object for this property.

Revision history for this message
Robert (carcasses) wrote :

Great work Deep! Sorry I couldn't provide you guys more help, but I detected it in a very complicated piece of code I built and honestly I haven't had much time recently. Good work and keep doing it well!

Revision history for this message
Niel Drummond (niel-drummond) wrote :

thanks for catching.. and the test case! I will fix it asap.

Changed in jeash:
status: Fix Committed → Incomplete
Revision history for this message
deep (system-grand) wrote :
Revision history for this message
Niel Drummond (niel-drummond) wrote :

ColorTransform on a displayobject.tranform was never really implemented (just stubbed). Otherwise, the alpha values are now working as the OP suggested.

I am looking at Jangaroo's implementation, but just from reading the code it seems like they have also stubbed the colorTransform method on the displayobject.transform code path, and is only implemented it on BitmapData.

I think the reason for this is mainly because a naive implementation of colorTransform is very slow on javascript, and if you have someone adding a colortransform and then writing new graphics calls to the same object on every enter_frame (which is quite common), then you will probably get a browser crash.

So, I need to look into it in more detail to check if there's a faster/better way to implement this.

As to the github question, this is because github is too slow, it doesn't support the git:// protocol, I have a better bug tracker (launchpad), github is not open source, I like a more minimal interface, some github features are really aiming towards a facebook for coders, and it sucks reading on any phone I ever used..

Revision history for this message
deep (system-grand) wrote :

Current fix broke more things.

Exemple:

var a:Sprite = new Sprite();
a.alpha = 0.5;
stage.addChild(a);

var b = new Sprite();
a.addChild(b);

b.alpha = 0.5;
trace(b.alpha); // 0.25

b.alpha += 0.5;
trace(b.alpha); // flash9: 1 , jeash: 0.375 %)

Need to use separete concatenatedColorTransform and calculate result alpha separete from getJeashAlpha. You can just invalidate alpha then change alpha. NME calc result alpha too, but doesn't broke something

Revision history for this message
Niel Drummond (niel-drummond) wrote :

i've reverted the change, I don't really have much time this week, so it'll have to wait.

also, doesn't b.alpha += 0.5 expand into b.jeashSetAlpha(b.jeashGetAlpha() /* 0.25 */ + 0.5) ?

Revision history for this message
deep (system-grand) wrote :

IF you reverted all ok.

With this patch b.jeashSetAlpha(b.jeashGetAlpha() /* 0.25 */ + 0.5)
and g.jeashGetAlpha() expand into parent.alpha * 0.75 = 0.375

Changed in jeash:
importance: Undecided → Medium
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.