更改 6 个图像然后预加载,但图像在更改之前正在预加载

发布于 2024-09-10 03:28:09 字数 1034 浏览 2 评论 0原文

我有 3 张马/骑士奔跑的图像。我交替使用它们,使其看起来像是在运行。我正在使用 GD 来改变特定用户角色的骑士/马的颜色。我更改图像颜色,然后预加载 3 张图像。但当我的程序改变图像时,它们已经被预加载了。所以我必须加载页面两次才能显示 Knight.horse 的正确颜色。我该如何解决这个问题?

代码位于标题中。函数 loadImage 获取基本图像并更改颜色并将其保存在 pic/#.gif 文件位置。然后预加载图像并在末尾添加时间,以便加载新图像而不是缓存中的图像。

loadImage('pic/4.gif','pic/knightcolor0.gif',"1")

loadImage('pic/7.gif','pic/knightcolor0b.gif',"2")
loadImage('pic/5.gif','pic/knightcolor1.gif',"")
loadImage('pic/6.gif','pic/knightcolor2.gif',"")
loadImage('pic/8.gif','pic/knightcolor1R.gif',"")
loadImage('pic/9.gif','pic/knightcolor2R.gif',"")


img1 = new Image();
img1.src = "pic/4.gif?t="+new Date().getTime()
img2 = new Image();
img2.src =  "pic/5.gif?t="+new Date().getTime()
img3 = new Image();
img3.src =  "pic/6.gif?t="+new Date().getTime()
img4 = new Image();
img4.src = "pic/7.gif?t="+new Date().getTime()
img5 = new Image();
img5.src =  "pic/8.gif?t="+new Date().getTime()
img6 = new Image();
img6.src =  "pic/9.gif?t="+new Date().getTime()

请帮助我尝试了很多方法来解决这个问题,已经工作了一个星期了,但无法弄清楚哦!

I have 3 images of a horse/knight running. I am alternating them to make it look like its running. I am using GD to alter the colors of the knight/horse for the specific users chacter. I alter the images color then preload the 3 images. but by the time my program has altered the images they have already been preloaded. so i have to load the page twice for the correct colors of the knight.horse to apear. How do i fix this?

THE CODE is in the header. The function loadImage takes the base image and changes the color and saves it in the pic/#.gif file location. then the images are preloaded and a time is added on to the end so a new image is loaded and not a the image in the cache.

loadImage('pic/4.gif','pic/knightcolor0.gif',"1")

loadImage('pic/7.gif','pic/knightcolor0b.gif',"2")
loadImage('pic/5.gif','pic/knightcolor1.gif',"")
loadImage('pic/6.gif','pic/knightcolor2.gif',"")
loadImage('pic/8.gif','pic/knightcolor1R.gif',"")
loadImage('pic/9.gif','pic/knightcolor2R.gif',"")


img1 = new Image();
img1.src = "pic/4.gif?t="+new Date().getTime()
img2 = new Image();
img2.src =  "pic/5.gif?t="+new Date().getTime()
img3 = new Image();
img3.src =  "pic/6.gif?t="+new Date().getTime()
img4 = new Image();
img4.src = "pic/7.gif?t="+new Date().getTime()
img5 = new Image();
img5.src =  "pic/8.gif?t="+new Date().getTime()
img6 = new Image();
img6.src =  "pic/9.gif?t="+new Date().getTime()

pls help Ive tried a lot of things to fix this been working on it for a week now and cant figure it out ughhhhhh!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百变从容 2024-09-17 03:28:09

如果预加载调用的是您还不想要的图像,那么预加载不会给您带来任何好处。如果您将预加载设置为回调 loadImage 函数,在正确的图像可用之前它不会执行。

或者,你能缩小颜色的选择范围吗?在这种情况下,将这些图像准备好供使用并不是不可想象的。

Preloading won't do you any good if it's calling an image that you don't want yet. If you set up the preload as a callback to the loadImage function, it won't execute until the right image is available.

Alternatively, could you narrow the choices of color? It's not inconceivable, in a situation like this, to have those images already prepared for use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文