Hi,
I've been stuck on the following problem for days. I am less asking about how to solve this, as I am asking if my strategy is correct or if anyone might have other approaches. But of course, any help at all appreciated.
I have a game in which…
- The camera/viewport (C) follows the player's x position.
- When the player reaches the left or right of a room, they wrap to the other side, creating the effect of a circular room. (From A to B and B to A)
- The viewport is not as wide as the entire room.
This works fine, but the challenge is in E and F above: showing the room in front of you, which is really the room on the opposite side.
My attempts at cracking this in ct.js have been rough.
My current strategy has been to leverage PIXI as much as possible…
- Create two "placeholder" rectangular sprites at either end, representing the player's "forward" view.
- At each draw cycle, if the player is within a certain range of one end or the other, I capture ct.room as a texture, and then assign that texture to the placeholder sprite.
This works on the left side (!!) but for the life of me I can't get it working on the right, where the content is always in the wrong position or not visible at all.
My code, mostly for illustrative purposes of the strategy I'm trying:
let fillLeft = ct.types.list['LeftRightFill'][0];
let fillRight = ct.types.list['LeftRightFill'][1];
let renderer = ct.pixiApp.renderer;
let texture = PIXI.RenderTexture.create(4880, 640);
let textureR = PIXI.RenderTexture.create(4280, 640);
if (this.activePlayer.x <= 600 && this.activePlayer.x >= 0) {
renderer.render(ct.room, texture);
fillLeft.texture = texture;
fillLeft.x = -3680 - 600 + ct.camera.x;
fillLeft.visible = true;
fillRight.visible = false;
} else if (this.activePlayer.x > 3080 && this.activePlayer.x <= 3680) {
renderer.render(ct.room, textureR);
fillRight.texture = textureR;
fillRight.x = ct.camera.right - 600;
fillRight.visible = true;
fillLeft.visible = false;
} else {
fillLeft.visible = false;
fillRight.visible = false;
}
Also, I am trying to ensure the solution is performant. This could become very processor intensive.