Jump to content

Is this legal? game.load.image(...)


ptdnet
 Share

Recommended Posts

So let's say I do something like ...

game.load.image("dude", "/some/image/here.png");// do a bunch of stuff...game.load.image("dude", "/other/image/here.png");

What happens to the first image I loaded? Is it leaked? Destroyed properly? I tried looking in the Phaser code but can't tell exactly.

Link to comment
Share on other sites

Depends when you load it.

 

If you do this in the same preload block, then the 2nd call will be ignored unless you set the overwrite parameter to true:

game.load.image("dude", "blah.png", true);

If you do this some time later, i.e. in another State, then it will replace whatever was in the image cache matching that ID, but the original image object is left un-touched. Under Phaser 2.3 if this happens the original image is destroyed first and removed from the GPU.

Link to comment
Share on other sites

  • 3 months later...

Depends when you load it.

 

If you do this in the same preload block, then the 2nd call will be ignored unless you set the overwrite parameter to true:

game.load.image("dude", "blah.png", true);

If you do this some time later, i.e. in another State, then it will replace whatever was in the image cache matching that ID, but the original image object is left un-touched. Under Phaser 2.3 if this happens the original image is destroyed first and removed from the GPU.

One more question related to this issue...imagine that you have 2 states...

one of them has something like this:

 

Previous State (Preload state)

//this.listofimages is an array of locations of images//this.imagearray is an array that countains the numbers of the images that i must loadpreload: function(){  //loading of sound before  while(this.i<5)    	    {    		    this.load.image('lvl1'+ this.i, 'assets/images/biblioteca/'+this.listofimages.imagens[this.imagearray[this.i]].imagem+'.jpg', true);    		    console.log('assets/images/biblioteca/'+this.listofimages.imagens[this.imagearray[this.i]].imagem);    		    this.i++;                    	    }},update: function(){		if(this.cache.isSoundDecoded('fundosong') && this.ready == true) {      		this.state.start('Game', true, false, this.listofimages, this.imagearray);    	}}

Next State (Game state)

create: function(){     this.imagem = this.add.image(this.game.world.centerX, this.game.world.centerY-200, 'lvl1'+this.counter);    this.imagem.x = this.game.width/2 - 150;}

basicly the 2nd time the images won't change....even with overwrite?

If so how can i get arround this...and can i apply the same logic for sounds too?

 

Thank you for your time to answer this question.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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