Jump to content

Camera does not move properly with container


KimKong
 Share

Recommended Posts

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;
    }
});

});

 

Link to comment
Share on other sites

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);

 

       

      

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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