Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java-如何将字符串转换为精灵?_Java_String_Libgdx_Sprite_Converter - Fatal编程技术网

java-如何将字符串转换为精灵?

java-如何将字符串转换为精灵?,java,string,libgdx,sprite,converter,Java,String,Libgdx,Sprite,Converter,我需要一个关于我正在制作的游戏的建议。。我有16个精灵,可以在运行时定位在43个位置。对于每个位置,我制作了一个字符串,其中包含将定位在该位置的精灵。如何将字符串转换为精灵名称,以便稍后向该精灵添加操作?如果我想添加If语句来检查这16个精灵中的哪一个在每个位置,将需要将近700个If。。有没有办法将字符串转换为精灵?您有精灵的编号 如果是,那么简单的解决方案是让字符串哈希代码按精灵计数进行修改。不幸的是,您需要保留一个映射来存储哪个字符串映射到哪个精灵 例如: int spriteCount

我需要一个关于我正在制作的游戏的建议。。我有16个精灵,可以在运行时定位在43个位置。对于每个位置,我制作了一个字符串,其中包含将定位在该位置的精灵。如何将字符串转换为精灵名称,以便稍后向该精灵添加操作?如果我想添加If语句来检查这16个精灵中的哪一个在每个位置,将需要将近700个If。。有没有办法将字符串转换为精灵?

您有精灵的编号

如果是,那么简单的解决方案是让字符串哈希代码按精灵计数进行修改。不幸的是,您需要保留一个映射来存储哪个字符串映射到哪个精灵

例如:

int spriteCount = 16:
Map strMap = new HashMap();//add type
String str = incomintStr;
int hashStr = incomingStr.hashCode();
int location = hashStr % spriteCount;//a number less than the remaining counts
map.put(str,location);
sprite[location].put(str); 
spriteCount = spriteCount -1; 

欢迎来到StackOverflow。请花点时间查看提供的帮助页面,特别是如何提供帮助。请提供一些例子。是的,我有编号。我试试这个。非常感谢。请记住使用映射以避免哈希代码冲突:)