//
// TestLayer.h
// MiniTD
//
// Created by OnePiece on 12-7-30.
// Copyright 2012年 __MyCompanyName__. All rights reserved.
// #import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "CCCrack.h" @interface TestLayer : CCNode
{
CCCrack *crack;
}
+(id)scene;
@end
//
// TestLayer.m
// MiniTD
//
// Created by OnePiece on 12-7-30.
// Copyright 2012年 __MyCompanyName__. All rights reserved.
// #import "TestLayer.h"
#import "CCExtendLabel.h"
#import "BaseDefine.h"
#import "CCCrack.h"
#import "UpgradeNode.h"
@interface TestLayer()<UIGestureRecognizerDelegate>{
UpgradeNode *upgradeNode;
int buildStep;
CCSprite *sprite; }
@end
@implementation TestLayer
+(id)scene
{
CCScene *scene = [CCScene node];
TestLayer *testLayer = [TestLayer node];
[scene addChild:testLayer]; return scene;
}
//多指操作看来最好还是用真机测试,测试各种手势之间的冲突情况
-(void)onEnter{
[super onEnter]; sprite=[[CCSprite alloc] initWithFile:@"gege.png"];
sprite.position=ccp(,);
[self addChild:sprite]; // [self buildingProcess]; UIPanGestureRecognizer * panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanFrom:)];
panRecognizer.delegate = self; // panRecognizer.cancelsTouchesInView=NO;
// panRecognizer.delaysTouchesBegan=YES; int fff= panRecognizer.maximumNumberOfTouches; //=2;
int fdsfdsf= panRecognizer.minimumNumberOfTouches; //=2; //panRecognizer.minimumNumberOfTouches=2;
// panRecognizer.maximumNumberOfTouches=2;
UILongPressGestureRecognizer *pressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handlePressFrom:)];
pressGesture.minimumPressDuration = ; pressGesture.allowableMovement = ; pressGesture.delaysTouchesBegan=YES; pressGesture.cancelsTouchesInView=NO; pressGesture.delegate = self; // int ff= pressGesture.numberOfTapsRequired;
// int ffff= pressGesture.numberOfTouchesRequired;
//
// pressGesture.numberOfTouchesRequired=2;
// pressGesture.numberOfTapsRequired=0; [[[CCDirector sharedDirector]openGLView]addGestureRecognizer:panRecognizer]; [[[CCDirector sharedDirector]openGLView]addGestureRecognizer:pressGesture]; }
-(void)handlePressFrom:(UILongPressGestureRecognizer *)recognizer
{ if([recognizer state] == UIGestureRecognizerStateBegan)
{
printf("长按开始\n"); }
else if([recognizer state] == UIGestureRecognizerStateChanged)
{ printf("长按移动\n");
}
else if([recognizer state] == UIGestureRecognizerStateEnded)
{
printf("长按结束\n");
}
} //地图的平移
- (void)handlePanFrom:(UIPanGestureRecognizer *)recognizer { if(recognizer.state == UIGestureRecognizerStateBegan)
{
printf("开始位移\n");
}
else if(recognizer.state == UIGestureRecognizerStateChanged)
{
printf("位移中\n");
}
else if (recognizer.state == UIGestureRecognizerStateEnded)
{
printf("位移结束\n");
}
} //- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
//{
// return YES;
//}
//-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
//{
// return YES;
//} -(void)buildingProcess;
{
if(!upgradeNode)
{
buildStep = ;
upgradeNode = [UpgradeNode nodeWithParent:self Level:];
upgradeNode.position = ccp(,);
[self addChild:upgradeNode z:MaxZorder];
[upgradeNode startProgress]; // //建造过程特效
// CCSprite *buildEffectSprite = [CCSprite spriteWithSpriteFrameName:@"military_build_1.png"];
// buildEffectSprite.opacity = 1;
// buildEffectSprite.position = ccp(buildEffectSprite.contentSize.width/2,buildEffectSprite.contentSize.height/2);
// [mainSprite addChild:buildEffectSprite z:1 tag:200];
// [buildEffectSprite runAction:[CCFadeIn actionWithDuration:1.6]];
//
sprite.opacity=;
[sprite runAction:[CCFadeIn actionWithDuration:]]; [self schedule:_cmd]; //调用自身方法 } // // 2秒为啥和1.6*3对应
//
int percentage = [upgradeNode percentage]; if(buildStep == && percentage >= )
{
buildStep = ; // mainSprite.opacity = 255;
// //很聪明啊,通过叠加的效果
// [mainSprite setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"military_build_1.png"]];
//
// CCSprite *buildEffectSprite = (CCSprite*)[mainSprite getChildByTag:200];
// [buildEffectSprite setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"military_build_2.png"]]; [sprite setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"military_build_2.png"]]; sprite.opacity = ; [sprite runAction:[CCFadeIn actionWithDuration:]]; [self unschedule:_cmd]; //停止轮训自身 }
// else if(buildStep == 2 && percentage >= 64)
// {
// buildStep = 3;
//
// [mainSprite setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"military_build_2.png"]];
//
// CCSprite *buildEffectSprite = (CCSprite*)[mainSprite getChildByTag:200];
// [buildEffectSprite setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"militaryTower2.png"]];
// buildEffectSprite.opacity = 0;
// [buildEffectSprite runAction:[CCFadeIn actionWithDuration:1.6]];
// }
//
//
// if(buildStep ==3 && percentage >= 100)
// {
//
//
//
// buildStep = -1; //建好了
//
// [upgradeNode endProgress];//移除loading
// upgradeNode = nil;//置空
//
// buildComplete = true; //建塔完毕
//
// [mainSprite removeChildByTag:200 cleanup:YES];
//
// CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"militaryTower2.png"];
// [mainSprite setDisplayFrame:frame];
// mainSprite.position = ccp(17,-33);
//
//
// //升级的效果
// [self upgradeSmoke];//烟雾
//
// [self unschedule:_cmd]; //停止轮训自身
//
//
//
//
//
//
// isCanUpgradeMainTower = true;//可以升级主建筑
//
// [self UpgradeBuildWithLevel:curUpgradeLevel Property:curPropertyCount Brach:hybrid Skill:(SkillStruct){0,0}];
//
// //音乐先忽略
// // [SoundManager stopEffect:buildEffectID];
// // [SoundManager playEffect:Military_Build];
//
//
//
//
//
// zorderPos = ccpAdd(baseSprite.position,ccp(0,-45));
// [self.parent reorderChild:self z:[user zorderForPosition:zorderPos]];
//
// [self focusAnimation:@"LostFocus"];
//
// //检测是否需要显示锁定精灵
// if(curUpgradeLevel == maxUpgradeLevel)
// {
// lockSprite.visible = YES;
// }
//
//
// //检查士兵 是否移动到新的旗子点
// [self schedule:@selector(scheduleSoldier) interval:0.5f];
//
// //实时检测是否需要更新胡萝卜数
// [self scheduleUpdate];
//
// //更新buff
// [self schedule:@selector(updateBuff) interval:0.2];
//
// [user addTower:self];
//
// //增加一个建塔数成就点
// [[AchievementManager sharedManager] addTowerType:Military_Tower Count:1 TowerLevel:1];
// }
} -(id)init
{
if(self = [super init])
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:- swallowsTouches:YES];
} return self;
} -(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
// crack = [CCCrack bladeWithMaximumPoint:100];
// [crack setTexture:[[CCTextureCache sharedTextureCache] addImage:@"streak.png"]];
// [self addChild:crack];
printf("轻点开始\n");
return YES;
} -(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
// CGPoint location = [self convertTouchToNodeSpace:touch];
//
// [crack push:location]; printf("轻点滑动\n");
} -(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
printf("轻点结束\n");
}
-(void) ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event
{
printf("触碰取消\n");
} @end
[[CCDirector sharedDirector] runWithScene:[CCTransitionFade transitionWithDuration:0.5 scene:[TestLayer scene] withColor:ccBLACK]];