feathersui / feathersui-starling

User interface components for Starling Framework and Adobe AIR
https://feathersui.com/learn/as3-starling/
Other
915 stars 386 forks source link

Button: scaleWhenDown doesn't unscale back to 1 #1742

Closed CrazyFlasher closed 6 years ago

CrazyFlasher commented 6 years ago

Hi, I setted button.scaleWhenDown = 1.2; to button style, but after click it doesn't return back to normal scale: gif

CrazyFlasher commented 6 years ago

This works as ugly workaround :)

                private function setButtonStyles(button:Button):void
        {
            button.addEventListener(FeathersEventType.STATE_CHANGE, function ():void
            {
                if (button.currentState == ButtonState.DOWN)
                {
                    button.pivotX = button.width / 2;
                    button.pivotY = button.height / 2;
                    button.scale = 1.2;
                } else
                {
                    button.scale = 1.0;
                }
            });
        }
joshtynjala commented 6 years ago

I'm afraid that I cannot reproduce this issue. I tried the following code, and the button's scale returned to 1.0 as expected.

var button:Button = new Button();
button.label = "Hello";
button.move(50, 50);
button.scaleWhenDown = 1.2;
this.addChild(button);
CrazyFlasher commented 6 years ago

I think there are some extra conditions I need to investigate, because some buttons work fine. I'll investigate ASAP and provide more detailed info

CrazyFlasher commented 6 years ago

This is weird, but I cannot reproduce it on my home machine...I'll investigate more

CrazyFlasher commented 6 years ago

By the way, is there a simple way to animate scaling?

joshtynjala commented 6 years ago

You can animate scaleX and scaleY with a regular Tween. However, that doesn't work exactly the same as scaleWhenDown. scaleWhenDown doesn't affect layouts, but scaleX and scaleY might.

CrazyFlasher commented 6 years ago

This is really weird, but this happens with some textures from atlas: gif1 If I use other textures, it works fine. The code is simple:

private function setGuiScreenAddSilverStyles(button:Button):void
{
    button.setScaleForState(ButtonState.DOWN, 1.2);

    button.defaultSkin = ift.imageFromTexture(TexturesNames.GENERAL_ADD_COINS_BTN);
}

I've attached atlas. Texture name is General/add-coins-btn.png ui.zip

joshtynjala commented 6 years ago

I tried the following code, but I still cannot reproduce the issue.

[Embed(source="ui.png")]
private static const ATLAS_IMAGE:Class;

[Embed(source="ui.xml",mimeType="application/octet-stream")]
private static const ATLAS_XML:Class;
var atlas:TextureAtlas = new TextureAtlas(Texture.fromEmbeddedAsset(ATLAS_IMAGE), XML(new ATLAS_XML()));
var button:Button = new Button();
button.move(50, 50);
button.setScaleForState(ButtonState.DOWN, 1.2);
button.defaultSkin = new ImageSkin(atlas.getTexture("General/add-coins-btn.png"));
this.addChild(button);

I also tried with keepDownStateOnRollOut, and that is working correctly too.

CrazyFlasher commented 6 years ago

Ok, I'll try to reproduce it in simple project and attach it here soon

CrazyFlasher commented 6 years ago

OK, the issue was in skipUnchangedFrames setted to true :) This is a good feature of Starling 2. Need to think, how to keep this flag enabled. Any suggestions?

joshtynjala commented 6 years ago

I'm pretty sure that I had skipUnchangedFrames enabled when I was trying to reproduce this issue. However, this is a good clue. If I can figure out how to get the button to change state without modifying the display list, I may be able to reproduce it now.