相位器3无法加载资产

时间:2019-05-09 16:27:41

标签: javascript phaser-framework

我对Phaser3框架有问题。我无法使用以下方式导入Spritesheet

this.load.multiatlas('cowboy', 'assets/Character_Json.json', 'assets');

资产文件夹似乎没有导入浏览器,但我确定它存在。

我在“网络”标签上签入了chrome开发人员工具;它说不能导入资产,但我不知道为什么。

/*Game Settings*/

var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    scene: {
        preload: preload,
        create: create,
        update: update
    },
    physics: {
        default: 'arcade',
        arcade: {
            gravity: {y: 0},
            debug: false
        }
    }
};


/*Game Globals*/

var game = new Phaser.Game(config);
var Scene;


function preload()
{
    Scene = this;

    this.load.multiatlas('cowboy', 'assets/Character_Json.json', 'assets');

    this.load.image('tiles', 'assets/Dungeon_Tileset.png');
    this.load.tilemapTiledJSON('json_map', 'assets/MapFinal.json');

}


/*This create MAP in the scene with JSON-MAP and create Layeres*/

function createMap(Scene){
     map = Scene.make.tilemap({key: 'json_map'});
     var tiles = map.addTilesetImage('Dungeon_Tileset', 'tiles');

     map.Layers = createLayers(map,tiles);

     return map;

}

/*Create layers for the map with tiles ( JSON )*/

function createLayers(map,tiles)
{
    backgroundLayer = map.createDynamicLayer('Background', tiles, 0, 0);

    collisionLayer = map.createDynamicLayer('Collision', tiles, 0, 0);

    slowLayer = map.createDynamicLayer('Slow', tiles, 0, 0);
    fastLayer = map.createDynamicLayer('Fast', tiles, 0, 0);
    itemLayer = map.createDynamicLayer('Item', tiles, 0, 0);
    //collisionLayer.setCollisionByExclusion([-1]);
    return Layers = {
        backgroundLayer : backgroundLayer,
        collisionLayer : collisionLayer,
        slowLayer : slowLayer,
        fastLayer : fastLayer,
        itemLayer : itemLayer
    };
}

/*Create annimations in scene*/

function createAnimations(Scene)
{
    Scene.anims.create({
        key: 'run',
        frames: Scene.anims.generateFrameNumbers('cowboy', {start: 0, end: 16}),
        frameRate: 20,
        repeat: -1
    });
}

/*Create all objects for our game and return them*/

function createGameObjects(Scene){
    return GameObjects = {
        player : Scene.physics.add.sprite(40, 40, 'cowboy', "Idle__001.png"),
        score : 0,
        cursor : Scene.input.keyboard.createCursorKeys()
        //textScore : Scene.add.text(200, 0, "Score: " + this.score, {font: "25px Impact"})
    };
}

/*CreatePhysics for objects (collisions)*/

function createPhysics(Scene,GameObjects,map)
{
   player = GameObjects.player;

   collisionLayer = map.Layers.collisionLayer;


   Scene.physics.add.collider(player, collisionLayer, collisionWithCollisionLayer);

}

function create()
{
   /*create Map with layers and save it to map variable (map.Layers)*/
   map = createMap(Scene);

   createAnimations(Scene);
   //create all GameObjects for this Scene
   var GameObjects = createGameObjects(Scene);

//create Physic for all ours game Objects
   createPhysics(Scene,GameObjects,map);

}

function update()
{
    //player.anims.play('run', true);

}

NetBeans代码

enter image description here

控制台输出

enter image description here

网络输出

enter image description here

1 个答案:

答案 0 :(得分:0)

我不认为这是一个大错误,只是如何使用this.load.multiatlas(...)

所以,我想您想从文件夹assets/加载地图集,因此请尝试以下方式:

this.load.setPath('assets/');
this.load.multiatlas('cowboy', 'Character_Json.json');

如果仍然不想加载,请告诉我json文件不正确