1

在这个主题的任何地方都找不到太多帮助——我一直在试图弄清楚如何在正交瓷砖地图上实现虚拟方向键来模拟 GBA 口袋妖怪/塞尔达游戏中看到的运动。

有人有我应该看的好教程吗?如果没有,我也会欣赏示例代码。

4

1 回答 1

2

SneakyInput 是我在游戏中用于 D-Pad 的,这些类可以在https://github.com/sneakyness/SneakyInput找到。

#import "SneakyJoystick.h" 
#import "SneakyButton.h"
#import "SneakyButtonSkinnedBase.h"
#import "SneakyJoystickSkinnedBase.h"

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

然后声明每个按钮的尺寸及其在屏幕上的位置:

-(void)initJoystickAndButtons 
{
    CGSize screenSize = [CCDirector sharedDirector].winSize;
    CGRect joystickBaseDimensions = CGRectMake(0, 0, 128.0f, 128.0f);
    CGRect jumpButtonDimensions = CGRectMake(0, 0, 64.0f, 64.0f);
    CGRect attackButtonDimensions = CGRectMake(0, 0, 64.0f, 64.0f);
    CGPoint joystickBasePosition;
    CGPoint jumpButtonPosition;
    CGPoint attackButtonPosition;

    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);
}

如果您想要完整的代码块,我可以帮助您,但它很长,我不想在这里全部输入。希望这可以帮助。

于 2012-03-04T13:12:33.433 回答