Skip to content

Commit cda17d4

Browse files
Merge branch '10835-sdk-scaling-issue-with-bufferedgroup' into 'master'
[FIX][GAMEENGINE] BufferedGroup scaling down See merge request codingame/game-engine!288
2 parents e6f357a + 68b055b commit cda17d4

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

engine/modules/entities/src/main/resources/view/entity-module/BufferedGroup.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
import { getRenderer, flagForDestructionOnReinit } from '../core/rendering.js'
2-
import { WIDTH, HEIGHT } from '../core/constants.js'
32
import { ContainerBasedEntity } from './ContainerBasedEntity.js'
43

54
/* global PIXI */
65

76
export class BufferedGroup extends ContainerBasedEntity {
87
initDisplay () {
98
super.initDisplay()
10-
this.gameTexture = PIXI.RenderTexture.create(WIDTH, HEIGHT)
11-
flagForDestructionOnReinit(this.gameTexture)
12-
this.graphics = new PIXI.Sprite(this.gameTexture)
139
this.buffer = new PIXI.Container()
10+
this.gameTexture = null
11+
this.graphics = new PIXI.Sprite()
1412
this.needsRender = true
1513
}
1614

1715
postUpdate () {
1816
if (this.needsRender) {
17+
const bufferBoundsWidth = this.buffer.getBounds().width
18+
const bufferBoundsHeight = this.buffer.getBounds().height
19+
if (this.gameTexture == null || this.gameTexture.width < bufferBoundsWidth || this.gameTexture.height < bufferBoundsHeight) {
20+
const width = Math.min(Math.max(bufferBoundsWidth, 512), 4096)
21+
const height = Math.min(Math.max(bufferBoundsHeight, 512), 4096)
22+
this.gameTexture = PIXI.RenderTexture.create(width, height)
23+
flagForDestructionOnReinit(this.gameTexture)
24+
this.graphics.texture = this.gameTexture
25+
}
26+
1927
getRenderer().render(this.buffer, this.gameTexture)
2028
this.needsRender = false
2129
}

playground/misc/misc-3-release-notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The CodinGame SDK is regularly updated and improved. This document lets you know
77
### 🐞 Bug fix
88

99
- Fixed a bug in the TooltipModule causing tooltips to stay visible permanently.
10+
- BufferedGroup will now dynamically resize to fit contents.
1011

1112
## 3.15.5
1213

0 commit comments

Comments
 (0)