Skip to content

Commit

Permalink
fix tiled bug for GPU Mode (#9456)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinYunMo committed Oct 11, 2021
1 parent 8d916b9 commit f54c8f5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
25 changes: 20 additions & 5 deletions cocos/2d/components/sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @module ui
*/

import { ccclass, help, executionOrder, menu, tooltip, displayOrder, type, range, editable, serializable } from 'cc.decorator';
import { ccclass, help, executionOrder, menu, tooltip, displayOrder, type, range, editable, serializable, override, displayName } from 'cc.decorator';
import { EDITOR, UI_GPU_DRIVEN } from 'internal:constants';
import { SpriteAtlas } from '../assets/sprite-atlas';
import { SpriteFrame } from '../assets/sprite-frame';
Expand Down Expand Up @@ -179,6 +179,25 @@ enum EventType {
@executionOrder(110)
@menu('2D/Sprite')
export class Sprite extends Renderable2D {
/**
* @en The customMaterial
* @zh 用户自定材质
*/
@type(Material)
@displayOrder(0)
@displayName('CustomMaterial')
@override
get customMaterial () {
return this._customMaterial;
}

set customMaterial (val) {
this._customMaterial = val;
this.updateMaterial();
if (UI_GPU_DRIVEN && !val) {
this._canDrawByFourVertex = true;
}
}
/**
* @en
* The sprite atlas where the sprite is.
Expand Down Expand Up @@ -570,10 +589,6 @@ export class Sprite extends Renderable2D {
}

protected _updateBuiltinMaterial () {
// macro.UI_GPU_DRIVEN
if (UI_GPU_DRIVEN) {
this._canDrawByFourVertex = true;
}
let mat = super._updateBuiltinMaterial();
if (this.spriteFrame && this.spriteFrame.texture instanceof RenderTexture) {
const defines = { SAMPLE_FROM_RT: true, ...mat.passes[0].defines };
Expand Down
9 changes: 9 additions & 0 deletions cocos/tiledmap/tiled-object-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/

import { ccclass, help, type, requireComponent } from 'cc.decorator';
import { UI_GPU_DRIVEN } from 'internal:constants';
import { Component } from '../core/components';
import { Sprite } from '../2d/components/sprite';
import { Label } from '../2d/components/label';
Expand Down Expand Up @@ -274,6 +275,10 @@ export class TiledObjectGroup extends Component {
label.horizontalAlign = object.halign;
label.verticalAlign = object.valign;
label.fontSize = object.pixelsize;
if (UI_GPU_DRIVEN) {
// @ts-expect-error HACK for Tiled
label._canDrawByFourVertex = false;
}

textTransComp.setContentSize(object.width, object.height);
} else if (objType === TMXObjectType.IMAGE) {
Expand Down Expand Up @@ -365,6 +370,10 @@ export class TiledObjectGroup extends Component {
spf.rotated = grid._rotated!;
spf.rect = grid._rect!;
sprite.spriteFrame = spf;
if (UI_GPU_DRIVEN) {
// @ts-expect-error HACK for Tiled
sprite._canDrawByFourVertex = false;
}

imgTrans.setContentSize(object.width, object.height);

Expand Down

0 comments on commit f54c8f5

Please sign in to comment.