xompl Posted January 25, 2015 Share Posted January 25, 2015 Not sure if this is a bug or I'm doing something wrong. I've made an infinite vertical runner.I have a bunch of blocks on screen. When a block exists the screen at the top I move it to the bottom.Hence I only have around 50 sprites for the whole game. Physics: ArcadeVersion: 2.2.2 My problem is that when I die and restart the game, the bounding boxes of the blocks remain on screen for some reason. See the example:In the first image the player is at (x=325 y=1200). There are some sprite platforms with the bounding box rendered with debug.body(block) When the player dies I go back to y=0 (image 2) the bounding boxes of the platforms remain in the same position even if the sprites are outside the screen. This is the code that moves the blocks when they go out of the screenfor (var i = 0; i < this.blocks.length; ++i) { var row = this.blocks[i]; if (row[0].y + 128 < player.y) { // row is outside the screen var dif = this.blocks.length * 32; for (var j = 0; j < row.length; ++j) { row[j].body.y += dif; // Select if it will be visible or not row[j].visible = this.game.rnd.realInRange(0, 1) < 0.1; } }}Any idea?Thank you! Link to comment Share on other sites More sharing options...
spencerTL Posted January 25, 2015 Share Posted January 25, 2015 From reading some other threads if you want to move a body directly, rather than using velocity I think you need to use body.reset(x,y); or you get strange results. Try changing the line where you change the body's y to use this method. http://docs.phaser.io/Phaser.Physics.Arcade.Body.html#reset Link to comment Share on other sites More sharing options...
xompl Posted January 25, 2015 Author Share Posted January 25, 2015 Thank you for you reply spencerTL but I still see these bounding boxes. I tried using body.reset(x, y), sprite.y, sprite.position.y and sprite.body.y. All have the problem I explained in the first post. It make no sense that the boxes are moved to the origin (0, 0) when I move the camera and the sprite. Link to comment Share on other sites More sharing options...
Recommended Posts