KimKong Posted September 22, 2019 Share Posted September 22, 2019 Hi, When a camera Is added to a moving container, it does not update its position unless the target moves out of the sensor field. To me this looks like a bug. Is it possible to work around it? game.module( 'game.main' ) .body(function() { game.addAsset('sprite.png'); game.createScene('Main', { init: function() { this.container = new game.Container(); this.container.addTo(this.stage); var bg = new game.TilingSprite('sprite.png', game.width * 2, game.height * 2); bg.alpha = 0.2; bg.addTo(this.container); this.circleContainer = new game.Container(); this.circleContainer.addTo(this.container); this.sprite = new game.Graphics(); this.sprite.drawCircle(10, 10, 10); this.sprite.anchorCenter(); this.sprite.center(this.stage); this.sprite.addTo(this.circleContainer); this.camera = new game.Camera(this.sprite); this.camera.addTo(this.circleContainer); }, update: function() { var speed = 200; this.circleContainer.y -= 10 * game.delta; if (game.keyboard.down('LEFT')) this.sprite.x -= speed * game.delta; if (game.keyboard.down('RIGHT')) this.sprite.x += speed * game.delta; if (game.keyboard.down('UP')) this.sprite.y -= speed * game.delta; if (game.keyboard.down('DOWN')) this.sprite.y += speed * game.delta; } }); }); Quote Link to comment Share on other sites More sharing options...
khleug35 Posted September 28, 2019 Share Posted September 28, 2019 Is it bug???? I always use this method to make some sprite or shape fix into camera view. if I want to make some sprite to fix into camera view and don't want to put it in 'stage' I will create fixed_camera_container to make the sprite to fix into camera view. this.fixed_camera_container = new game.Container(); this.fixed_camera_container .addTo(this.stage); this.container = new game.Container(); this.container.addTo(this.stage); this.healthbar = new game.healthbarClass(); //Fixed to camera this.healthbar.sprite.addTo(this.fixed_camera_container); this.player = new game.playerClass(); this.player.sprite.addTo(this.container); this.camera = new game.Camera(this.player.sprite); this.camera.addTo(this.container); 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.