Jump to content

Applying camera offset when rendering tilemap layers to textures ?


Refeuh
 Share

Recommended Posts

Hi all !

I am rendering tilemap layers to textures, but I have issues applying a "camera" offset to get the correct area of the layer to appear in the texture.

In this setup, the actual world/scene is only made of 1 single sprite covering the entire game window and displaying the content of the rendertexture. The game/world camera is static (0, 0). Only the content of the rendertexture is updated to reflect the player moving around. (The goal is to do some fancy post-processing using the rendertexture, including custom up-scaling)

My problem is that I can't seem to find the right combination of layer parameters to get a subset of the layer to render into the texture :-? I've created a minimal test scene that demonstrates the problem : http://phaser.io/sandbox/edit/weeeaLZy

function create() {
    
    // Create a render texture the size of the game window
    texture = game.make.renderTexture(game.width, game.height);
    // Adds a sprite using the render texture to the scene
    game.add.sprite(0, 0, texture);

    // Create the tilemap
    var map = game.add.tilemap('Map');
    map.addTilesetImage('CybernoidMap3BG_bank.png', 'Tiles');
    
    // A layer is added to a dummy group, not to be included in the default World
    // The layer is rendered onto the render texture manually in the update()
    group = game.make.group(null);
    layer = map.createLayer(0, game.width, game.height, group);
    
    // Custom arbitrary "camera" offset ; this would driven by gameplay logic (player position, etc.)
    var camX = 64;
    var camY = 64;
    
    // Attempt at getting the tilemap layer to render according to manual offset. These values seem ignored when rendering to texture :-?
    layer.fixedToCamera = true;
    layer.cameraOffset.x = -camX;
    layer.cameraOffset.y = -camY;
}

The only relevant topic/example I found is this demo : http://phaser.io/examples/v2/display/render-texture-tilemap , doing a manual layer render by processing all the tiles manually... Which I'd really like to avoid, because of massive drawcalls overhead.

I've tried lots of things, cropping, render offset, etc. so far nothing gave the expected result :-? Any help would be greatly appreciated !

Regards

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...