Java和SDL_GetKeyState() [英] Java and SDL_GetKeyState()

查看:92
本文介绍了Java和SDL_GetKeyState()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一些使用SDL的代码转换为Java.我正在使用sdljava绑定.

I'm trying to convert to Java some code that uses SDL. I'm using the sdljava bindings.

sdljava使用SWIG作为C数据类型和Java之间的桥梁.为了获得等同于SDL_GetKeyState()的值,sdljava提供了方法SWIG_SDLEvent.SDL_GetKeyState(),该方法返回称为SWIGTYPE_p_unsigned_char的内容.

sdljava uses SWIG as the bridge between the C datatypes and Java. To get the equivalent of SDL_GetKeyState(), sdljava provides the method SWIG_SDLEvent.SDL_GetKeyState(), which returns something called a SWIGTYPE_p_unsigned_char.

当然,Java没有unsigned char类型,我不知道编译器认为该SWIG类型实际上代表Java什么.在C/C ++中正常使用SDL_GetKeyState()类似于:

Of course, Java has no unsigned char type, and I don't know what the compiler thinks this SWIG type actually represents to Java. Normal use of SDL_GetKeyState() in C/C++ would be something like:

Uint8 *ks = SDL_GetKeyState(NULL);
if ( ks[SDLK_UP] ) { /* handle Up key */ }

...,其中SDL键状态值(如SDLK_UP)索引到数组中.

... where the SDL keystate values like SDLK_UP index into an array.

但是,以下Java代码:

However, the following Java code:

SWIGTYPE_p_unsigned_char ks = SWIG_SDLEvent.SDL_GetKeyState(null);
if ( ks[SDLKeyValues.SDLK_UP] != 0) { /* handle Up key */ }

导致编译器错误,表达式的类型必须是数组类型,但已解析为SWIGTYPE_p_unsigned_char."

results in the compiler error, "The type of the expression must be an array type, but it resolved to SWIGTYPE_p_unsigned_char."

我想知道的是,在调用SWIG_SDLEvent.SDL_GetKeyState()之后,如何使用它返回的内容来检查各个键的状态?

What I want to know is, after calling SWIG_SDLEvent.SDL_GetKeyState(), how do you use what it returns to inspect the state of the individual keys?

推荐答案

我与负责SWIG Java支持的William Fulton进行了交谈,他回答:

I spoke with William Fulton, who is responsible for SWIG Java support, and he responded:

SWIGTYPE_p_unsigned_char的存在表明包装器还没有被很好地考虑过,因为该类型包装器"类对于从Java中访问不是很有用.

The existence of SWIGTYPE_p_unsigned_char indicates the wrappers have not been thought through very well as this "type wrapper" class is not very useful for access from Java.

请阅读Java章节中有关数组的解决方案- http://www.swig .org/Doc1.3/Java.html 或仅添加一个可以从Java调用的助手方法:

Please read the Java chapter for solutions for arrays - http://www.swig.org/Doc1.3/Java.html or just add in a helper method which you can then call from Java:

%inline %{
 Uint8 getValueFromArray(Uint8* array, size_t i) {
  return array[i];
 }
%}

这篇关于Java和SDL_GetKeyState()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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