Frage

Couldn't really find much help anywhere on this subject-- I'm stuck trying to figure out how to implement a virtual D-Pad on an orthogonal tilemap to simulate movement as seen in the GBA pokemon/zelda games.

Does anyone have a good tutorial i should look at? If not, I'd appreciate example code as well.

War es hilfreich?

Lösung

SneakyInput is what I used for my D-Pad in my game, the classes can be found at 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

You then declare the dimensions of each of the buttons and their positions on the screen:

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

If you want the full code block I can help you out, but its long and I don't want to type it all out here. Hope this helps.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top