从spritesheet载入大量图片 [英] Loading a large number of images from a spritesheet

查看:300
本文介绍了从spritesheet载入大量图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做对的简单的游戏为Android。

I'm attempting to make a simple game of Pairs for Android.

程序结构:

Menu.java(菜单活动最初加载)

Menu.java (Menu activity initially loaded)

Game.java(游戏活动,通过菜单启动)结果
GameThread.java(把手gameloop,电话渲染GameView过程)结果
GameView.java(处理所有绘制到屏幕)

Game.java (Game activity, started by Menu)
GameThread.java (Handles gameloop, calls render process in GameView)
GameView.java (Handles all drawing to the screen)

Graphics.java(存储加载图片)

Graphics.java (Stores loaded images)

问题:

游戏功能15种不同类型的卡,其中每一个需要用于动画(翻转,破坏等)约14帧。目前,我正在阅读这些掀起了PNG spritesheet,然后砍他们到一个位图阵列(位图[15] [14])使用以下code:

The game features 15 different types of card, each of which requires around 14 frames for animation (flipping, destroying, etc). I'm currently reading these off a PNG spritesheet, and then chopping them into a Bitmap array (Bitmap[15][14]) using the following code:

for (int i=0; i<15; i++) {
    for (int j=0; j<14; j++) {
        card[i][j] = Bitmap.createBitmap(spriteSheet,
            j*cardWidth, i*cardHeight, cardWidth, cardHeight);
    }
}

在出现问题时,我最初加载GameView,卡图形需要加载,这似乎需要大约2秒处理(导致无响应的应用程​​序)。

The problem arises when I initially load the GameView, the card graphics need to be loaded, which seems to take around 2 seconds to process (resulting in an unresponsive app).

有没有更好的办法,我可以做到这一点?

Is there a better way I can do this?

感谢您的帮助提前。

推荐答案

如果问题确实是你的应用程序没有响应,我会建议通过一个线程加载图像,同时向用户显示一个不确定的对话框。这是通过线程和的处理器。有很多的如何做到这一点的在线例子。

If the problem is indeed that your app is unresponsive, I would recommend loading the images via a thread while showing the user an indeterminate dialog box. This is generally done via a Thread and a Handler. There are plenty of examples of how to do this online.

如果然而,问题是,你的记忆将不得不想出一个不同的方式来处理所有图像。这可能会在同一时间内只进一个动画,调整您的位图,或者固定内存的问题。有没有办法说没有看到的错误和/或更code。

If however the problem is that of memory your going to have to figure out a different way to handle all the images. That could be loading only one animation at a time, resizing your bitmaps, or fixing a memory problem. There is no way to tell without seeing the errors and/or more code.

最后,我从你的逻辑必然比要求,你可能有更多的位图在内存中看到的。再次,我不能没有看到更多的逻辑是肯定的。

Finally, I see from your logic that you may have more Bitmaps in memory than necessarily are required. Once again I can't be certain without seeing more logic.

这篇关于从spritesheet载入大量图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