[]扇形遮罩画不全画了一个很奇怪的形状但是矩形的就没问题。显示效果如下:版本号1.7.10
var p = "ui/icons/icons_skill"+data.icon + ".png";
view.icon_3.skin=p;
var im:Image=new Image();
im.skin=p;
im.setColor(Const_colorData.ColorData[0]);
im.setName("grayIcon");
view.icon_3.addChild(im);
var img:Image = view.icon_3.getChildByName("grayIcon") as Image;
processTimer = ProcessTimer.create(img,new laya.maths.Size(70,70));
processTimer.setPercentage(100);
processTimer.setType(ProcessTimer.PROGRESS_TIMER_TYPE_RECT);
processTimer.setPosition(0,0);
processTimer.setReverseDirection(true)
var percent:Number = 0;
if( data.totalDuration != 0 && data.totalDuration != -1 )
{
percent = 100 - (data.curDuration / data.totalDuration) * 100;
}
if (processTimer)
{
processTimer.setPercentage(percent)
}
下面是processTimer类
package uiLogic.core
{
import laya.display.Sprite;
import laya.maths.Size;
import laya.ui.Image;
public class ProcessTimer extends Sprite
{
public var img:Image;
public var maskSp:Sprite;
public var percent:Number;
public var type:String = "PROGRESS_TIMER_TYPE_RADIAL";
public var reverseDirection:Boolean = true;
public var spSize:Size;
public static var PROGRESS_TIMER_TYPE_RADIAL:String = "PROGRESS_TIMER_TYPE_RADIAL"
public static var PROGRESS_TIMER_TYPE_RECT:String = "PROGRESS_TIMER_TYPE_RECT"
public function ProcessTimer(size:Size)
{
this.spSize = size;
super();
}
public static function create(img:Image,size:laya.maths.Size):ProcessTimer
{
var pt:ProcessTimer = new ProcessTimer(size);
pt.createUI(img);
return pt;
}
public function createUI(img:Image):void
{
this.img = img;
maskSp = new Sprite();
maskSp.setSize(spSize);
maskSp.pos(0,0);
this.img.mask = maskSp;
}
public function drawMask():void
{
if (maskSp)
{
maskSp.graphics.clear();
var w:Number = maskSp.getSize().width;
var h:Number = maskSp.getSize().height;
switch (this.type)
{
case PROGRESS_TIMER_TYPE_RADIAL:
var r:Number = Math.sqrt(w*w + h*h);
var endAngle:Number;
if (reverseDirection)
{
endAngle = -90 + (360 * (100 - this.percent) / 100);
}
else
{
endAngle = -90 + (360 * this.percent / 100);
}
maskSp.graphics.drawPie(w*0.5, h*0.5, r, -90, endAngle, '#ffffff');
break;
case PROGRESS_TIMER_TYPE_RECT:
var height:Number;
if (reverseDirection)
{
height = (h* (100 - this.percent) / 100);
}
else
{
height = h*this.percent / 100;
}
maskSp.graphics.drawRect(0, 0, w, height, '#ffffff');
}
}
}
public function setPercentage(p:Number):void
{
this.percent = p;
drawMask();
}
public function setType(type:String):void
{
this.type = type;
drawMask();
}
public function setReverseDirection(b:Boolean):void
{
this.reverseDirection = b;
drawMask();
}
}
}
view.icon_3.skin=p;
var im:Image=new Image();
im.skin=p;
im.setColor(Const_colorData.ColorData[0]);
im.setName("grayIcon");
view.icon_3.addChild(im);
var img:Image = view.icon_3.getChildByName("grayIcon") as Image;
processTimer = ProcessTimer.create(img,new laya.maths.Size(70,70));
processTimer.setPercentage(100);
processTimer.setType(ProcessTimer.PROGRESS_TIMER_TYPE_RECT);
processTimer.setPosition(0,0);
processTimer.setReverseDirection(true)
var percent:Number = 0;
if( data.totalDuration != 0 && data.totalDuration != -1 )
{
percent = 100 - (data.curDuration / data.totalDuration) * 100;
}
if (processTimer)
{
processTimer.setPercentage(percent)
}
下面是processTimer类
package uiLogic.core
{
import laya.display.Sprite;
import laya.maths.Size;
import laya.ui.Image;
public class ProcessTimer extends Sprite
{
public var img:Image;
public var maskSp:Sprite;
public var percent:Number;
public var type:String = "PROGRESS_TIMER_TYPE_RADIAL";
public var reverseDirection:Boolean = true;
public var spSize:Size;
public static var PROGRESS_TIMER_TYPE_RADIAL:String = "PROGRESS_TIMER_TYPE_RADIAL"
public static var PROGRESS_TIMER_TYPE_RECT:String = "PROGRESS_TIMER_TYPE_RECT"
public function ProcessTimer(size:Size)
{
this.spSize = size;
super();
}
public static function create(img:Image,size:laya.maths.Size):ProcessTimer
{
var pt:ProcessTimer = new ProcessTimer(size);
pt.createUI(img);
return pt;
}
public function createUI(img:Image):void
{
this.img = img;
maskSp = new Sprite();
maskSp.setSize(spSize);
maskSp.pos(0,0);
this.img.mask = maskSp;
}
public function drawMask():void
{
if (maskSp)
{
maskSp.graphics.clear();
var w:Number = maskSp.getSize().width;
var h:Number = maskSp.getSize().height;
switch (this.type)
{
case PROGRESS_TIMER_TYPE_RADIAL:
var r:Number = Math.sqrt(w*w + h*h);
var endAngle:Number;
if (reverseDirection)
{
endAngle = -90 + (360 * (100 - this.percent) / 100);
}
else
{
endAngle = -90 + (360 * this.percent / 100);
}
maskSp.graphics.drawPie(w*0.5, h*0.5, r, -90, endAngle, '#ffffff');
break;
case PROGRESS_TIMER_TYPE_RECT:
var height:Number;
if (reverseDirection)
{
height = (h* (100 - this.percent) / 100);
}
else
{
height = h*this.percent / 100;
}
maskSp.graphics.drawRect(0, 0, w, height, '#ffffff');
}
}
}
public function setPercentage(p:Number):void
{
this.percent = p;
drawMask();
}
public function setType(type:String):void
{
this.type = type;
drawMask();
}
public function setReverseDirection(b:Boolean):void
{
this.reverseDirection = b;
drawMask();
}
}
}
没有找到相关结果
已邀请:
要回复问题请先登录
2 个回复
Laya_XS
赞同来自:
annimor
赞同来自: