SneakyJoyStick 用法( 兼容universal)

1. import  JoystickClasses folder into project

2. 在game操作的layer.h import class


#import "SneakyJoystick.h"

#import "SneakyButton.h"


#import "SneakyButtonSkinnedBase.h"

#import "SneakyJoystickSkinnedBase.h"


@interface GameplayLayer : CCLayer {
    CCSprite *vikingSprite;
    SneakyJoystick *leftJoystick;
    SneakyButton *jumpButton;
    SneakyButton *attackButton;
}
@end



-(void)initJoystickAndButtons {
CGSize screenSize = [CCDirector sharedDirector].winSize; // 1
CGRect joystickBaseDimensions = CGRectMake(0, 0, 128.0f, 128.0f);                      // 2
CGRect jumpButtonDimensions   = CGRectMake(0, 0, 64.0f, 64.0f);
CGRect attackButtonDimensions = CGRectMake(0, 0, 64.0f, 64.0f);

CGPoint joystickBasePosition;                                  // 3
CGPoint 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:vikingSprite
forTimeDelta: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
   }
}


资源下载链接为: https://pan.quark.cn/s/502b0f9d0e26 在当下互联网蓬勃发展的时代,流媒体技术已然成为多媒体内容传播与分享的关键手段,而 m3u8 格式凭借其基于 HTTP Live Streaming (HLS) 的特性,在在线视频、直播等诸多领域被广泛应用。不过,普通用户若想把 m3u8 链接下载下来,再转换成像 MP4 这样的本地离线观看文件,往往离不开一款专业的工具——m3u8 下载器。本文将深入剖析 m3u8 下载器的功能特点,以及其如何助力用户实现多任务下载、突破速度限制、将 ts 文件合并为 MP4 格式,还有处理加密视频等诸多功能。 m3u8 下载器核心功能是能从 m3u8 播放列表里解析出 TS 分片文件,并进行批量下载。TS 即传输流,是流媒体传输中常见的数据包形式。该下载器支持多任务下载,用户可同时操作多个 m3u8 链接,对于有大量视频下载需求的用户而言,这大大提升了下载效率。而且,m3u8 下载器在合法合规的前提下,通过优化下载策略,突破了常规网络环境下部分网站对下载速度的限制,让用户能更快速地获取所需多媒体资源。 此外,m3u8 下载器还能把 TS 文件合并成 MP4 文件。TS 文件是流媒体数据的片段,MP4 则是一种通用且便于存储、播放的格式。下载器会自动按顺序将所有 TS 文件合并,生成完整的 MP4 文件,极大简化了用户操作。更关键的是,它支持处理采用 AES-128-CBC 加密的 TS 文件。AES 是广泛使用的加密标准,CBC 是其工作模式之一,对于这类加密的 m3u8 视频,下载器能自动识别并解密,保障用户正常下载、播放加密内容。 m3u8 下载器还对错误进行了修正,优化了性能,有效解决了下载中断等问题,确保下载过程稳定。同时,软件在设计时将安全性作为重点,注重保护用户隐私,规避下载过程中的安全风
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值