Hi, how do i change color of some bones/slots?
I tried:
armature.getSlot("body_idle").display.color = 0xff0000;
armature.getBone("tail").display.color = 0xff0000;
If i call them before calling the animation.goToAndPlay(), they don't work, if i call them after calling every animation, it only works the first time, which is weird, like if something was overriding it.
I found here it says something about colorTransform: https://dragonbones.github.io/features.html
But armature.colorTransform property doesn't exist now :S
How to change color of some bones/slots in DragonBones?
(9 posts) (5 voices)-
Posted 1 year ago #
-
We remove it because we think it is better to let developer encapsulate interface themselves to change the color by calling DisplayObject's api directly. so that DB will not care the difference between different engines.
Posted 1 year ago # -
@superlancelot but how do i do it in starling?
I'm doing the following but it doesn't work well, the color disappears when the first animation changes, and even if i call that after every animation call it doesn't work.
armature.getBone("body").slot.display.color = 0xff0000;
armature.getSlot("body_idle").display.color = 0xff0000;Posted 1 year ago # -
@Jacowaco
I just figured out how to allow color offset on slots.
First you need make some changes in
dragonBones.starling.StarlingSlot
.
_updateColor
method is where you should look into.override protected function _updateColor():void { _renderDisplay.alpha = _colorTransform.alphaMultiplier; const mesh:Mesh = _renderDisplay as Mesh; if (mesh) { if (mesh.color != color) { mesh.color = color; } } } public function get color():uint {return _color;} public function set color(value:uint):void { if(_color != value){ _color = value; _updateColor(); } } // I discarded the color stored in _colorTransform to make it simpler. private var _color:uint = 0xffffff;
Then we can change all slots' color as the following:
const newColor:uint = 0xff0000; var slots:Vector.<Slot> = armature.getSlots(); for each (var slot:StarlingSlot in slots) { slot.color = newColor; }
Posted 2 months ago # -
@udreamer thank you very much! i will try it out
Posted 2 months ago # -
Hi...
With db5.6 you can change the color of the bones in your amarture with the new tools available.
You can check my update vid that is available here.https://youtu.be/0zbhhqFcIm4
Posted 2 months ago # -
Yes, I noticed this. Instead of changing it programmatically, we can ask the designer to change the color of the bones by this way . That's the color stored in _colorTransform which I discarded in the previous code. To keep that color, we need override super '_init' method in StarlingSlot.
override dragonBones_internal function _init(skinSlotData:SkinSlotData, rawDisplay:Object, meshDisplay:Object):void { super._init(skinSlotData, rawDisplay, meshDisplay); _color = (uint(_colorTransform.redMultiplier * 0xFF) << 16) + (uint(_colorTransform.greenMultiplier * 0xFF) << 8) + uint(_colorTransform.blueMultiplier * 0xFF); }
Not tested , but it should work.
Posted 2 months ago # -
@Poedil88 @superlancelot
There is a bug in Starling2.x version ofStarlingSlot
existing for a long time that would cause any changing on the bones which contains meshes won't update color correctly. Here's the line of code in_updateColor
method which causes that error.const quad:Quad = _renderDisplay as Quad;
Due to structure changing in Starling2.x, Quad is extended from Mesh. And this line causes all mesh object casted as null value.
Posted 2 months ago # -
Thanks for sharing friend its really knowledgeable thread.
Posted 2 months ago #
Reply
You must log in to post.