Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy tiks issue #29

Closed
jonlepage opened this issue Feb 9, 2019 · 1 comment
Closed

Legacy tiks issue #29

jonlepage opened this issue Feb 9, 2019 · 1 comment

Comments

@jonlepage
Copy link
Contributor

jonlepage commented Feb 9, 2019

Expected Behavior**

When creating a 2d sprite, and assigning values before the tiks, they are badly rendered.
In the example below, all sprites should the same SIZE

Current Behavior

When creating a sprite, should apply values without affecting the future behavior of the sprite2d projection
In the example below, all sprites are not the same SIZE

Possible Solution**

To be honest, it exceeds me and it's really complicated.
This suggests a deep understanding of the rendering.

Environment**

*node: "11.8.0"
*nw: "0.36.0 SDK"

  • pixi.js version: 4.8.2 webGL
  • Browser & Version: *chromium: "72.0.3626.81"
  • OS & Version: _e.g. win10

- Running Example:
please to understand, copy and replace this code in this current link example:
https://pixijs.io/examples/#/projection/iso-basic.js
Sorry not available in pixiplayground.

i clean the code to make easy to read.
you can see the big issue inside the scene at start()

// HERARCHI: APP => STAGE => CAMERA => SCENES => GAMEOBJ
//APP:
class _app extends PIXI.Application { 
  constructor() {
      super({
        width: 800,height: 600,                       
        sharedTicker:true,
        backgroundColor: 0x303030
      });
    };
    run() {
        try { stage.initialize(); } 
        catch (e) { throw console.error(e.stack) };
    };
};

// STAGE: scenesManager
class _stage extends PIXI.Stage {
    constructor() {
        super();
        this.sceneList = {Scene_1:new _Scene_Base(3400,2600)}; //scene cache
        this._timer = -1; // fake timer update for change scene
        this.debugSceneText =  {t:new PIXI.Text(''),_id:0,get next(){this.t.text=`currentScene: ${this._id++}`} };
        this.addChild(this.debugSceneText.t);
        this.ticker = PIXI.ticker.shared.add(this.update, this); // game update sharedTicker:true,
    };
    initialize(){
        this.addChild(Camera);
        Camera.initialize();
    };
    update(delta) {
      try {
          // refresh||change scene cache
          if(--this._timer<0){
            this._timer = 200;
            this.sceneList.Scene_1.end();
            Camera.initialize();
            Camera.setupToScene(this.sceneList.Scene_1);
            this.sceneList.Scene_1.start();
            this.debugSceneText.next
          }else{
            Camera.updateProjection();
          }
      } catch (e) { throw console.error(e.stack) };
    };
};

// SCENE: batch create in a loading scene
class _Scene_Base extends PIXI.projection.Container2d {
    constructor() {super()};
    // start when we succeed clear last 'scene,events,camera,fadeIn'
    // scene are constructed and batched in a buffer kit during the loading scene.
    // start build sprite required for this scene and apply data from json
    start(){
        this.setupObjs();
        setTimeout(()=>this.setupObjs(200) , 300);
        setTimeout(()=>this.setupObjs(300) , 600);
    };
    end(){ 
        this.removeChildren();
    };
    setupObjs(x=100){
        for (let i=0, l=5; i<l; i++) {
            var s = new PIXI.projection.Sprite2d(new PIXI.Texture.fromImage('required/assets/flowerTop.png'));
            this.addChild(s);
            // custom data
            s.rotation= i/Math.PI; // seem ok
            s.anchor.set(0.5,1);
            s.position.set(x,85*i); 
            s.scale.set(0.5);
        };
    };
};

//CAMERA: controler scene rendering , projection, view-port and culling.
class _camera extends PIXI.projection.Container2d{
    constructor() {
        super()
        this._screenW = app.screen.width; 
        this._screenH = app.screen.height;
        this._sceneW = app.screen.width; // scene width
        this._sceneH = app.screen.height; // scene height
        this.far = new PIXI.Sprite(PIXI.Texture.WHITE);
        this.far.factor = 0.5;
        this.scene = null;
    };
    initialize() {
        this._sceneW = app.screen.width; // scene width
        this._sceneH = app.screen.height; // scene height
        this.position.set(this._screenW/2,this._screenH/2); // center camera
        this.scene = null;
        this.removeChildren();
        this.parent.addChild(this.far); // add to stage
        this.far.position.set(this._screenW/2,0);
    };
    setupToScene(scene) {
        this.scene = scene;
        this._sceneW = scene.w;
        this._sceneH = scene.h;
        this.addChild(scene);
        // FIXME: when we creat new sprite it seem no take current setup, we need wait ~next tiks ?
        Camera.updateProjection(); // make one update from current scene.
    };
    updateProjection(){
        const far = this.far  ;
        const _fpX = 0, _fpY = 0, _fpF = 0, _zoom = 1;
        far.x = ((this._screenW/2)-(this.pivot._x*_zoom))+_fpX;
        far.y = (-(this.pivot._y*_zoom))+_fpY;
        far.factor = _fpF;
        this.scale.set(_zoom);
        let pos = this.toLocal(far.position, undefined, undefined, undefined, PIXI.projection.TRANSFORM_STEP.BEFORE_PROJ);
        pos.y = -pos.y;
        pos.x = -pos.x;
        this.proj.setAxisY(pos, -far.factor);
        this.scene.children.forEach(s => { s.proj.affine = PIXI.projection.AFFINE.AXIS_X });// update gameObjs affine
    };
};

var app = new _app();
document.body.appendChild(app.view);
var Camera = new _camera()
var stage = new _stage();
app.stage = stage;
app.run();

Thank in advance for any tips or suggest or fix.
note: It is likely that I misunderstand the problem or that the problem comes from a bad logic.

@jonlepage
Copy link
Contributor Author

7eef6dd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant