Jump to content

Phaser Group : Set offset on group


julien74370
 Share

Recommended Posts

Hi everyone,

 

In first excuse me for my level in english :P

 

I need some advices to do a game.

 

I have in my game a group wich represents my background scenery. It contains one background sprite and some items sprite.

 

However i want to set offset on my group depending on the size of the screen.

 

Backgroud Sprite size : 1650px * 1050px

 

Example :

 

post-15625-0-58965100-1438008550_thumb.p

Black : facultative content visible (1620 * 1050)

White : obligatory content visible (980*520)

Red: some items

 

 

I did a class extending Phaser.Group and controller for switch group displayed

function CameraPrefab(game, parent, name, addToStage, background, items) {    // The super call to Phaser.Group    Phaser.Group.call(this, game, parent, name, addToStage);    var _this = this;    // Add background to group    this.create(0, 0, background);    var item;    // Add items to group    items.forEach(function (item) {        item = _this.create(parseInt(item.pos.x), parseInt(item.pos.y), "itm" + item.id + "_bgn" + item.pos.bgn + "_cam" + item.pos.cam);        item.name = "item";    });}CameraPrefab.prototype = Object.create(Phaser.Group.prototype);CameraPrefab.prototype.constructor = CameraPrefab;function CameraController(scenery_info, position, game){    var _this = this;    this.cams = {};    this.cam_position = 0;    this.backgrouds_list = scenery_info.backgrounds;    this.items_list = scenery_info.items;    this.backgrouds_list.forEach(function(cam){        var backgroundToSet = 'cam_' + cam.id;        _this.cams[cam.id] = new CameraPrefab(game, null, "camera", true, backgroundToSet, _this.getItemsByCamId(cam.id))    });    this.switchCamera(position);}

I would like my game fit the screen size and if my screen size is smaller than 1650 * 1050 set offset until 980 * 520

 

 

I really looking for a way but i did not find one.

 

Do you have an idea to do that?

 

Thank you :D

 

 

 

 

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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