cocos2d 1.01rc iPhone アプリで Retina ディスプレイのタッチを処理しようとしたところ、AppDelegate で Retina ディスプレイに設定したとしても (コードを参照)、タッチ ポイントに倍率を掛ける必要があることがわかりました (以下のコードを参照)。ページの最後にあります)。locationInView関数が「標準」の 480x640 解像度のタッチではなく、網膜ディスプレイのタッチを取得すると予想していたので、少し混乱しています。私の推測では、これはlocationInViewという事実によるものですcocos2d からではなく ios ライブラリから取得され、cocos2d App デリゲートの Retina ディスプレイ設定は ios レベルまで伝播されません。変。明確にするために以下のコードと出力を投稿しますが、同様の問題があり、この「バグ」と見なす必要があるかどうかを評価していただければ幸いです。cocos2d と ios SDK の間で失われる可能性のある何かについての警告ベルとして。私は愚かで、適切なドキュメントページが見つからなかったのかもしれません。
それは私がccTouchesEndedイベントで実行しているコードです:
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
for(int i=0; i<[[touches allObjects] count]; i++){
UITouch *touch = [[touches allObjects] objectAtIndex:i];
CGPoint point = [touch locationInView: [touch view]];
CCLOG(@"Before x:%f y:%f", point.x, point.y);
point = [[CCDirector sharedDirector] convertToGL: point];
float factor = CC_CONTENT_SCALE_FACTOR();
CCLOG(@"factor %f:", factor);
CCLOG(@"After x:%f y:%f", point.x , point.y );
CCLOG(@"After x:%f y:%f", point.x * factor, point.y * factor);
...
}
出力:
Before x:314.000000 y:3.000000
factor 2.000000:
After x:314.000000 y:477.000000
After x:628.000000 y:954.000000
アプリは iPod touch 第 4 世代の Retina ディスプレイで実行されています。初期化データの一部を以下に示します。
cocos2d: cocos2d v1.0.1
cocos2d: GL_VENDOR: Imagination Technologies
cocos2d: GL_RENDERER: PowerVR SGX 535
cocos2d: GL_VERSION: OpenGL ES-CM 1.1 IMGSGX535-63.14.2
cocos2d: GL_MAX_TEXTURE_SIZE: 2048
cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH: 16
cocos2d: GL_MAX_SAMPLES: 4
cocos2d: GL supports PVRTC: YES
cocos2d: GL supports BGRA8888 textures: YES
cocos2d: GL supports NPOT textures: YES
cocos2d: OS version: 5.0.1 (0x05000100)
cocos2d: surface size: 640x960
私はGoogleとstackoverflowをチェックしましたが、これは1年前の既知のバグであると思われました.rc1.01バージョンでこれが修正されているのか、AppDelegateで何か愚かなことをしているのかは100%確信が持てません. :
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
//added
CC_DIRECTOR_INIT();
// Init the window
// window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Try to use CADisplayLink director
// if it fails (SDK < 3.1) use the default director
if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
[CCDirector setDirectorType:kCCDirectorTypeDefault];
CCDirector *director = [CCDirector sharedDirector];
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
// Init the View Controller
// viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
// viewController.wantsFullScreenLayout = YES;
//
// Create the EAGLView manually
// 1. Create a RGB565 format. Alternative: RGBA8
// 2. depth format of 0 bit. Use 16 or 24 bit for 3d effects, like CCPageTurnTransition
//
//
EAGLView *glView = [director openGLView];
[glView setMultipleTouchEnabled:YES];
// attach the openglView to the director
[director setOpenGLView:glView];
// // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director enableRetinaDisplay:YES] )
CCLOG(@"Retina Display Not supported");
何か案は?これは私のコードの他の側面にも影響しますか? タッチ検出のみに関係しているようです。このため、倍率を乗算する修正は問題ないようで、スプライト オブジェクトの相対位置にアクセスするときに問題はないようでした。これについてさらにテストを行い、これを念頭に置きます。
ありがとう!