No more viewports?

In Ace I had a little script that would allow me to show pictures behind the map rather than in front. I did this by putting the pictures into a different viewport and modifying their z index.

I went to convert it today, only to find there's no update_pictures equivalent in Spriteset_Map, and there don't seem to be viewports either.

So does MV add containers to the scene in a certain order, then add objects (sprites) to those containers, and that's the order they're shown in, and you're stuck with that order? Which means I'll have to add another container for pictures prior to the map container, and put them in there when I want pictures behind the map?


edit: this is my Ace script - it's really, really simple. But doesn't look like converting to MV will be quite as easy as this.
Spoiler
Code:
class Game_Temp
  attr_accessor :pictures_in_back         # Show pictures behind tilemap
  def initialize
    ....
    @pictures_in_back = false
  end
end

class Sprite_Picture < Sprite
  def update_position
    self.x = @picture.x
    self.y = @picture.y
    self.z = $game_temp.pictures_in_back ? @picture.number - 100 : @picture.number
  end
end

class Spriteset_Map
  def update_pictures
    $game_map.screen.pictures.each do |pic|
      @picture_sprites[pic.number] ||= Sprite_Picture.new(
        $game_temp.pictures_in_back ? @viewport1 : @viewport2, pic)
      @picture_sprites[pic.number].update
    end
  end
end

edit2: what I'd really like to do is just temporarily move Spriteset_Base's _pictureContainer so that it's between Spriteset_Map's _parallax and _tilemap, and then later move it back to where it originally was - all within a single cutscene. Is there an easy way to do that?
I don't know if this is now included in the main version of PIXI yet, but you can use this official plugin for dealing with children zIndex.
https://github.com/pixijs/pixi-display

However, you can create your personal system, adding to the Sprite_Picture object a property like childOrder, and then in the method that creates the picture container, you can edit the addChild method to check the childOrder using a sorting method on the children property.
Something like:

Code:
// INSIDE THE METHOD THAT CREATES THE PICTURE CONTAINER
var sup = pictureContainer.addChild
pictureContainer.addChild = function(child) {
sup.call(this, child)
pictureContainer.children.sort(function(a, b) {
a.childOrder = a.childOrder || pictureContainer.children.indexOf(a)
b.childOrder = b.childOrder || pictureContainer.children.indexOf(b)
return b.childOrder - a.childOrder
})
}
The whole picture container is still above the map though, so even though I could rearrange them within the container, I still need a way to place them between the parallax and the map.

What I'm trying to do is, during one cutscene, show two pictures between the parallax and the map, and move them around a bit. No other pictures will be displayed at the same time, and there is no point in the game where I will want some pictures to show behind and some to show in front of the map.

I've just found the addChildAt command, so going to tinker with that a bit - it looks like it already handles removing from old parent if there is one.
The whole picture container is still above the map though, so even though I could rearrange them within the container, I still need a way to place them between the parallax and the map.

What I'm trying to do is, during one cutscene, show two pictures between the parallax and the map, and move them around a bit. No other pictures will be displayed at the same time, and there is no point in the game where I will want some pictures to show behind and some to show in front of the map.

I've just found the addChildAt command, so going to tinker with that a bit - it looks like it already handles removing from old parent if there is one.
you need asign .z varlur to sprite, container or pixi element for rmmv take the Z indexation.
bellowTitle z:-1
bellowEvents z:3
middleEvents z:4
upperEvents z:6


PHP:
Spriteset_Map.prototype.createLowerLayer = function() {
    Spriteset_Base.prototype.createLowerLayer.call(this);
    this.createParallax(); // Create parralaxe and add parralaxe layers
    this.createTilemap();
    this.createCharacters();
    this.createShadow();
    this.createDestination();
    this.createWeather();
    //plugin
    this.addRmmvLayers(); // add rmmv with z event layer
    this.addTopLayers();// add final top layer
};

