Sign in to follow this  
Followers 0
01271

Swapping and managing containers

3 posts in this topic

side note: sorry for making so many threads ( 3 in ~2 months ) but I have different issues and I think threads should be problem-centric rather than project-centric.

So I wanted to know how to swap containers.

Here's one of my containers.

/**
 * a HUD container and child items
 */

game.inventoryContainer = game.inventoryContainer || {};
game.containers = game.containers || {};

game.containers.inventory = me.Container.extend({

	init: function() {
		// call the constructor
		this._super(me.Container, 'init');
		// persistent across level change
		this.isPersistent = true;
		// make sure we use screen coordinates
		this.floating = false;
		this.alwaysUpdate = false;
		this.visible = false;
		// give a name
		this.name = "inventoryContainer";

		me.levelDirector.loadLevel("collision");
		this.addChild(new me.ColorLayer("invbg", "#55233B"), 0);
		this.addChild(new game.invLayer1, 1);
		this.addChild(new game.ManagerEntity(0, 0), 2);
		game.pointers.containers.inventory = this;
	},
	update: function(dt) {
		if (game.screenspace === this.name) {
			return this._super(me.Container, 'update', [dt]);
		}
		return false;
	},

	draw: function(renderer, rect) {
		if (game.screenspace === this.name) {
			return this._super(me.Container, 'draw', [renderer, rect]);
		}
		return false;
	},
	reactivate: function() {
		this.isRenderable = true;
	},
	deactivate: function() {
		// this.isRenderable = false;
		// for (var i = this.children.length - 1; i >= 0; i--) {
		// this.children[i].pos.x +=1000;
		// }
		// me.game.world.removeChild(this);
	}

});

It's added to the game via

this.inventoryContainer = new game.containers.inventory();
        me.game.world.addChild(this.inventoryContainer);

How do I swap it out without losing its children? All I want is not to have it or its children use up processor cycles while another container is displayed.

This I think would be interesting to other developers too.

Share this post


Link to post
Share on other sites

Ah, just responded to your PM. Yeah you should be able to simply do: me.game.world.removeChild(this.inventoryContainer); That will keep the container itself intact, but just detached from the game world.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.