Skip to content

Commit 0beb6b4

Browse files
committed
Fix a regression on the displayed position of custom objects
1 parent c8d5f46 commit 0beb6b4

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

GDJS/Runtime/RuntimeCustomObjectLayer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ namespace gdjs {
2525

2626
// Let the renderer do its final set up:
2727
this._renderer.onCreated();
28-
this._renderer.updatePosition();
28+
// We don't call `this._renderer.updatePosition` because the camera has
29+
// no effect unless it's moved.
2930
}
3031

3132
override onGameResolutionResized(

GDJS/Runtime/RuntimeLayer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,18 @@ namespace gdjs {
281281
* @returns the scene the layer belongs to directly or indirectly
282282
*/
283283
getRuntimeScene(): gdjs.RuntimeScene {
284+
// TODO Check that method is not wrongly called instead of `getInstanceContainer`.
284285
return this._runtimeScene.getScene();
285286
}
286287

288+
/**
289+
* Returns the scene the layer directly belongs
290+
* @returns the scene the layer directly belongs
291+
*/
292+
getInstanceContainer(): gdjs.RuntimeInstanceContainer {
293+
return this._runtimeScene;
294+
}
295+
287296
/**
288297
* Called at each frame, after events are run and before rendering.
289298
*/

GDJS/Runtime/pixi-renderers/layer-pixi-renderer.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,8 @@ namespace gdjs {
829829
}
830830

831831
updatePosition(): void {
832-
const runtimeGame = this._layer.getRuntimeScene().getGame();
832+
const instanceContainer = this._layer.getInstanceContainer();
833+
const runtimeGame = instanceContainer.getGame();
833834

834835
// Update the 3D camera position and rotation.
835836
if (this._threeCamera) {
@@ -921,8 +922,10 @@ namespace gdjs {
921922
const centerY =
922923
this._layer.getCameraX() * effectivePixiZoom * angleSinValue +
923924
this._layer.getCameraY() * effectivePixiZoom * angleCosValue;
924-
this._pixiContainer.position.x = this._layer.getWidth() / 2 - centerX;
925-
this._pixiContainer.position.y = this._layer.getHeight() / 2 - centerY;
925+
this._pixiContainer.position.x =
926+
instanceContainer.getViewportOriginX() - centerX;
927+
this._pixiContainer.position.y =
928+
instanceContainer.getViewportOriginY() - centerY;
926929
}
927930

928931
// Pixel rounding for the Pixi rendering (be it for 2D only

0 commit comments

Comments
 (0)