// befor Create parralaxe and add parralaxe layers
Spriteset_Map.prototype.createParallax = function() {
    this._parallax = new TilingSprite();
    this._parallax.move(0, 0, Graphics.width, Graphics.height);
    this._baseSprite.addChild(this._parallax);
    //plugin
    for(var i = 0,len = pixiSSA._layers.data_parralaxeLayer.length ; i <len; i++){
        this._baseSprite.addChild(pixiSSA._layers.data_parralaxeLayer[i]);
    };
};

// add rmmv with z event layer
Spriteset_Map.prototype.addRmmvLayers = function() { // procced to add other layers with Z to _tilemap and TOP
    for(var i = 0,len = pixiSSA._layers.data_bellowTitle.length ; i <len; i++){// TODO: INUTILE DANS MON CONTEXT DE JEUX
        this._tilemap.addChild(pixiSSA._layers.data_bellowTitle[i]);
    };
    for(var i = 0,len = pixiSSA._layers.data_belowEventsLayer.length ; i <len; i++){
        this._tilemap.addChild(pixiSSA._layers.data_belowEventsLayer[i]);
    };
    for(var i = 0,len = pixiSSA._layers.data_middleEventsLayer.length ; i <len; i++){
        this._tilemap.addChild(pixiSSA._layers.data_middleEventsLayer[i]);
    };
    for(var i = 0,len = pixiSSA._layers.data_upperEventsLayer.length ; i <len; i++){
        this._tilemap.addChild(pixiSSA._layers.data_upperEventsLayer[i]);
    };
};

// add final top layer
Spriteset_Map.prototype.addTopLayers = function() { // procced to add other layers with Z to _tilemap and TOP
    for(var i = 0,len = pixiSSA._layers.data_topLayers.length ; i <len; i++){
        this._tilemap.addChild(pixiSSA._layers.data_topLayers[i]);
    };
};
example with container with .z rmmv valur


You need to take a look in your project folder libs pixi-tilemap.js and in the rpg_core.js

PHP:
Tilemap.prototype._createLayers = function() {
    var width = this._width;
    var height = this._height;
    var margin = this._margin;
    var tileCols = Math.ceil(width / this._tileWidth) + 1;
    var tileRows = Math.ceil(height / this._tileHeight) + 1;
    var layerWidth = tileCols * this._tileWidth;
    var layerHeight = tileRows * this._tileHeight;
    this._lowerBitmap = new Bitmap(layerWidth, layerHeight);
    this._upperBitmap = new Bitmap(layerWidth, layerHeight);
    this._layerWidth = layerWidth;
    this._layerHeight = layerHeight;

    /*
     * Z coordinate:
     *
     * 0 : Lower tiles
     * 1 : Lower characters
     * 3 : Normal characters
     * 4 : Upper tiles
     * 5 : Upper characters
     * 6 : Airship shadow
     * 7 : Balloon
     * 8 : Animation
     * 9 : Destination
     */

    this._lowerLayer = new Sprite();
    this._lowerLayer.move(-margin, -margin, width, height);
    this._lowerLayer.z = 0;

    this._upperLayer = new Sprite();
    this._upperLayer.move(-margin, -margin, width, height);
    this._upperLayer.z = 4;

    for (var i = 0; i < 4; i++) {
        this._lowerLayer.addChild(new Sprite(this._lowerBitmap));
        this._upperLayer.addChild(new Sprite(this._upperBitmap));
    }

    this.addChild(this._lowerLayer);
    this.addChild(this._upperLayer);
};

My solution to just move the pictures to a different container worked. It's a bit ugly, but I'm only using it for one single cutscene throughout the entire game. If I were doing it more often, or wanted some pictures above the map and some below, I'd go to the trouble of writing a plugin, but I didn't want the overhead just for this one event.

So to move the pictures from above the map to between the map and the parallax:
Code:
SceneManager._scene._spriteset._baseSprite.addChildAt(SceneManager._scene._spriteset._pictureContainer, 2)

and to move it back again:
Code:
SceneManager._scene._spriteset.addChildAt(SceneManager._scene._spriteset._pictureContainer, 2)

When I get to adding fog, I may need to change that, as the fog will be added around the same layer as the weather (though I also have the option of USING the weather layer for the fog, which sounds logical).
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/no-more-viewports.90906/