Jump to content

[PROBLEM] Generate Tile Sprite with different texture in same function when is called


sanlegas
 Share

Recommended Posts

Hi guys!, i am new by here, i have a couple of months works with phaser, i like it really !.
Well lets go with my problem, i am programming a endless runner game, i want generate builds with different texture, i am using tile sprite for generate those builds, that is in a function for generate the builds with a random texture, the problem is when the new tile sprite is created affect to the tile sprite that was created previus to the new doing the previus tile sprite show the new texture for a Milliseconds and after back to his correct previus texture, i dont know what happend, my code is the next

 

crea_edificio: function (x,width,height) {
		// body...
		console.log("creando edificio");
		//this.crea_fondo();
		var i_edificio =  Math.floor(Math.random() * 5);
		var textura = Holk.TEXTURES[i_edificio];

		var edificio = this.game.add.tileSprite(x, this.game.world.height - height,width * textura.width,height 
												,Object.keys(Holk.TEXTURES[i_edificio])[0]);

	    this.game.physics.enable(edificio, Phaser.Physics.ARCADE);
	    edificio.body.allowGravity = false;
	    edificio.body.immovable = true;
	    edificio.body.velocity.x = Holk.VELOCIDAD_SUELO ;

	    edificio.update = function(){
	    	//edificio.body.position.x = edificio.body.position.x - 2;
			//this.game.physics.arcade.collide(holk, edificio_grupo);

			if (this.body.position.x + this.body.width < 0) {
				this.destroy();
			}	    	

	    }
    
    	edificio_grupo.add(edificio);
    	
	}

this function is called every X seconds for other validation for generate a new build,

 

I hope you can help me, thanks !!.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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