2010-05-20 47 views
2

我以前使用过graphics包,但不确定是否可以完成。我试图用flex编程创建一个狗耳朵效果。可以做到吗?如果不可能,我还有其他选项或库。弯曲的狗耳效应?

+2

狗耳?喜欢这个? http://bit.ly/adIv1v – spender 2010-05-20 16:25:57

+0

我还没有听说过狗耳效应。斯佩德的建议似乎很难实现:那里的+1! :) – 2010-05-20 16:42:31

+0

狗耳朵效果只是意味着纸张在一侧稍微折叠。将尝试找到一个图像。 – donpal 2010-05-20 16:45:19

回答

6

你可以逃脱的无证drawRoundRectComplex()为一个时髦的圆角版本:

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

这是从工具面板的矩形原始工具的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角形)版本应该什么样子:

dog ears

更新: 过几分钟玩这个,下面是一些舍入版本的代码,用于记录:

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; 
} 

使用软阴影,看起来不错:

dog ears rounded

您可以填写一个不错的线性渐变的角落里,你可以修改功能,使您可以选择边角圆润,并且都没有,离散动画吧,等有乐趣!

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

+0

非常感谢,都是完美的答案。 – donpal 2010-05-20 21:08:00

4

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

首先,在容器的顶角绘制一个黑色方形矩形。然后从黑色矩形的左上角开始绘制一个带白色背景的实心三角形+ 1,moveTo黑色矩形的左下角+ 1,moveTo矩形左侧+矩形宽度,最后返回到您开始的位置。

了解图形类here

+0

非常感谢,这两个都是完美的答案。 – donpal 2010-05-20 21:07:43

+0

是的,但乔治做了更多的工作,值得检查。 :) – Robusto 2010-05-20 21:17:32