我一直在谷歌搜索并搜索堆栈溢出,但有什么办法可以找出像素是什么点?比如,是否有一些应用程序可以确定您的指向说,(321,199)?
虽然我在这里,在CoCos2d中,我使用的是iPhone 5.0模拟器,所以我假设它有视网膜显示。然而,当我告诉CoCos2d将精灵放置在(516,724)时,我不得不将其降低到320x480的测量值。我以为视网膜是640x960。
答案 0 :(得分:2)
就像UIKit一样,cocos可让您通过使用“积分”轻松处理这两种分辨率。
非视网膜显示中的一个点是一个像素,但在视网膜显示器上,它是两个像素宽,两个像素高。
因此,即使在视网膜设备上工作,您也可以使用320x480点的网格。
答案 1 :(得分:0)
是的,我刚刚制作了一个完全符合此标准的示例应用
HelloWorld.m
//
// HelloWorldLayer.m
// FindCocosCoord
//
#import "HelloWorldLayer.h"
CCLabelTTF *touchLabelX;
CCLabelTTF *touchLabelY;
CCSprite *touchSprite;
@implementation HelloWorldLayer
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
HelloWorldLayer *layer = [HelloWorldLayer node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
-(id) init
{
if( (self=[super init])) {
self.isTouchEnabled = YES;
touchLabelX = [CCLabelTTF labelWithString:@"X = " fontName:@"Marker Felt" fontSize:20];
touchLabelX.position = ccp(100,50);
[self addChild:touchLabelX];
touchLabelY = [CCLabelTTF labelWithString:@"Y = " fontName:@"Marker Felt" fontSize:20];
touchLabelY.position = ccp(170,50);
[self addChild:touchLabelY];
touchSprite = [CCSprite spriteWithFile:@"Icon-Small.png"];
touchSprite.position = ccp(0,0);
[self addChild:touchSprite];
}
return self;
}
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch* myTouch = [touches anyObject];
CGPoint location = [myTouch locationInView: [myTouch view]];
location = [[CCDirector sharedDirector]convertToUI:location];
touchSprite.position = location;
touchX = touchSprite.position.x;
touchY = touchSprite.position.y;
NSLog(@"Location X = %i", (int)touchX);
NSLog(@"Location Y = %i", (int)touchY);
NSString *touchXstring = [NSString stringWithFormat:@"X = %i", (int)touchX];
NSString *touchYstring = [NSString stringWithFormat:@"Y = %i", (int)touchY];
[touchLabelX setString:touchXstring];
[touchLabelY setString:touchYstring];
}
- (void) dealloc
{
[super dealloc];
}
@end
HelloWorld.h
#import "cocos2d.h"
@interface HelloWorldLayer : CCLayer
{
int touchX,touchY;
}
+(CCScene *) scene;
@end