ambidex Posted October 17, 2014 Share Posted October 17, 2014 I'm currently writing some horizontal scrolling game in which I have 3 layers (game.Container) and one of them contains the player and all the other objects which it encounters. I'm using game.Camera to follow the player around. This works wonderfully, though, the bodies of the player and collidable objects stay in place, since they aren't added to the container which the camera is moving. I can't seem to find out of I can add the bodies to the container so they get moved with the rest... Any suggestions? Thanks again all. Quote Link to comment Share on other sites More sharing options...
enpu Posted October 17, 2014 Share Posted October 17, 2014 Do you mean that bodies are not moving, when using debug draw? Quote Link to comment Share on other sites More sharing options...
ambidex Posted October 17, 2014 Author Share Posted October 17, 2014 Yeah, that's what I meant. You can see the sprites moving (as expected since they are in the camera's container) but the (?debugdraw) bodies are keeping static position. Quote Link to comment Share on other sites More sharing options...
enpu Posted October 19, 2014 Share Posted October 19, 2014 This is known issue, i will try to fix this asap. Quick fix would be to move game.debugDraw.bodyContainer, like this:game.debugDraw.bodyContainer.position.x = -this.camera.position.x;game.debugDraw.bodyContainer.position.y = -this.camera.position.y; Quote Link to comment Share on other sites More sharing options...
ambidex Posted October 20, 2014 Author Share Posted October 20, 2014 Oh so the bodies are actually being moved? I'd have to test this, I think I'm not making any kind of connection between the body and the actual sprite. I can't really be sure at this point since I'm not able to view my code at this time. Can I ask you how this relation would normally be made between a Sprite and a Body which represents it's collidable body? Thanks again! Quote Link to comment Share on other sites More sharing options...
ambidex Posted October 28, 2014 Author Share Posted October 28, 2014 Enpu, I've been testing this, the bodies do not seem to be moved when their sprites are being moved and therefor debugdraw shows the right position of the bodies. This is somewhat the result that I expected, since there is no way (as far as I know) to connect the two together? I would expect some functionality like: this.sprite.addTo(this.container);this.body.addTo(this.container); Or:this.sprite.addto(this.container);this.sprite.addChild(this.body);Though both do not work. Any idea how to keep the body's position up-to-date with that of the sprite? Quote Link to comment Share on other sites More sharing options...
enpu Posted October 28, 2014 Share Posted October 28, 2014 Look at Player class on Flying Dog:https://github.com/ekelokorpi/flyingdog/blob/master/src/game/objects.js Quote Link to comment Share on other sites More sharing options...
ambidex Posted October 28, 2014 Author Share Posted October 28, 2014 You're addressing the following?this.sprite.position.x = this.body.position.x;this.sprite.position.y = this.body.position.y;But consider the following scenario. Screen +-----------------+-----------------------------------------------------------+| Sprite A body | || X: 0 Y:0 | || Parent: World | |+-----------------+ || || || || || || || || || || Container A || X: 600 Y: 400 || +------------------+-------------+| | Sprite A | || | X: 0 Y: 0 | || | Parent: Cont. A | || +------------------+ || | || | || | || | || | || | || | || | || | |+--------------------------------------------+--------------------------------+Updating the body with the sprite's coords will result in a offset body (visa-versa will result the reversed result of course). I think a nice feature might be that you can also add the body to the container, which would update the body's coords too instead of creating a additional update function to update the bodies when moving the container around. What's your perspective on this? Quote Link to comment Share on other sites More sharing options...
Legomite Posted August 25, 2015 Share Posted August 25, 2015 This is known issue, i will try to fix this asap. Quick fix would be to move game.debugDraw.bodyContainer, like this:game.debugDraw.bodyContainer.position.x = -this.camera.position.x;game.debugDraw.bodyContainer.position.y = -this.camera.position.y;Is this fixed yet? I have the same problem Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.