Jump to content

Issue with camera + dragged group of sprite


Recommended Posts


I'm creating a game composed by a map (created with Tiled) and, at the bottom, a menu with a list of building.

The list of building is draggable horizontaly (to see all buildings).

To drag all buildings at the same time I add all the buiding's sprite in a graphics component. I also put a black background with alpha to 0.25. Every component has a fixedOnCamera to true.


Here is my BuildingMenu class TypeScript code:

    public static create(game: Phaser.Game)  {
       let background = game.add.graphics(0, 0);
       background.beginFill(0x000000, 0.25);
       background.drawRect(0, game.height - 64, game.width , 64);
       background.fixedToCamera = true;
       let buildings = ["building1", "building1"....];
       let bounds = new Phaser.Rectangle(-game.width / 2, game.height - 64, game.width, 64);
       this.buildingsGroup = game.add.graphics(0, game.height - 64);

       buildings.forEach((building, index) => {
           let spriteBuilding = game.add.sprite(index * (64 + 2), 0, building.getName());
           spriteBuilding.width = 64;
           spriteBuilding.height = 64;
           spriteBuilding.fixedToCamera = true;
       this.buildingsGroup.width = game.width;
       this.buildingsGroup.height = 64;
       this.buildingsGroup.inputEnabled = true;
       this.buildingsGroup.input.allowHorizontalDrag = true;
       this.buildingsGroup.input.allowVerticalDrag = false;
       this.buildingsGroup.input.enableDrag(false, false, false, 100, bounds);
       this.buildingsGroup.fixedToCamera = true;
    public static update(game: Phaser.Game) {
        game.camera.y += 1


My problem is when I uncomment the line "this.buildingsGroup.addChild(spriteBuilding)" item are affected by the camera but can be dragged of course. The background is not affected....

I can't figure out why... Can anybody help?



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.

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.


  • Recently Browsing   0 members

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