Flixel Forums

development => iOS => Topic started by: wahkiz on Wed, Apr 18, 2012

Title: flxtilemap & controller
Post by: wahkiz on Wed, Apr 18, 2012
After trying out flixel for myself, I find this library quite interesting. I have been doing cocos2d for a long time now, and flixel itself is a breath of fresh air. I think what I like about flixel ios right now, is how it resembles what cocos2d used to be, simple to use, easy to understand. Right now cocos2d has become quite a bloat, and flixel is just right for what I am looking for.

However, in this current state, without the flxtilemap library and touch screen controls class, it's hard to work with it. I tried extracting the controls from mode, but doesnt seems to work.
Title: Re: flxtilemap & controller
Post by: initials on Wed, Apr 18, 2012
What seems to be your problem with the controls from Mode?
Title: Re: flxtilemap & controller
Post by: wahkiz on Wed, Apr 18, 2012
Hey initials,

thanks for all the work you put into making the flixel-ios library awesome! Right now I have copied over flxg,flxtouches and flxgame header and implementation file over already. Then I added the buttons and controls sprite into my state file. However tapping on the controls does not give a response.

I added this code into my update function.

Quote
    if (FlxG.touches.vcpLeftArrow) {
        NSLog(@"left");
        [player setAcceleration:CGPointMake(-player.maxVelocity.x*4, 0)];

    } else if (FlxG.touches.vcpRightArrow) {
         NSLog(@"right");
         [player setAcceleration:CGPointMake(player.maxVelocity.x*4, 0)];

    }
Title: Re: flxtilemap & controller
Post by: initials on Wed, Apr 18, 2012
Have a look at registering some defaults in FlxG.

I store these in FlxG so that you can customize button position. If you're not registering the defaults, it's probably set it to 0 or NIL or NULL so it's looking for a touch between 0,0 and 0,0.

I know the Flixel iOS addons are messy right now. There are a bunch of things pulled from different sources, but I'm a noobie to git and versioning, so basically Mode-iOS is my branch of Flixel for the public. I hope to open source Super Lemonade Factory eventually, with the Game Center, XML Ogmo Level (that is super messy! but it works.) and other stuff.


Code: [Select]
+ (void) initAudio
{
  [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
                                                           [NSNumber numberWithFloat:1.0], @"MusicVolume",
                                                           [NSNumber numberWithFloat:1.0], @"SoundEffectsVolume",
                                                           
                                                           [NSNumber numberWithFloat:0], @"LEFT_ARROW_POSITION_X",
                                                           [NSNumber numberWithFloat:240], @"LEFT_ARROW_POSITION_Y",
                                                           [NSNumber numberWithFloat:80], @"RIGHT_ARROW_POSITION_X",
                                                           [NSNumber numberWithFloat:240], @"RIGHT_ARROW_POSITION_Y", 
                                                           
                                                           [NSNumber numberWithFloat:320], @"BUTTON_1_POSITION_X",
                                                           [NSNumber numberWithFloat:240], @"BUTTON_1_POSITION_Y",
                                                           [NSNumber numberWithFloat:400], @"BUTTON_2_POSITION_X",
                                                           [NSNumber numberWithFloat:240], @"BUTTON_2_POSITION_Y",                                                             
                                                           
nil]];
   
    if (self.iPad) {
        [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                 [NSNumber numberWithFloat:0], @"LEFT_ARROW_POSITION_X",
                                                                 [NSNumber numberWithFloat:304], @"LEFT_ARROW_POSITION_Y",
                                                                 [NSNumber numberWithFloat:80], @"RIGHT_ARROW_POSITION_X",
                                                                 [NSNumber numberWithFloat:304], @"RIGHT_ARROW_POSITION_Y", 
                                                                 [NSNumber numberWithFloat:352], @"BUTTON_1_POSITION_X",
                                                                 [NSNumber numberWithFloat:304], @"BUTTON_1_POSITION_Y",
                                                                 [NSNumber numberWithFloat:432], @"BUTTON_2_POSITION_X",
                                                                 [NSNumber numberWithFloat:304], @"BUTTON_2_POSITION_Y",                                                             
                                                                 nil]];
    }
Title: Re: flxtilemap & controller
Post by: initials on Wed, Apr 18, 2012
If you're having no luck, go into FlxTouches and change this bit:

Code: [Select]
            if (p2.x > FlxG.leftArrowPosition.x &&
                p2.x < FlxG.leftArrowPosition.x+80 &&
                p2.y > FlxG.leftArrowPosition.y &&
                p2.y < FlxG.leftArrowPosition.y+80) {
               
                vcpLeftArrow = YES;
            }

change it to

Code: [Select]
            if (p2.x > 0 &&
                p2.x < 800 &&
                p2.y > 0 &&
                p2.y < 800) {
               
                vcpLeftArrow = YES;
            }

See if you get any response. It will check a huge part of the screen for a touch.

If you want to hard code it because the NSDefaults aren't working, or because you don't want to edit your FlxG file, just start putting numbers in for the values, but it's pretty hard working out touches for retina/iPhone/iPad/textureBufferZoom etc.

Title: Re: flxtilemap & controller
Post by: wahkiz on Wed, Apr 18, 2012
Hmm, somehow after changing the values it still does not register. The flxG file should be the same as mode's.

I have attached the project files to my dropbox. https://dl.dropbox.com/s/75ro9ikhg5yq7wr/lode.zip?dl=1. It is basically code that I ported over from ezplatformer in as.

If it's not too troubling, I hope that you can take a look at the code. Much appreciated!

Seeing that the touch detection is dependent on stored position values, I am thinking, maybe in the future the touch controls addon could instead opt to read the positions from the control's sprite? Just a thought. :D

Nice work on Super Lemonade Factory btw!
Title: Re: flxtilemap & controller
Post by: initials on Wed, Apr 18, 2012
You're calling [super update] twice.

Do all your control pad stuff before the call to super update.
Title: Re: flxtilemap & controller
Post by: wahkiz on Thu, Apr 19, 2012
cool thanks! it works now. any chances of flxtilemap getting ported? I don't mind helping, I know it's tough when you are doing it all by yourself.
Title: Re: flxtilemap & controller
Post by: initials on Thu, Apr 19, 2012
There is a post on this forum where someone has started, and possibly completed it.

I don't use it for iOS personally, because the Flash version creates a single FlxSprite for each tile. Checking collisions with those on iOS really slowed down, so I aborted it and used a modified FlxTileBlock that does some auto placement to make blocks, but they are large rectangles, not a group of single FlxSprites.

So check out the other thread, I will be looking at other stuff, such as FlxPaths before I get to FlxTileMap.