当前位置:  开发笔记 > 编程语言 > 正文

弯曲的狗耳效应?

如何解决《弯曲的狗耳效应?》经验,为你挑选了1个好方法。

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



1> George Profe..:

您可以使用未记录的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

推荐阅读
wangtao
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有