Jump to content

Error using render texture with existing p2 bodies


tidelake
 Share

Recommended Posts

HI, I am enthralled by the pixi render texture tutorial, but I'm getting an error from the update() function: 

Quote

Uncaught TypeError: Cannot read property 'renderXY' of undefined

I've changed the variable names, but I've triple checked that they are consistent.  Here's some of my create() code to give an idea what I'm doing. I was hoping to use the render-texture tutorial on top of my working code.  Is there a way to get the renderTexture working within an existing p2 game?  Thank you.

  //game.stage.backgroundColor = "#f2f2f2";
  game.world.setBounds(0, 0, 450, 800);
  game.physics.startSystem(Phaser.Physics.P2JS);

  // create two render textures..
  // these dynamic textures will be used to draw the scene into itself
	render_texture1 = game.add.renderTexture(450, 800, 'texture1');
	render_texture2 = game.add.renderTexture(450, 800, 'texture2');
	current_texture = render_texture;

  // create a new sprite that uses the render texture we created above
	output_sprite = game.add.sprite(225, 400, current_texture);

  // align the sprite
	output_sprite.anchor.x = 0.5;
	output_sprite.anchor.y = 0.5;

	stuff_container = game.add.group();
	stuff_container.x = 450/2;
	stuff_container.y = 800/2;

  // now create some items and randomly position them in the stuff container
	for (var i = 0; i < 4; i++) {
		var item = stuff_container.create(
      Math.random() * 400 - 200, Math.random() * 400 - 200,
        game.rnd.pick(game.cache.getKeys(Phaser.Cache.IMAGE))
    );
		item.anchor.setTo(0.5, 0.5);
	}

	// used for spinning!
	count = 0;

  //  Turn on impact events for the world,
  // without this we get no collision callbacks
  game.physics.p2.setImpactEvents(true);
  game.physics.p2.updateBoundsCollisionGroup();
  game.physics.p2.gravity.y = 0;
  game.physics.p2.restitution = 0.7;

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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