EmeraldZone Posted March 12, 2016 Share Posted March 12, 2016 I've been trying to whip up a little prototype today and when I built up my tilemap and added in the camera follow, I was getting weird behavior from the camera follow. The player speed would greatly increase that the camera can't keep up. When I hit the fire button all projectiles are originating from where the player is supposed to be. Have any of you encountered this before? //I am using the lockon method but I have also tried platformer and a default follow //I've called this in the create method, I've tried the update but the same behavior is happening this.game.camera.follow(this.player, Phaser.Camera.FOLLOW_LOCKON); playerMovement() { if (this.controls.left.isDown) { this.body.velocity.x = -this.attrs.moveSpeed;//200 } else if (this.controls.right.isDown) { this.body.velocity.x = this.attrs.moveSpeed;//200 } else { this.body.velocity.x = 0; } if (this.controls.jump.isDown) { this.jump(); } } Link to comment Share on other sites More sharing options...
Pryme8 Posted March 12, 2016 Share Posted March 12, 2016 have you tried var camera = new BABYLON.FollowCamera("FollowCam", new BABYLON.Vector3(0, 15, 45), scene); http://doc.babylonjs.com/tutorials/05._Cameras scroll down to the follow camera section, you can do a lot with this camera.... then take a look at how I set up the controls of the "actionCam" in this example and you can tailor it quite a bit with rotation accel and follow accel and stuff...https://github.com/Pryme8/Magic_Marble/blob/gh-pages/editor.html if your targets upVector changes though make sure you make an invisible target that keeps an upVector aligned to the world Y axis and is set to update to your real targets position so that way the camera does not go all floppy Link to comment Share on other sites More sharing options...
EmeraldZone Posted March 12, 2016 Author Share Posted March 12, 2016 Does this work with Phaser or have I entered this in the wrong forum? Link to comment Share on other sites More sharing options...
Pryme8 Posted March 12, 2016 Share Posted March 12, 2016 wooo My bad! I miss read the forum head, I thought it said Babylon initially. Link to comment Share on other sites More sharing options...
drhayes Posted March 14, 2016 Share Posted March 14, 2016 Where are you calling playerMovement()? Is it in your state's update method, or somewhere else? Link to comment Share on other sites More sharing options...
EmeraldZone Posted March 14, 2016 Author Share Posted March 14, 2016 @drhayes It's called in the 'play' states update, It was in the sprites update method before that but I was still experiencing the same behavior. I should note that the Player object is extending Phaser.Sprite Link to comment Share on other sites More sharing options...
drhayes Posted March 14, 2016 Share Posted March 14, 2016 I have this funny feeling that it's something to do with high-velocity and the camera updating its position in preUpdate, but I'm not sure. But that velocity doesn't look especially big. Maybe it's that the body isn't aligned with the texture somehow? Can you put a "game.debug.body" call in your update too? Link to comment Share on other sites More sharing options...
EmeraldZone Posted March 14, 2016 Author Share Posted March 14, 2016 @drhayes I've added that in and the body is aligned with the sprite. Would it help If I linked to my repo? Link to comment Share on other sites More sharing options...
drhayes Posted March 15, 2016 Share Posted March 15, 2016 Sure, or a live example too, if that's okay. Either one works. Link to comment Share on other sites More sharing options...
drhayes Posted March 15, 2016 Share Posted March 15, 2016 Oh right! You're probably GCing. In Chrome, open the dev tools and check out the timeline panel. There's a checkbox for "Memory" and "JS Profile". Start recording, then run your game, then stop recording. It'll display a memory usage profile close to the top of the dev tools. If you see a sawtooth pattern like /|/|/| then you're GCing because of too many object allocations. The only way to fix that is not allocate objects, which AFAIK you'll just have to do manually. Link to comment Share on other sites More sharing options...
EmeraldZone Posted March 15, 2016 Author Share Posted March 15, 2016 @drhayes Thanks I'll try that when I get home. Link to comment Share on other sites More sharing options...
EmeraldZone Posted March 15, 2016 Author Share Posted March 15, 2016 @drhayes Is this the saw tooth pattern you were referring to? Link to comment Share on other sites More sharing options...
EmeraldZone Posted March 15, 2016 Author Share Posted March 15, 2016 @drhayes I've alleviated the issue by using game.add.existing(this.player) rather than game.stage.addChild(this.player) While it works, is this a valid solution? Link to comment Share on other sites More sharing options...
drhayes Posted March 15, 2016 Share Posted March 15, 2016 Sawtooth: yup! I'm working on clearing some of this up in my game too... although I've heard that you can add pressure to the GC by having dev tools open (frustrating!) so do a lot of testing. existing vs. addChild: ¯\_(ツ)_/¯ Well, that's not entirely true. addChild is a method that comes from PIXI. The corresponding Phaser method is "add" (no child). "game.add.existing", by default, adds to the Phaser World. "game.stage.addChild" is adding to the stage directly. I'd say: if it's working for your game and you understand the implications of adding directly to the stage vs. the world, go for it. Link to comment Share on other sites More sharing options...
EmeraldZone Posted March 15, 2016 Author Share Posted March 15, 2016 @drhayes thanks for all the help Link to comment Share on other sites More sharing options...
Recommended Posts