简体   繁体   English

我该怎么做图像动画?

[英]How should I do image animation?

I plan to have an animated character (the character's image changing multiple times to make it appear to be moving), and I would like to know the best way to do it. 我计划有一个动画角色(角色的图像多次改变以使其看起来像是在移动),我想知道最好的方法。 I am currently planning to do something like this: 我目前正计划做这样的事情:

String fileLocation = "./images/picture";
BufferedImage img;
int numImages = 10;

for(int i = 0; i < numImages; i++){
    img = ImageIO.read(new File(fileLocation + i + ".png"));
    Thread.sleep(100);
    g.drawImage(img, 0, 0, null);
}

This is an incredibly simplified version, missing a few things, but I'm sure you get what I mean. 这是一个令人难以置信的简化版本,缺少一些东西,但我相信你明白我的意思。 Are there any problems doing it this way? 这样做有什么问题吗? (Note: the for loop would repeat again straight after finishing, and there would be files called "picture0.png", "picture1.png", etc. in the "images" folder) (注意:完成后for循环会再次重复,并且“images”文件夹中会出现名为“picture0.png”,“picture1.png”等的文件)

If the images are not huge and don't require a lot of memory for storing them, I would rather read the images first and cache them. 如果图像不是很大并且不需要大量内存来存储它们,我宁愿先读取图像并缓存它们。 When they need to be displayed, I would read them from memory rather than from disk. 当需要显示时,我会从内存而不是从磁盘中读取它们。

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

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