Meteor and Phaser - error loading asset

天涯浪子 提交于 2020-01-07 09:03:48

问题


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:


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



来源:https://stackoverflow.com/questions/31736758/meteor-and-phaser-error-loading-asset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!