public SLabel(CharSequence text, Label.LabelStyle style) { label = new VLabel(text, style); addActor(label); setSize(label.getPrefWidth(), label.getPrefHeight()); setColor(label.getColor()); }
public VLabel(CharSequence text, LabelStyle style) { super(append(text, style), style); setSize(getPrefWidth(), getPrefHeight()); setColor(style.fontColor); fontCache = getBitmapFontCache(); }
public void setFontScale(float fontScaleX, float fontScaleY) { label.setFontScale(fontScaleX, fontScaleY); setSize(label.getPrefWidth(), label.getPrefHeight()); }
public void setFontScale(float fontScaleX, float fontScaleY) { super.setFontScale(fontScaleX, fontScaleY); setSize(getPrefWidth(), getPrefHeight()); }
public void drawLabel(Batch batch, float parentAlpha) { validate(); if (getStyle().background != null) { batch.setColor(1,1,1,getColor().a); float padding=getHeight()*0.15f; float paddingX=getStyle().font.getSpaceWidth()*0.5f; getStyle().background.draw(batch, getX()-paddingX, getY(), getWidth()+paddingX*2, getHeight()+padding); } if (isStroke) { strokeColor.a = getColor().a; fontCache.tint(strokeColor); for (int i = 0; i < dxs.length; i++) { fontCache.setPosition(getX() + dxs[i] * strokeWidth, getY() + dys[i] * strokeWidth + strokeWidth); fontCache.draw(batch); } fontCache.setPosition(getX(), getY() + strokeWidth); fontCache.tint(getColor()); fontCache.draw(batch); } else { fontCache.setPosition(getX(), getY() + strokeWidth); fontCache.tint(getColor()); fontCache.draw(batch); } } }
public void draw(Batch batch, float parentAlpha) { switch (shadowOption) { case Disable: //关闭阴影特效 drawLabel(batch, parentAlpha); break; case Projection: //投影效果 oldShadowAlpha = shadowColor.a; shadowColor.a = getColor().a; fontCache.tint(shadowColor); fontCache.setPosition(getX() + shadowOffsetX, getY() + shadowOffsetY); fontCache.draw(batch); shadowColor.a = oldShadowAlpha; drawLabel(batch, parentAlpha); break; case Smear: //拖影效果 shadowColor.a = getColor().a; while (Math.abs(offsetX) > 0 && Math.abs(offsetY) > 0) { offsetX += off; offsetY = k * offsetX; if (isStroke) { validate(); for (int i = 0; i < dxs.length; i++) { fontCache.tint(shadowColor); fontCache.setPosition(getX() + offsetX + dxs[i] * strokeWidth, getY() + offsetY + dys[i] * strokeWidth + strokeWidth); fontCache.draw(batch); fontCache.setPosition(getX() + offsetX, getY() + offsetY); fontCache.draw(batch);
if (obj != null) { Model model = (Model) obj; lab_msg.setColor(model.labColor); if (model.labStrokeColor != null) lab_msg.setStroke(model.labStrokeColor); lab_msg.setText(model.messge); float height = lab_msg.getPrefHeight() + game.getDefaultFontSize(); img_bg.setHeight(height); img_bg.setPosition(getWidth() / 2, getHeight() / 2, Align.center);
public void act(float delta){ super.act(delta); if(getActions().size>0){ fontCache.tint(getColor()); } }
lab_title2.addAction(Actions.forever(Actions.sequence(Actions.alpha(0,1),Actions.alpha(1,1)))); VLabel lab_title3 = game.getLabel("emoji测试◐◐").setColor(Color.YELLOW).setPosition(getWidth() / 2 , getTop() - 70, Align.top).touchOff().show(); lab_title3.addAction(Actions.forever(Actions.sequence(Actions.alpha(0,1),Actions.alpha(1,1)))); VLabel lab_title4 = game.getLabel("emoji带描边测试◐◐").setColor(Color.CYAN).setPosition(getWidth() / 2 , getTop() - 100, Align.top).touchOff().setStroke(Color.BLUE).show(); lab_title4.addAction(Actions.forever(Actions.sequence(Actions.alpha(0,1),Actions.alpha(1,1)))); lab_title5.setBackground(game.getRectColorDrawable(1,1,Color.ORANGE)); lab_test1.addAction(Actions.forever(Actions.sequence(Actions.scaleTo(0.5f, 0.5f, 1), Actions.color(Color.WHITE, 1), Actions.scaleTo(1f, 1f, 1), Actions.color(Color.RED, 1)))); SLabel lab_test2 = game.getSLabel("测试可缩放字体控件").setOrigin(Align.center).setColor(Color.YELLOW).setPosition(getRateX(0.5f), getRateY(0.4f), Align.center).show(); lab_test2.addAction(Actions.forever(Actions.sequence(Actions.scaleTo(0.5f, 0.5f, 1), Actions.color(Color.CYAN, 1), Actions.scaleTo(1f, 1f, 1), Actions.color(Color.RED, 1))));
/** * 创建Label */ public UI<VLabel> getLabel(String text, LabelStyle style) { return getUI(new VLabel(text, style)); } /**