Skip to content

Commit ec1e9e7

Browse files
committed
feat: add displayobject initScale
1 parent c26e68b commit ec1e9e7

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

examples/source/js/text/text.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ text.x = 250;
1919
text.y = 200;
2020
app.stage.addChild(text);
2121

22-
var text = new InkPaint.Text("你好周杰伦! 哈哈");
23-
text.updateStyle({
22+
var text1 = new InkPaint.Text("你好周杰伦! 哈哈");
23+
text1.updateStyle({
2424
fill: "#ffffff",
2525
backgroundColor: "#00eeee",
2626
padding: 10
2727
});
28-
text.x = 450;
29-
text.y = 300;
30-
app.stage.addChild(text);
28+
text1.x = 450;
29+
text1.y = 300;
30+
app.stage.addChild(text1);
3131

3232
var bunny = InkPaint.Sprite.fromImage("source/assets/eggHead.png");
3333
bunny.x = 500;
@@ -60,8 +60,13 @@ richText.y = 350;
6060

6161
app.stage.addChild(richText);
6262

63+
var length = 10;
6364
var ticker = new InkPaint.Ticker();
6465
ticker.start();
6566
ticker.add(function() {
6667
app.render();
68+
69+
length -= 0.1;
70+
if (length <= -5) length = 10;
71+
text1.text = "你好周杰伦! 哈哈".substr(0, Math.max(0, length) >> 0);
6772
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "inkpaint",
3-
"version": "2.2.5",
3+
"version": "2.3.1",
44
"description": "InkPaint is a lightweight node.js canvas graphics animation library.",
55
"main": "./lib/index.js",
66
"license": "MIT",

src/display/DisplayObject.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import EventEmitter from "eventemitter3";
22
import { TRANSFORM_MODE } from "../const";
3+
import Bounds from "./Bounds";
34
import settings from "../settings";
45
import Transform from "./Transform";
5-
import Bounds from "./Bounds";
6-
import { Rectangle } from "../math";
76
import { uuidvx } from "../utils";
7+
import { Rectangle, Point } from "../math";
8+
import TransformStatic from "./TransformStatic";
89
import FXAAFilter from "../filters/fxaa/FXAAFilter";
910
import BlurFilter from "../filters/blur/BlurFilter";
10-
import TransformStatic from "./TransformStatic";
1111

1212
export default class DisplayObject extends EventEmitter {
1313
constructor() {
@@ -26,6 +26,7 @@ export default class DisplayObject extends EventEmitter {
2626
this.parent = null;
2727
this.worldAlpha = 1;
2828
this.filterArea = null;
29+
this.initScale = new Point(1, 1);
2930

3031
this.filters = null;
3132
this._enabledFilters = null;
@@ -422,6 +423,7 @@ export default class DisplayObject extends EventEmitter {
422423
this.fxaa = false;
423424
this.filters = null;
424425
this.transform = null;
426+
this.initScale = null;
425427
this.parent = null;
426428
this._bounds = null;
427429
this._currentBounds = null;

src/text/Text.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,14 @@ export default class Text extends Sprite {
181181
const background = style.background || style.backgroundColor;
182182
if (!background) return;
183183

184-
const context = this.context;
185-
context.fillStyle = background;
186-
context.fillRect(0, 0, this.canvas.width, this.canvas.height);
184+
const { context, canvas, text } = this;
185+
const ftext = String(text).trim();
186+
if (ftext) {
187+
context.fillStyle = background;
188+
context.fillRect(0, 0, canvas.width, canvas.height);
189+
} else {
190+
context.clearRect(0, 0, canvas.width, canvas.height);
191+
}
187192
}
188193

189194
drawLetterSpacing(text, x, y, isStroke = false) {
@@ -280,9 +285,7 @@ export default class Text extends Sprite {
280285

281286
// call sprite onTextureUpdate to update scale if _width or _height were set
282287
this._onTextureUpdate();
283-
284288
baseTexture.emit("update", baseTexture);
285-
286289
this.dirty = false;
287290
}
288291

@@ -414,13 +417,11 @@ export default class Text extends Sprite {
414417

415418
get width() {
416419
this.updateText(true);
417-
418420
return Math.abs(this.scale.x) * this._texture.orig.width;
419421
}
420422

421423
set width(value) {
422424
this.updateText(true);
423-
424425
const s = sign(this.scale.x) || 1;
425426
this.scale.x = (s * value) / this._texture.orig.width;
426427
this._width = value;
@@ -468,9 +469,7 @@ export default class Text extends Sprite {
468469
text === "" || text === null || text === undefined ? " " : text
469470
);
470471

471-
if (this._text === text) {
472-
return;
473-
}
472+
if (this._text === text) return;
474473
this._text = text;
475474
this.dirty = true;
476475
}

0 commit comments

Comments
 (0)