在这个主题的任何地方都找不到多少帮助 - 我一直试图弄清楚如何在正交的tilemap上实现虚拟D-Pad来模拟GBA口袋妖怪/塞尔达游戏中的运动。
有没有人有一个我应该看的好教程?如果没有,我也会欣赏示例代码。
答案 0 :(得分: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);
}
如果你想要完整的代码块,我可以帮助你,但它很长,我不想在这里输入所有内容。希望这会有所帮助。