[0]Box2D项目滚动屏幕问题

想实现超级玛丽那样角色始终在屏幕中间,滚动背景世界
发现无论是方法1还是方法2都不行....
已邀请:

Winterning

赞同来自:

DEMO点击屏幕就是给主角加个力 往右边移动的 移动到中场就开始滚屏  结果跟预想不太一样...

Winterning

赞同来自:

private watch(): void {
        //方法1:移动父容器
        // var gloX = -this.player.x + GameConfig.width * 0.5;
        // if (gloX > 0) {
        //     gloX = 0;
        // }
        // else if (gloX < -MainSceneCtrl.SCENE_WIDTH + GameConfig.width) {
        //     gloX = -MainSceneCtrl.SCENE_WIDTH + GameConfig.width;
        // }
        // this.mainScene.world.x = gloX;
        // console.log("@@gloX="+gloX); 
        //方法2:scrollRect
        var tx = this.player.x - GameConfig.width * 0.5;
        if (tx < 0) {
            tx = 0;
        }
        else if (tx > MainSceneCtrl.SCENE_WIDTH - GameConfig.width) {
            tx = MainSceneCtrl.SCENE_WIDTH - GameConfig.width;
        }
        this.mainScene.world.scrollRect = new Laya.Rectangle(tx, 0, GameConfig.width, GameConfig.height);
        console.log("@@tx="+tx); 
    }

要回复问题请先

商务合作
商务合作