スプライトを移動する方法を実装していました。すべてのスプライトを配置する配列を配置し、その配列にタッチで移動するアクションを与えたいと考えています。しかし、実行しても何も起こりません:
-(void)onEnter
{
[super onEnter];
self.isTouchEnabled = YES;
}
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *myTouch = [touches anyObject];
CGPoint location = [myTouch locationInView:[myTouch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
mSpriteOnHand = nil;
for(CCSprite *cloth in mSpriteArray)
{
if(CGRectContainsPoint([cloth boundingBox], location))
{
mSpriteOnHand = cloth;
break;
}
}
}
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
if(mSpriteOnHand)
mSpriteOnHand.position = location;
}
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
mSpriteOnHand = nil;
}
-(void)onExit
{
[mSpriteArray release];
mSpriteArray = nil;
[super onExit];
}
何か問題がありますか?問題はタッチビガンにあると思いますが、よくわかりません...
編集:
スプライトが応答しませんが、メソッドは問題ないようです。これが私の初期化です:
-(id) init
{
if( (self=[super init]) )
{
CGSize winSize = [[CCDirector sharedDirector] winSize];
CCSprite * backGround = [CCSprite spriteWithFile:@"background_ipad.png"];
backGround.position = ccp(winSize.width/2, winSize.height/2);
[self addChild:backGround z:0];
cloth1 = [CCSprite spriteWithFile:@"clothe_1.png"];
cloth1.position = ccp(380, 500);
[self addChild:cloth1 z:1];
cloth2 = [CCSprite spriteWithFile:@"clothe_2.png"];
cloth2.position = ccp(530, 500);
[self addChild:cloth2 z:2];
cloth3 = [CCSprite spriteWithFile:@"clothe_3.png"];
cloth3.position = ccp(700, 500);
[self addChild:cloth3 z:3];
cloth4 = [CCSprite spriteWithFile:@"clothe_4.png"];
cloth4.position = ccp(380, 270);
[self addChild:cloth4 z:4];
cloth5 = [CCSprite spriteWithFile:@"clothe_5.png"];
cloth5.position = ccp(530, 270);
[self addChild:cloth5 z:5];
cloth6 = [CCSprite spriteWithFile:@"clothe_6.png"];
cloth6.position = ccp(700, 270);
[self addChild:cloth6 z:6];
[mSpriteArray addObject: cloth1];
[mSpriteArray addObject: cloth2];
[mSpriteArray addObject: cloth3];
[mSpriteArray addObject: cloth4];
[mSpriteArray addObject: cloth5];
[mSpriteArray addObject: cloth6];
}
return self;
}