Reputation: 127
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'. I deleted this file 'circle' and put new file and renamed it to '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). And then when I switch back to 'circle', it goes back to old image.
game.load.image('circle', 'assets/circle.gif');
P.S. I tried restarting my computer and my MAMP server.
Upvotes: 0
Views: 582
Reputation: 3747
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. 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
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.
Upvotes: 1
Reputation: 127
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.
Upvotes: 0