LHSprite registerTouchBeganObserver

-(id) init {

if( (self=[super init])) {

LHSprite *piyoSprite1 = [loader spriteWithUniqueName:@”piyo_baby_1″];
[piyoSprite1 registerTouchBeganObserver:self selector:@selector(touchBegin:)];

}
}

-(void)touchBegin:(LHTouchInfo*)info {

CCLOG(@”%s”,__func__);

CGPoint touchLocation = [self convertTouchToNodeSpace:info.touch];
CGPoint spriteLocation = info.sprite.position;

CCLOG(@”touchLocation=%f,%f”,touchLocation.x,touchLocation.y);
CCLOG(@”spriteLocation=%f,%f”,spriteLocation.x,spriteLocation.y);

if(info.sprite) {
CCLOG(@”Touch BEGIN on sprite %@”, [info.sprite uniqueName]);
LHSprite *piyoSprite = [loader spriteWithUniqueName:[info.sprite uniqueName]];
b2Body *piyoBody = [piyoSprite body];
b2Vec2 tmpvec = piyoBody->GetLinearVelocity();
CCLOG(@”tmpvec=%f,%f”,tmpvec.x,tmpvec.y);

//        piyoBody->ApplyLinearImpulse(b2Vec2((spriteLocation.x-touchLocation.x)/50,-1), piyoBody->GetLocalCenter());
piyoBody->SetLinearVelocity(b2Vec2((spriteLocation.x-touchLocation.x)/8.0f,1.0f));
b2Vec2 tmpvec2 = piyoBody->GetLinearVelocity();
CCLOG(@”tmpvec=%f,%f”,tmpvec2.x,tmpvec2.y);
}

if(info.bezier)
CCLOG(@”Touch BEGIN on bezier %@”, [info.bezier uniqueName]);

}

LHSprite registerTouchBeganObserver
トップへ戻る