SneakyJoyStick 用法( 兼容universal)
来源:互联网 发布:php 电子商城 编辑:程序博客网 时间:2024/06/03 16:54
1. import JoystickClasses folder into project
2. 在game操作的layer.h import class
#import "SneakyButton.h"
#import "SneakyJoystickSkinnedBase.h"
@interface GameplayLayer : CCLayer {
CCSprite *vikingSprite;
SneakyJoystick *leftJoystick;
SneakyButton *jumpButton;
SneakyButton *attackButton;
}
@end
-(void)initJoystickAndButtons {CGSize screenSize = [CCDirector sharedDirector].winSize; // 1CGRect joystickBaseDimensions = CGRectMake(0, 0, 128.0f, 128.0f); // 2CGRect jumpButtonDimensions = CGRectMake(0, 0, 64.0f, 64.0f);CGRect attackButtonDimensions = CGRectMake(0, 0, 64.0f, 64.0f);CGPoint joystickBasePosition; // 3CGPoint jumpButtonPosition;CGPoint attackButtonPosition;if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { // 4// The device is an iPad running iPhone 3.2 or later.CCLOG(@"Positioning Joystick and Buttons for iPad"); joystickBasePosition = ccp(screenSize.width*0.0625f, screenSize.height*0.052f); jumpButtonPosition = ccp(screenSize.width*0.946f, screenSize.height*0.052f); attackButtonPosition = ccp(screenSize.width*0.947f, screenSize.height*0.169f); } else {// The device is an iPhone or iPod touch.CCLOG(@"Positioning Joystick and Buttons for iPhone"); joystickBasePosition = ccp(screenSize.width*0.07f, screenSize.height*0.11f); jumpButtonPosition = ccp(screenSize.width*0.93f, screenSize.height*0.11f); attackButtonPosition = ccp(screenSize.width*0.93f, screenSize.height*0.35f); } SneakyJoystickSkinnedBase *joystickBase = [[[SneakyJoystickSkinnedBase alloc] init] autorelease]; // 5 joystickBase.position = joystickBasePosition; // 6 joystickBase.backgroundSprite = [CCSprite spriteWithFile:@"dpadDown.png"]; // 7 joystickBase.thumbSprite = [CCSprite spriteWithFile:@"joystickDown.png"]; // 8 joystickBase.joystick = [[SneakyJoystick alloc] initWithRect:joystickBaseDimensions]; // 9 leftJoystick = [joystickBase.joystick retain]; // 10 [self addChild:joystickBase]; // 11 SneakyButtonSkinnedBase *jumpButtonBase = [[[SneakyButtonSkinnedBase alloc] init] autorelease]; // 12 jumpButtonBase.position = jumpButtonPosition; // 13 jumpButtonBase.defaultSprite = [CCSprite spriteWithFile:@"jumpUp.png"]; // 14 jumpButtonBase.activatedSprite = [CCSprite spriteWithFile:@"jumpDown.png"]; // 15 jumpButtonBase.pressSprite = [CCSprite spriteWithFile:@"jumpDown.png"]; // 16 jumpButtonBase.button = [[SneakyButton alloc] initWithRect:jumpButtonDimensions]; // 17 jumpButton = [jumpButtonBase.button retain]; // 18 jumpButton.isToggleable = NO; // 19 [self addChild:jumpButtonBase]; // 20 SneakyButtonSkinnedBase *attackButtonBase = [[[SneakyButtonSkinnedBase alloc] init] autorelease]; // 21 attackButtonBase.position = attackButtonPosition; // 22 attackButtonBase.defaultSprite = [CCSprite spriteWithFile:@"handUp.png"]; // 23 attackButtonBase.activatedSprite = [CCSprite spriteWithFile:@"handDown.png"]; // 24 attackButtonBase.pressSprite = [CCSprite spriteWithFile:@"handDown.png"]; // 25 attackButtonBase.button = [[SneakyButton alloc] initWithRect:attackButtonDimensions]; // 26 attackButton = [attackButtonBase.button retain]; // 27 attackButton.isToggleable = NO; // 28 [self addChild:attackButtonBase]; // 29}
在每一帧中检测joystick ,应用joystick的响应:
#pragma mark -#pragma mark Update Method-(void) update:(ccTime)deltaTime{ [self applyJoystick:leftJoystick toNode:vikingSpriteforTimeDelta:deltaTime];}
实际通过下面方法对某node的操作
-(void)applyJoystick:(SneakyJoystick *)aJoystick toNode:(CCNode *)tempNode forTimeDelta:(float)deltaTime{ CGPoint scaledVelocity = ccpMult(aJoystick.velocity, 1024.0f); // 1 CGPoint newPosition = ccp(tempNode.position.x + scaledVelocity.x * deltaTime,tempNode.position.y + scaledVelocity.y * deltaTime); // 2 [tempNode setPosition:newPosition]; // 3 if (jumpButton.active == YES) { CCLOG(@"Jump button is pressed."); // 4 } if (attackButton.active == YES) { CCLOG(@"Attack button is pressed."); // 5 }}
- SneakyJoyStick 用法( 兼容universal)
- Universal Image Loader用法详解
- Android图片加载框架(universal-image-loader,Picasso,Glide,Fresco)的用法
- Android-Universal-ImageLoader的用法和案例
- Universal-ImageLoader的优点,以及用法
- 兼容ie8 rgba()用法
- 兼容ie8 rgba()用法
- Universal Link(iOS)踩坑
- iPad开发(Universal Applications)
- min-height兼容浏览器用法
- 兼容ie8 的 rgba()用法
- 兼容ie8以下 rgba()用法
- Android图片加载库—Universal-ImageLoader用法详解
- Universal-Image-Loader(android图片缓存)
- Universal-Image-Loader(android图片缓存)
- Universal-Image-Loader(android图片缓存)
- Universal-Image-Loader(android图片缓存)
- Universal-Image-Loader(android图片缓存)
- jquery 图片随机切换插件
- 如何写每周工作报告(How to Write a Weekly Report)
- 记python开发网络爬虫所遇问题
- ibatis的#和$的区别
- SAE MYSQL 连接实例(创建一个表)
- SneakyJoyStick 用法( 兼容universal)
- 测试GCC在windows下编译宽字符的问题
- Eclipse介绍
- 11G的SORT GROUP BY NOSORT导致错误执行计划
- 解决CButtonST按钮类在vs2005下报错问题
- PrefereceActivity 程序配置方案
- MVC框架实现10---Smart框架打包、下载、使用
- linux top命令详解
- Scroll View Programming Guide for iOS 笔记