- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
- 345
- 346
- 347
- 348
- 349
- 350
- 351
- 352
- 353
- 354
- 355
- 356
- 357
- 358
- 359
- 360
- 361
- 362
- 363
- 364
- 365
- 366
- 367
- 368
- 369
- 370
- 371
- 372
- 373
- 374
- 375
- 376
- 377
- 378
- 379
- 380
- 381
- 382
- 383
- 384
- 385
- 386
- 387
- 388
- 389
- 390
- 391
- 392
- 393
- 394
- 395
- 396
- 397
- 398
- 399
- 400
- 401
- 402
- 403
- 404
- 405
- 406
- 407
- 408
- 409
- 410
- 411
- 412
- 413
- 414
- 415
- 416
- 417
- 418
- 419
- 420
- 421
- 422
- 423
- 424
- 425
- 426
- 427
- 428
- 429
- 430
- 431
- 432
- 433
- 434
- 435
- 436
- 437
- 438
- 439
- 440
- 441
- 442
- 443
- 444
- 445
- 446
- 447
- 448
- 449
- 450
- 451
- 452
- 453
- 454
- 455
- 456
- 457
- 458
- 459
- 460
- 461
- 462
- 463
- 464
- 465
- 466
- 467
- 468
- 469
- 470
- 471
- 472
- 473
- 474
- 475
- 476
- 477
- 478
- 479
- 480
- 481
- 482
- 483
- 484
- 485
- 486
- 487
- 488
- 489
- 490
- 491
- 492
- 493
- 494
- 495
- 496
- 497
- 498
- 499
- 500
- 501
- 502
- 503
- 504
- 505
- 506
- 507
- 508
- 509
- 510
- 511
- 512
- 513
- 514
- 515
- 516
- 517
- 518
- 519
- 520
- 521
- 522
- 523
- 524
- 525
- 526
- 527
- 528
- 529
- 530
- 531
- 532
- 533
- 534
- 535
- 536
- 537
- 538
- 539
- 540
- 541
- 542
- 543
- 544
- 545
- 546
- 547
- 548
- 549
- 550
- 551
- 552
- 553
- 554
- 555
- 556
- 557
- 558
- 559
- 560
- 561
- 562
- 563
- 564
- 565
- 566
- 567
- 568
- 569
- 570
- 571
- 572
- 573
- 574
- 575
- 576
- 577
- 578
- 579
- 580
- 581
- 582
- 583
- 584
- 585
- 586
- 587
- 588
- 589
- 590
- 591
- 592
- 593
- 594
- 595
- 596
- 597
- 598
- 599
- 600
- 601
- 602
- 603
- 604
- 605
- 606
- 607
- 608
- 609
- 610
- 611
- 612
- 613
- 614
- 615
- 616
- 617
- 618
- 619
- 620
- 621
- 622
- 623
- 624
- 625
- 626
- 627
- 628
- 629
- 630
- 631
- 632
- 633
- 634
- 635
- 636
- 637
- 638
- 639
- 640
- 641
- 642
- 643
- 644
- 645
- 646
- 647
- 648
- 649
- 650
- 651
- 652
- 653
- 654
- 655
- 656
- 657
- 658
- 659
- 660
- 661
- 662
- 663
- 664
- 665
- 666
- 667
- 668
- 669
- 670
- 671
- 672
- 673
- 674
- 675
- 676
- 677
- 678
- 679
- 680
- 681
- 682
- 683
- 684
- 685
- 686
- 687
- 688
- 689
- 690
- 691
- 692
- 693
- 694
- 695
- 696
- 697
- 698
- 699
- 700
- 701
- 702
- 703
- 704
- 705
- 706
- 707
- 708
- 709
- 710
- 711
- 712
- 713
- 714
- 715
- 716
- 717
- 718
- 719
- 720
- 721
- 722
- 723
- 724
- 725
- 726
- 727
- 728
- 729
- 730
- 731
- 732
- 733
- 734
- 735
- 736
- 737
- 738
- 739
- 740
- 741
- 742
- 743
- 744
- 745
- 746
- 747
- 748
- 749
- 750
- 751
- 752
- 753
- 754
import { Container, Bounds } from '@pixi/display';
import { DRAW_MODES } from '@pixi/constants';
import { Texture, Renderer } from '@pixi/core';
import { TileRenderer } from './TileRenderer';
import { Matrix, Rectangle, groupD8 } from '@pixi/math';
import { settings } from './settings';
import { CanvasTileRenderer } from './CanvasTileRenderer';
import type { BaseTexture } from '@pixi/core';
import type { IDestroyOptions } from '@pixi/display';
import type { TilemapGeometry } from './TilemapShader';
enum POINT_STRUCT {
U,
V,
X,
Y,
TILE_WIDTH,
TILE_HEIGHT,
ROTATE,
ANIM_X,
ANIM_Y,
TEXTURE_INDEX,
ANIM_COUNT_X,
ANIM_COUNT_Y,
ANIM_DIVISOR,
ALPHA,
}
export const POINT_STRUCT_SIZE = (Object.keys(POINT_STRUCT).length / 2);
/**
* A rectangular tilemap implementation that renders a predefined set of tile textures.
*
* The {@link Tilemap.tileset tileset} of a tilemap defines the list of base-textures that can be painted in the
* tilemap. A texture is identified using its base-texture's index into the this list, i.e. changing the base-texture
* at a given index in the tileset modifies the paint of all tiles pointing to that index.
*
* The size of the tileset is limited by the texture units supported by the client device. The minimum supported
* value is 8, as defined by the WebGL 1 specification. `gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS`) can be used
* to extract this limit. {@link CompositeTilemap} can be used to get around this limit by layering multiple tilemap
* instances.
*
* @example
* import { Tilemap } from '@pixi/tilemap';
* import { Loader } from '@pixi/loaders';
*
* // Add the spritesheet into your loader!
* Loader.shared.add('atlas', 'assets/atlas.json');
*
* // Make the tilemap once the tileset assets are available.
* Loader.shared.load(function onTilesetLoaded()
* {
* // The base-texture is shared between all the tile textures.
* const tilemap = new Tilemap([Texture.from('grass.png').baseTexture])
* .tile('grass.png', 0, 0)
* .tile('grass.png', 100, 100)
* .tile('brick_wall.png', 0, 100);
* });
*/
export class Tilemap extends Container
{
shadowColor = new Float32Array([0.0, 0.0, 0.0, 0.5]);
_globalMat: Matrix = null;
/**
* The tile animation frame.
*
* @see CompositeTilemap.tileAnim
*/
public tileAnim: [number, number] = null;
/**
* This is the last uploaded size of the tilemap geometry.
* @ignore
*/
modificationMarker = 0;
/** @ignore */
offsetX = 0;
/** @ignore */
offsetY = 0;
/** @ignore */
compositeParent = false;
/**
* The list of base-textures being used in the tilemap.
*
* This should not be shuffled after tiles have been added into this tilemap. Usually, only tile textures
* should be added after tiles have been added into the map.
*/
protected tileset: Array<BaseTexture>;
/**
* The local bounds of the tilemap itself. This does not include DisplayObject children.
*/
protected readonly tilemapBounds = new Bounds();
/** Flags whether any animated tile was added. */
protected hasAnimatedTile = false;
/** The interleaved geometry of the tilemap. */
private pointsBuf: Array<number> = [];
/**
* @param tileset - The tileset to use for the tilemap. This can be reset later with {@link Tilemap.setTileset}. The
* base-textures in this array must not be duplicated.
*/
constructor(tileset: BaseTexture | Array<BaseTexture>)
{
super();
this.setTileset(tileset);
}
/**
* @returns The tileset of this tilemap.
*/
getTileset(): Array<BaseTexture>
{
return this.tileset;
}
/**
* Define the tileset used by the tilemap.
*
* @param tileset - The list of textures to use in the tilemap. If a base-texture (not array) is passed, it will
* be wrapped into an array. This should not contain any duplicates.
*/
setTileset(tileset: BaseTexture | Array<BaseTexture> = []): this
{
if (!Array.isArray(tileset))
{
tileset = [tileset];
}
for (let i = 0; i < tileset.length; i++)
{
if ((tileset[i] as unknown as Texture).baseTexture)
{
tileset[i] = (tileset[i] as unknown as Texture).baseTexture;
}
}
this.tileset = tileset;
return this;
}
/** Clears all the tiles added into this tilemap. */
clear(): this
{
this.pointsBuf.length = 0;
this.modificationMarker = 0;
this.tilemapBounds.clear();
this.hasAnimatedTile = false;
return this;
}
/**
* Adds a tile that paints the given texture at (x, y).
*
* @param tileTexture - The tiling texture to render.
* @param x - The local x-coordinate of the tile's position.
* @param y - The local y-coordinate of the tile's position.
* @param options - Additional tile options.
* @param [options.u=texture.frame.x] - The x-coordinate of the texture in its base-texture's space.
* @param [options.v=texture.frame.y] - The y-coordinate of the texture in its base-texture's space.
* @param [options.tileWidth=texture.orig.width] - The local width of the tile.
* @param [options.tileHeight=texture.orig.height] - The local height of the tile.
* @param [options.animX=0] - For animated tiles, this is the "offset" along the x-axis for adjacent
* animation frame textures in the base-texture.
* @param [options.animY=0] - For animated tiles, this is the "offset" along the y-axis for adjacent
* animation frames textures in the base-texture.
* @param [options.rotate=0]
* @param [options.animCountX=1024] - For animated tiles, this is the number of animation frame textures
* per row.
* @param [options.animCountY=1024] - For animated tiles, this is the number of animation frame textures
* per column.
* @param [options.animDivisor=1] - For animated tiles, this is the animation duration of each frame
* @param [options.alpha=1] - Tile alpha
* @return This tilemap, good for chaining.
*/
tile(
tileTexture: number | string | Texture | BaseTexture,
x: number,
y: number,
options: {
u?: number,
v?: number,
tileWidth?: number,
tileHeight?: number,
animX?: number,
animY?: number,
rotate?: number,
animCountX?: number,
animCountY?: number,
animDivisor?: number,
alpha?: number,
} = {}
): this
{
let baseTexture: BaseTexture;
let textureIndex = -1;
if (typeof tileTexture === 'number')
{
textureIndex = tileTexture;
baseTexture = this.tileset[textureIndex];
}
else
{
let texture: Texture | BaseTexture;
if (typeof tileTexture === 'string')
{
texture = Texture.from(tileTexture);
}
else
{
texture = tileTexture;
}
const textureList = this.tileset;
for (let i = 0; i < textureList.length; i++)
{
if (textureList[i] === texture.castToBaseTexture())
{
textureIndex = i;
break;
}
}
if ('baseTexture' in texture)
{
options.u = options.u ?? texture.frame.x;
options.v = options.v ?? texture.frame.y;
options.tileWidth = options.tileWidth ?? texture.orig.width;
options.tileHeight = options.tileHeight ?? texture.orig.height;
}
baseTexture = texture.castToBaseTexture();
}
if (!baseTexture || textureIndex < 0)
{
console.error('The tile texture was not found in the tilemap tileset.');
return this;
}
const {
u = 0,
v = 0,
tileWidth = baseTexture.realWidth,
tileHeight = baseTexture.realHeight,
animX = 0,
animY = 0,
rotate = 0,
animCountX = 1024,
animCountY = 1024,
animDivisor = 1,
alpha = 1,
} = options;
const pb = this.pointsBuf;
this.hasAnimatedTile = this.hasAnimatedTile || animX > 0 || animY > 0;
pb.push(u);
pb.push(v);
pb.push(x);
pb.push(y);
pb.push(tileWidth);
pb.push(tileHeight);
pb.push(rotate);
pb.push(animX | 0);
pb.push(animY | 0);
pb.push(textureIndex);
pb.push(animCountX);
pb.push(animCountY);
pb.push(animDivisor);
pb.push(alpha);
this.tilemapBounds.addFramePad(x, y, x + tileWidth, y + tileHeight, 0, 0);
return this;
}
/** Changes the rotation of the last tile. */
tileRotate(rotate: number): void
{
const pb = this.pointsBuf;
pb[pb.length - (POINT_STRUCT_SIZE - POINT_STRUCT.TEXTURE_INDEX)] = rotate;
}
/** Changes the `animX`, `animCountX` of the last tile. */
tileAnimX(offset: number, count: number): void
{
const pb = this.pointsBuf;
pb[pb.length - (POINT_STRUCT_SIZE - POINT_STRUCT.ANIM_X)] = offset;
pb[pb.length - (POINT_STRUCT_SIZE - POINT_STRUCT.ANIM_COUNT_X)] = count;
// pb[pb.length - (POINT_STRUCT_SIZE - POINT_STRUCT.ANIM_DIVISOR)] = duration;
}
/** Changes the `animY`, `animCountY` of the last tile. */
tileAnimY(offset: number, count: number): void
{
const pb = this.pointsBuf;
pb[pb.length - (POINT_STRUCT_SIZE - POINT_STRUCT.ANIM_Y)] = offset;
pb[pb.length - (POINT_STRUCT_SIZE - POINT_STRUCT.ANIM_COUNT_Y)] = count;
}
/** Changes the `animDivisor` value of the last tile. */
tileAnimDivisor(divisor: number): void
{
const pb = this.pointsBuf;
pb[pb.length - (POINT_STRUCT_SIZE - POINT_STRUCT.ANIM_DIVISOR)] = divisor;
}
tileAlpha(alpha: number): void
{
const pb = this.pointsBuf;
pb[pb.length - (POINT_STRUCT_SIZE - POINT_STRUCT.ALPHA)] = alpha;
}
renderCanvas = (renderer: any): void =>
{
const plugin = CanvasTileRenderer.getInstance(renderer);
if (plugin && !plugin.dontUseTransform)
{
const wt = this.worldTransform;
renderer.context.setTransform(
wt.a,
wt.b,
wt.c,
wt.d,
wt.tx * renderer.resolution,
wt.ty * renderer.resolution
);
}
this.renderCanvasCore(renderer);
}
renderCanvasCore(renderer: any): void
{
if (this.tileset.length === 0) return;
const points = this.pointsBuf;
const tileAnim = this.tileAnim || (renderer.plugins.tilemap && renderer.plugins.tilemap.tileAnim);
renderer.context.fillStyle = '#000000';
for (let i = 0, n = points.length; i < n; i += POINT_STRUCT_SIZE)
{
let x1 = points[i + POINT_STRUCT.U];
let y1 = points[i + POINT_STRUCT.V];
const x2 = points[i + POINT_STRUCT.X];
const y2 = points[i + POINT_STRUCT.Y];
const w = points[i + POINT_STRUCT.TILE_WIDTH];
const h = points[i + POINT_STRUCT.TILE_HEIGHT];
x1 += points[i + POINT_STRUCT.ANIM_X] * tileAnim[0];
y1 += points[i + POINT_STRUCT.ANIM_Y] * tileAnim[1];
const textureIndex = points[i + POINT_STRUCT.TEXTURE_INDEX];
const alpha = points[i + POINT_STRUCT.ALPHA];
// canvas does not work with rotate yet
if (textureIndex >= 0 && this.tileset[textureIndex])
{
renderer.context.globalAlpha = alpha;
renderer.context.drawImage(
(this.tileset[textureIndex] as any).getDrawableSource(),
x1, y1, w, h, x2, y2, w, h
);
}
else
{
renderer.context.globalAlpha = 0.5;
renderer.context.fillRect(x2, y2, w, h);
}
renderer.context.globalAlpha = 1;
}
}
private vbId = 0;
private vb: TilemapGeometry = null;
private vbBuffer: ArrayBuffer = null;
private vbArray: Float32Array = null;
private vbInts: Uint32Array = null;
private destroyVb(): void
{
if (this.vb)
{
this.vb.destroy();
this.vb = null;
}
}
render(renderer: Renderer): void
{
const plugin = (renderer.plugins as any).tilemap;
const shader = plugin.getShader();
renderer.batch.setObjectRenderer(plugin);
this._globalMat = shader.uniforms.projTransMatrix;
renderer
.globalUniforms
.uniforms
.projectionMatrix
.copyTo(this._globalMat)
.append(this.worldTransform);
shader.uniforms.shadowColor = this.shadowColor;
shader.uniforms.animationFrame = this.tileAnim || plugin.tileAnim;
this.renderWebGLCore(renderer, plugin);
}
renderWebGLCore(renderer: Renderer, plugin: TileRenderer): void
{
const points = this.pointsBuf;
if (points.length === 0) return;
const rectsCount = points.length / POINT_STRUCT_SIZE;
const shader = plugin.getShader();
const textures = this.tileset;
if (textures.length === 0) return;
plugin.bindTileTextures(renderer, textures);
renderer.shader.bind(shader, false);
// lost context! recover!
let vb = this.vb;
if (!vb)
{
vb = plugin.createVb();
this.vb = vb;
this.vbId = (vb as any).id;
this.vbBuffer = null;
this.modificationMarker = 0;
}
plugin.checkIndexBuffer(rectsCount, vb);
const boundCountPerBuffer = settings.TEXTILE_UNITS;
const vertexBuf = vb.getBuffer('aVertexPosition');
// if layer was changed, re-upload vertices
const vertices = rectsCount * vb.vertPerQuad;
if (vertices === 0) return;
if (this.modificationMarker !== vertices)
{
this.modificationMarker = vertices;
const vs = vb.stride * vertices;
if (!this.vbBuffer || this.vbBuffer.byteLength < vs)
{
// !@#$ happens, need resize
let bk = vb.stride;
while (bk < vs)
{
bk *= 2;
}
this.vbBuffer = new ArrayBuffer(bk);
this.vbArray = new Float32Array(this.vbBuffer);
this.vbInts = new Uint32Array(this.vbBuffer);
vertexBuf.update(this.vbBuffer);
}
const arr = this.vbArray;
// const ints = this.vbInts;
// upload vertices!
let sz = 0;
// let tint = 0xffffffff;
let textureId = 0;
let shiftU: number = this.offsetX;
let shiftV: number = this.offsetY;
// let tint = 0xffffffff;
// const tint = -1;
for (let i = 0; i < points.length; i += POINT_STRUCT_SIZE)
{
const eps = 0.5;
if (this.compositeParent)
{
const textureIndex = points[i + POINT_STRUCT.TEXTURE_INDEX];
if (boundCountPerBuffer > 1)
{
// TODO: what if its more than 4?
textureId = (textureIndex >> 2);
shiftU = this.offsetX * (textureIndex & 1);
shiftV = this.offsetY * ((textureIndex >> 1) & 1);
}
else
{
textureId = textureIndex;
shiftU = 0;
shiftV = 0;
}
}
const x = points[i + POINT_STRUCT.X];
const y = points[i + POINT_STRUCT.Y];
const w = points[i + POINT_STRUCT.TILE_WIDTH];
const h = points[i + POINT_STRUCT.TILE_HEIGHT];
const u = points[i + POINT_STRUCT.U] + shiftU;
const v = points[i + POINT_STRUCT.V] + shiftV;
let rotate = points[i + POINT_STRUCT.ROTATE];
const animX = points[i + POINT_STRUCT.ANIM_X];
const animY = points[i + POINT_STRUCT.ANIM_Y];
const animWidth = points[i + POINT_STRUCT.ANIM_COUNT_X] || 1024;
const animHeight = points[i + POINT_STRUCT.ANIM_COUNT_Y] || 1024;
const animXEncoded = animX + (animWidth * 2048);
const animYEncoded = animY + (animHeight * 2048);
const animDivisor = points[i + POINT_STRUCT.ANIM_DIVISOR];
const alpha = points[i + POINT_STRUCT.ALPHA];
let u0: number;
let v0: number; let u1: number;
let v1: number; let u2: number;
let v2: number; let u3: number;
let v3: number;
if (rotate === 0)
{
u0 = u;
v0 = v;
u1 = u + w;
v1 = v;
u2 = u + w;
v2 = v + h;
u3 = u;
v3 = v + h;
}
else
{
let w2 = w / 2;
let h2 = h / 2;
if (rotate % 4 !== 0)
{
w2 = h / 2;
h2 = w / 2;
}
const cX = u + w2;
const cY = v + h2;
rotate = groupD8.add(rotate, groupD8.NW);
u0 = cX + (w2 * groupD8.uX(rotate));
v0 = cY + (h2 * groupD8.uY(rotate));
rotate = groupD8.add(rotate, 2); // rotate 90 degrees clockwise
u1 = cX + (w2 * groupD8.uX(rotate));
v1 = cY + (h2 * groupD8.uY(rotate));
rotate = groupD8.add(rotate, 2);
u2 = cX + (w2 * groupD8.uX(rotate));
v2 = cY + (h2 * groupD8.uY(rotate));
rotate = groupD8.add(rotate, 2);
u3 = cX + (w2 * groupD8.uX(rotate));
v3 = cY + (h2 * groupD8.uY(rotate));
}
arr[sz++] = x;
arr[sz++] = y;
arr[sz++] = u0;
arr[sz++] = v0;
arr[sz++] = u + eps;
arr[sz++] = v + eps;
arr[sz++] = u + w - eps;
arr[sz++] = v + h - eps;
arr[sz++] = animXEncoded;
arr[sz++] = animYEncoded;
arr[sz++] = textureId;
arr[sz++] = animDivisor;
arr[sz++] = alpha;
arr[sz++] = x + w;
arr[sz++] = y;
arr[sz++] = u1;
arr[sz++] = v1;
arr[sz++] = u + eps;
arr[sz++] = v + eps;
arr[sz++] = u + w - eps;
arr[sz++] = v + h - eps;
arr[sz++] = animXEncoded;
arr[sz++] = animYEncoded;
arr[sz++] = textureId;
arr[sz++] = animDivisor;
arr[sz++] = alpha;
arr[sz++] = x + w;
arr[sz++] = y + h;
arr[sz++] = u2;
arr[sz++] = v2;
arr[sz++] = u + eps;
arr[sz++] = v + eps;
arr[sz++] = u + w - eps;
arr[sz++] = v + h - eps;
arr[sz++] = animXEncoded;
arr[sz++] = animYEncoded;
arr[sz++] = textureId;
arr[sz++] = animDivisor;
arr[sz++] = alpha;
arr[sz++] = x;
arr[sz++] = y + h;
arr[sz++] = u3;
arr[sz++] = v3;
arr[sz++] = u + eps;
arr[sz++] = v + eps;
arr[sz++] = u + w - eps;
arr[sz++] = v + h - eps;
arr[sz++] = animXEncoded;
arr[sz++] = animYEncoded;
arr[sz++] = textureId;
arr[sz++] = animDivisor;
arr[sz++] = alpha;
}
vertexBuf.update(arr);
}
(renderer.geometry as any).bind(vb, shader);
renderer.geometry.draw(DRAW_MODES.TRIANGLES, rectsCount * 6, 0);
}
/**
* @internal
* @ignore
*/
isModified(anim: boolean): boolean
{
if (this.modificationMarker !== this.pointsBuf.length
|| (anim && this.hasAnimatedTile))
{
return true;
}
return false;
}
/**
* This will pull forward the modification marker.
*
* @internal
* @ignore
*/
clearModify(): void
{
this.modificationMarker = this.pointsBuf.length;
}
/** @override */
protected _calculateBounds(): void
{
const { minX, minY, maxX, maxY } = this.tilemapBounds;
this._bounds.addFrame(this.transform, minX, minY, maxX, maxY);
}
/** @override */
public getLocalBounds(rect?: Rectangle): Rectangle
{
// we can do a fast local bounds if the sprite has no children!
if (this.children.length === 0)
{
return this.tilemapBounds.getRectangle(rect);
}
return super.getLocalBounds.call(this, rect);
}
/** @override */
destroy(options?: IDestroyOptions): void
{
super.destroy(options);
this.destroyVb();
}
/**
* Deprecated signature for {@link Tilemap.tile tile}.
*
* @deprecated Since @pixi/tilemap 3.
*/
addFrame(texture: Texture | string | number, x: number, y: number, animX: number, animY: number): boolean
{
this.tile(
texture,
x,
y,
{
animX,
animY,
}
);
return true;
}
/**
* Deprecated signature for {@link Tilemap.tile tile}.
*
* @deprecated Since @pixi/tilemap 3.
*/
// eslint-disable-next-line max-params
addRect(
textureIndex: number,
u: number,
v: number,
x: number,
y: number,
tileWidth: number,
tileHeight: number,
animX = 0,
animY = 0,
rotate = 0,
animCountX = 1024,
animCountY = 1024,
animDivisor = 1,
alpha = 1,
): this
{
return this.tile(
textureIndex,
x, y,
{
u, v, tileWidth, tileHeight, animX, animY, rotate, animCountX, animCountY, animDivisor, alpha
}
);
}
}