cocos2d触碰例子代码
//
// 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]];
cocos2d触碰例子代码的更多相关文章
- 触屏设备上的多点触碰检测C++代码实现
转自:http://aigo.iteye.com/blog/2272698 代码还是参考自Epic官方的塔防项目:StrategyGame 看了下C++的API,现成的API中貌似只支持单点触碰检测, ...
- cocos2dx基础篇(7) 触碰事件
cocos2dx游戏引擎的重点是在于移动设备的跨平台开发,而移动设备上的游戏大部分都是通过屏幕触碰来进行的.比如主菜单的按钮触碰,打飞机中飞机的触碰移动,都需要用到触碰操作.想一想之前讲的菜单按钮CC ...
- 触碰jQuery:AJAX异步详解
触碰jQuery:AJAX异步详解 传送门:异步编程系列目录…… 示例源码:触碰jQuery:AJAX异步详解.rar AJAX 全称 Asynchronous JavaScript and XML( ...
- 触碰jQuery:AJAX异步详解(转)
AJAX 全称 Asynchronous JavaScript and XML(异步的 JavaScript 和 XML).它并非一种新的技术,而是以下几种原有技术的结合体. 1) 使用CSS和X ...
- Android基础新手教程——3.4 TouchListener PK OnTouchEvent + 多点触碰
Android基础新手教程--3.4 TouchListener PK OnTouchEvent + 多点触碰 标签(空格分隔): Android基础新手教程 本节引言: 如题,本节给大家带来的是To ...
- TouchListener PK OnTouchEvent + 多点触碰
1.基于监听的TouchListener 代码示例: 实现效果图: 实现代码: main.xml <RelativeLayout xmlns:android="http://schem ...
- 爬虫界的福利--touchRobot,机器模拟触碰滑动库(已开源)
此插件能干什么? 一句话概括:通过程序主动触发移动端滑动.拖拽.触碰等操作 插件有什么用呢? 可以用于爬虫,也可以用于自动化测试以及程序演示 插件演示地址 (从网上扒了一个canvas绘图的demo, ...
- <<精通iOS开发>>第14章例子代码彻底清除警告
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 上一篇我们解决了<<精通iOS开发>> ...
- swiper4自动轮播切换手动触碰后停止踩坑——属性disableOnInteraction
swiper4轮播设置autoplay自动切换后,即默认设置: <script> var mySwiper = new Swiper('.swiper-container', { auto ...
随机推荐
- ajax 选项卡
Ajax其实就是交互式网页应用开发技术包括以下几个方面: 1.XHTML和CSS 2.使用DOM作为动态显示和交互 3.使用XML和XSLT 做数据交互和操作 (这些完全不太懂) 4.使用XMLHtt ...
- C++的深拷贝与浅拷贝
对于普通类型的对象来说,它们之间的复制是很简单的,例如:int a=88;int b=a; 而类对象与普通对象不同,类对象内部结构一般较为复杂,存在各种成员变量.下面是一个类对象拷贝的简单例子. #i ...
- java项目调用kettleJob和Trans
1.调用本地Job和Trans 较简单不用多说没有遇到任何问题,以下是代码: import org.pentaho.di.core.KettleEnvironment; import org.pent ...
- 高效能人士必知铁律--note
偶然看到了<高效能人士 必知铁律>这本书,我比较少看成功学,但是这本书把很多著名的成功学书籍整理出来,有时会让你耳目一新,有些观点尽管是常识,但是却加深了你对它们的理解,比如: 只要在积极 ...
- Quant的笑话
Q) Why was the FX quant so unlucky with the ladies?A) Because he always kept his dates short. Q) Why ...
- python socket
#!/usr/bin/env python import sys import time import socket s = socket.fromfd(sys.stdin.fileno(),sock ...
- Jmeter基础之---jmeter基础概念
Jmeter基础之---jmeter基础概念 JMeter 介绍: 一个非常优秀的开源的性能测试工具. 优点:你用着用着就会发现它的重多优点,当然不足点也会呈现出来. JMeter 介绍: 一个非常优 ...
- LeetCode---String
Count and Say 思路:递归求出n - 1时的字符串,然后双指针算出每个字符的次数,拼接在结果后面 public String countAndSay(int n) { if(n == 1) ...
- ubuntu下sublime中文无法输入的问题
感谢- http://www.cnblogs.com/ningvsban/p/4346766.html
- Linux下使用ping快速检测存活主机
该shell脚本主要是通过ping来批量检测网段内存活主机,执行结果保存在脚本当前目录下的IPinfor目录中,写的比较匆忙,希望大家留下更好的建议. #!/usr/bin/env bash##### ...