Jump to content

Issue with camera + dragged group of sprite


weby2014
 Share

Recommended Posts

Hello,

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.endFill();
       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.addChild(spriteBuilding);
       });
       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

 Share

  • Recently Browsing   0 members

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