下にレイヤーがあり、HelloWorldLayer
どこでもタッチが機能しますが、下のレイヤーのスプライトにタッチしたときにのみ機能するようにしたいと思いturtle
ます。
レイヤーに追加しようとするself.isTouchEnabled = YES;
と、CCTurtle
isTouchEnabled
オブジェクトタイプCCTurtleにプロパティが見つかりません
私の出力は次のようになります
2013-01-08 20:30:14.767 FlashToCocosARC [6746:d503] cocos2d:割り当て解除
2013-01-08 20:30:15.245 FlashToCocosARC [6746:d503]ウォークアニメーションの再生2
これが私のHelloWorldLayerコードです:
#import "HelloWorldLayer.h"
#import "CCTurtle.h"
@implementation HelloWorldLayer
+(CCScene *) scene
{
CCScene *scene = [CCScene node];
HelloWorldLayer *layer = [HelloWorldLayer node];
[scene addChild: layer];
return scene;
}
-(id) init
{
if( (self=[super init])) {
turtle= [[CCTurtle alloc] init];
[turtle setPosition:ccp(300, 100)];
[self addChild:turtle];
///addChild:child z:z tag:aTag;
self.isTouchEnabled = YES;
turtle. tag=4;
//
}
return self;
}
//- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
// // Processing all touches for multi-touch support
// UITouch *touch = [touches anyObject];
// if ([[touch view] isKindOfClass:[turtle class]]) {
// NSLog(@"[touch view].tag = %d", [touch view].tag);
// [self toggleTurtle];
// }
//}
-(BOOL)containsTouch:(UITouch *)touch {
CGRect r=[turtle textureRect];
CGPoint p=[turtle convertTouchToNodeSpace:touch];
return CGRectContainsPoint(r, p );
}
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//////GENERAL TOUCH SCREEN
for (UITouch *touch in touches) {
CGPoint touchLocation = [touch locationInView:[touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
[self toggleTurtle];
/////
}
}
-(void) toggleTurtle
{
NSLog(@"playing walk animation2");
[turtle playAnimation:@"walk_in" loop:NO wait:YES];
}
@end
//こんにちはworld.h
#import "cocos2d.h"
#import "CCTurtle.h"
@interface HelloWorldLayer : CCLayer
{
CCTurtle *turtle;
}
+(CCScene *) scene;
@end
// CCturtle
#import <Foundation/Foundation.h>
#import "FTCCharacter.h"
@interface CCTurtle : FTCCharacter <FTCCharacterDelegate, CCTargetedTouchDelegate>
{
}
@end
私はCocos2Dcocos2dv1.0.1(arch対応)を使用しており、ipad4.3シミュレーターでテストしています。感謝を込めてナタリー
iveはタッチをccturtle.mに直接入れようとしたため、上記のようにCCTargetedTouchDelegateを使用して独自のタッチを処理できますが、
CCturtle ///ファイルをこれに変更して、タッチされた領域を見つける別の方法を試しました...
- (CGRect)rect
{
CGSize s = [self.texture contentSize];
return CGRectMake(-s.width / 2, -s.height / 2, s.width, s.height);
}
-(BOOL) didTouch: (UITouch*)touch {
return CGRectContainsPoint(self.rect, [self convertTouchToNodeSpaceAR:touch]);
//return CGRectContainsPoint( [self rect], [self convertTouchToNodeSpaceAR: touch] );
}
-(BOOL) ccTouchBegan:(UITouch*)touch withEvent: (UIEvent*)event {
NSLog(@"attempting touch.");
if([self didTouch: touch]) {
return [self tsTouchBegan:touch withEvent: event];
}
return NO;
}
ただし、 「プロパティ」は「TouchEnabled」というエラーがオブジェクトタイプ「CCTurtle *」に見つからないため、コンパイルされません。
今それを実行するために私が何ができるか本当にわかりません...そして本当にこれを機能させる必要があります(私は目に見えないボタンを作ることができると思いますが、ccturtleを正しく見つけて何を理解することができればもっといいでしょう私は間違っています...誰かが助けることができることを願っています