简体   繁体   English

如何移相器:更改图像文件

[英]How Phaser: to change image file

I'm currently working on this game and I'm having trouble with image loading. 我目前正在开发这款游戏,无法加载图片。 Or should I say "dis-loading?" 还是我应该说“卸货”?

I had this image file 'circle' and I used this image file to create sprite 'ball'. 我有此图像文件“ circle”,并使用此图像文件创建了精灵“ ball”。 I deleted this file 'circle' and put new file and renamed it to 'circle'. 我删除了此文件“ circle”,并放置了新文件,并将其重命名为“ circle”。 Basically, I replaced it. 基本上,我替换了它。

BUT, when I save my work and refresh my game, it still uses old file, although it's not in my asset folder anymore! 但是,当我保存工作并刷新游戏时,尽管它不再位于我的资产文件夹中,但仍使用旧文件! When I change the file name to something else like 'circle1' then it suddenly works again(meaning new image is loaded). 当我将文件名更改为“ circle1”之类的文件时,它突然又可以工作了(意味着已加载新图像)。 And then when I switch back to 'circle', it goes back to old image. 然后,当我切换回“圆形”时,它又回到了旧的图像。

game.load.image('circle',       'assets/circle.gif');

PS I tried restarting my computer and my MAMP server. PS我尝试重新启动计算机和MAMP服务器。

This happens because the browser caches the assets. 发生这种情况是因为浏览器缓存了资产。 Basically put, the browser looks in the cache first, sees that a file with this name and this URL is already there and decides that it needs not to turn to the server and thus it shows you the old file. 基本上,浏览器首先在缓存中查找,发现具有该名称和URL的文件已经存在,并决定不需要转向服务器,从而向您显示旧文件。 Clear the browser's cache and you should see the new file. 清除浏览器的缓存,您应该会看到新文件。

A workaround from Phaser's point of view would be to add simple versioning to the files, so instead of 从Phaser的角度来看,一种解决方法是向文件添加简单的版本控制,因此,

game.load.image('circle', 'assets/circle.gif'); ,

you do the following: 您可以执行以下操作:

var version = 1;
game.load.image('circle', 'assets/circle.gif' + '?' + version);

and change version 's value every time you change an asset. 并在每次更改资产时更改version的值。

Took a while to figure out. 花了一段时间才弄清楚。 (Still not sure) (仍然不确定)

I think if I create a new sprite with the image, it let the new image file to replace all the old ones. 我想如果我用图像创建一个新的精灵,它会让新的图像文件替换所有旧的文件。 I don't know why. 我不知道为什么 Please explain me if you know why or exact way of fixing this. 如果您知道解决此问题的原因或确切方法,请向我解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM