我以前使用過graphics
包,但不確定是否可以完成。我試圖用flex編程創建一個狗耳朵效果。可以做到嗎?如果不可能,我還有其他選項或庫。彎曲的狗耳效應?
Q
彎曲的狗耳效應?
2
A
回答
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角形)版本應該什麼樣子:
更新: 過幾分鐘玩這個,下面是一些舍入版本的代碼,用於記錄:
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
+0
非常感謝,都是完美的答案。 – donpal 2010-05-20 21:08:00
4
相關問題
- 1. CSS3彎曲效果
- 2. CSS3彎曲/透視效果
- 3. 三JS彎曲(彎曲)CSS3DObject
- 4. 在彎曲項目中顯示彎曲
- 5. 用CSS/JS/jQuery彎曲圖像效果?
- 6. 龜彎曲線
- 7. 直線彎曲
- 8. 彎曲圖像
- 9. 調用彎曲
- 10. 彎曲的UITableView/UIScrollView
- 11. Gef BendPoints彎曲的
- 12. 彎曲的Y軸
- 13. 轉換捲曲彎曲
- 14. Android彎曲查看畫布以產生捲曲效果
- 15. 彎曲度輸出
- 16. ,動態彎曲verticalaxisrenderers
- 17. `UINavigationBar`彎曲擴展?
- 18. 彎曲曲線內的折線圖
- 19. 彎曲的線條圖案
- 20. 在側面彎曲的Div
- 21. 奇怪的彎曲行爲
- 22. 彎曲的底部視圖
- 23. 不同的圖標彎曲
- 24. css中的彎曲邊框
- 25. 彎曲 - 的SWFLoader - 認證
- 26. 彎曲的css盒子
- 27. 在IE8彎曲的角落?
- 28. 「彎曲」3D中的UIView
- 29. PHP功能彎曲/扭曲圖像
- 30. 日期時間彎曲
狗耳?喜歡這個? http://bit.ly/adIv1v – spender 2010-05-20 16:25:57
我還沒有聽說過狗耳效應。斯佩德的建議似乎很難實現:那裏的+1! :) – 2010-05-20 16:42:31
狗耳朵效果只是意味着紙張在一側稍微摺疊。將嘗試找到一個圖像。 – donpal 2010-05-20 16:45:19