繁体   English   中英

弯曲的狗耳效应?

[英]Dog ear effect in flex?

我之前使用过graphics包,但不确定是否可以这样做。 我正在尝试用flex编程创建狗耳效果。 可以吗? 如果不可能,我还有哪些其他选项或库。

您可以使用未记录的drawRoundRectComplex()来获得时尚的圆角版本:

graphics.drawRoundRectComplex(x, y, width, height, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);

它是Tools Panel中Rectangle Primitive Tools的actionscript版本。

当然,正如@Robusto建议的那样,你可以绕过Graphics类。 同时,这是一个简单的45角度版本:

var dogEars:Sprite = getDogEars45(200,100,15,0x009900,0x007700);
dogEars.x = dogEars.y = 50;
addChild(dogEars);


function getDogEars45(width:Number,height:Number,cornerSize:Number,baseFill:Number,highlightFill:Number):Sprite{
    var rect:Sprite = new Sprite();
    var base:Shape = new Shape();
    base.graphics.beginFill(baseFill);
    base.graphics.lineTo(width-cornerSize,0);
    base.graphics.lineTo(width,cornerSize);
    base.graphics.lineTo(width,height);
    base.graphics.lineTo(0,height);
    base.graphics.lineTo(0,0);
    rect.addChild(base);
    var corner:Shape = new Shape();
    corner.graphics.beginFill(highlightFill);
    corner.graphics.lineTo(cornerSize,cornerSize);
    corner.graphics.lineTo(0,cornerSize);
    corner.graphics.lineTo(0,0);
    corner.graphics.endFill();
    rect.addChild(corner);
    corner.x = width-cornerSize;
    return rect;
}

这是粗糙(45角度)版本的样子:

狗耳朵

更新:有几分钟玩这个,这里有一些圆形版本的代码,用于记录:

var dogEarsRounded:Sprite = getFlippedCornerRect(200,150,25,0x009900,0x00CC00);
dogEarsRounded.x = dogEarsRounded.y = 150;
addChild(dogEarsRounded);

var dogEarsRounded2:Sprite = getFlippedCornerRoundedRect(200,150,15,35,0x990000,0xCC0000);
dogEarsRounded2.x = dogEarsRounded2.y = 200;
addChild(dogEarsRounded2);

var dropShadow:DropShadowFilter = new DropShadowFilter(2,30,0,.5,2,2);
dogEarsRounded.filters = dogEarsRounded2.filters = [dropShadow];

function getFlippedCornerRect(width:Number,height:Number,cornerSize:Number,mainFill:int,cornerFill:int):Sprite{
    var result:Sprite = new Sprite();
    var topRight:Shape = new Shape();
    topRight.graphics.beginFill(mainFill);
    topRight.graphics.lineTo(width-cornerSize,0);
    topRight.graphics.lineTo(width,cornerSize);
    topRight.graphics.lineTo(width,height);
    topRight.graphics.lineTo(0,height);
    topRight.graphics.lineTo(0,0);
    topRight.graphics.endFill();
    result.addChild(topRight);
    var corner:Shape = new Shape();
    corner.graphics.beginFill(cornerFill);
    corner.graphics.curveTo(0,cornerSize,cornerSize,cornerSize);
    corner.graphics.lineTo(0,0);
    corner.graphics.endFill();
    result.addChild(corner);
    corner.x = width-cornerSize;
    return result;
}

function getFlippedCornerRoundedRect(width:Number,height:Number,rectRadius:Number,cornerSize:Number,mainFill:int,cornerFill:int):Sprite{
    var result:Sprite = new Sprite();
    var topRight:Shape = new Shape();
    var hw:Number = width * .5;
    var hh:Number = height* .5;
    topRight.graphics.beginFill(mainFill);
    topRight.graphics.lineTo(hw-cornerSize,0);
    topRight.graphics.lineTo(hw,cornerSize);
    topRight.graphics.lineTo(hw,hw);
    topRight.graphics.lineTo(0,hw);
    topRight.graphics.lineTo(0,0);
    topRight.graphics.endFill();
    topRight.x = hw;
    result.addChild(topRight);
    var corner:Shape = new Shape();
    corner.graphics.beginFill(cornerFill);
    corner.graphics.curveTo(0,cornerSize,cornerSize,cornerSize);
    corner.graphics.lineTo(0,0);
    corner.graphics.endFill();
    result.addChild(corner);
    corner.x = width-cornerSize;
    var topLeft:Shape = new Shape();
    topLeft.graphics.beginFill(mainFill);
    topLeft.graphics.drawRoundRectComplex(0, 0, hw, hh, rectRadius, 0,0,0);
    topLeft.graphics.endFill();
    result.addChild(topLeft);
    var bottomLeft:Shape = new Shape();
    bottomLeft.graphics.beginFill(mainFill);
    bottomLeft.graphics.drawRoundRectComplex(0, 0, hw, hh, 0, 0,rectRadius,0);
    bottomLeft.graphics.endFill();
    bottomLeft.y = hh;
    result.addChild(bottomLeft);
    var bottomRight:Shape = new Shape();
    bottomRight.graphics.beginFill(mainFill);
    bottomRight.graphics.drawRoundRectComplex(0, 0, hw, hh, 0, 0,0,rectRadius);
    bottomRight.graphics.endFill();
    bottomRight.x = hw;
    bottomRight.y = hh;
    result.addChild(bottomRight);
    return result;
}

使用柔和的阴影,看起来不错:

狗耳朵圆润

你可以用一个漂亮的线性渐变填充角落,你可以修改这个功能,这样你就可以选择哪些角是圆角的,哪些角不是,离散地为它设置动画等等。玩得开心!

我现在理解狗的耳朵,只是想知道折角处发生了什么:P

你可以使用图形对象做一个简单的版本。

首先,在容器的顶角绘制一个黑色方形矩形。 然后绘制一个带有白色背景的填充三角形,从暗矩形的左上角开始+ 1,移动到暗矩形的左下角+ 1,向左移动矩形+矩形宽度,最后返回到开始的位置。

在这里了解Graphics类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM