Meteor and Phaser - error loading asset

2019-08-31 05:23发布

I run Phaser with Meteor I get an error when loading a .png file from the directory. Could someone please provide some guidance on how to fix it.

My environment is

ubuntu 14.04
Meteor 1.1.0.2
Phaser v2.3.0

My directory structure and folders are

cmt@ubuntu:~/projects/myMeteorProjects/issueReplication2$ ls -R
.:
client  index.css  index.html  public  server

./client:
client.js   phaser.js

./public:
car.png

index.html is

<head>
  <title>phaser and meteor</title>
</head>

<body>
  <h1>Phaser and Meteor</h1>

  {{> game1}}
</body>

<template name="game1">
  {{phaserGame}}

client.js is

Template.game1.helpers({
    phaserGame: function() {
    var game = new Phaser.Game(320,320, Phaser.AUTO, 'firstGame', { preload:
 preload, create: create, update:update }); 
    return game;

    function preload() {
        game.load.image('car', './public/car.png');
    }

    function create() {
        car = game.add.sprite(50, 50, 'car');
    }

    function update() {
    }

    function moveBullets (bullet) { 
    }

    function accelerateToObject(obj1, obj2, speed) {
    }
    }
})

and finally the error in Chrome is

Phaser.Loader - image[car]: error loading asset from URL ./public/car.png

1条回答
再贱就再见
2楼-- · 2019-08-31 06:02

Change from './public/car.png' to '/car.png'

查看更多
登录 后发表回答