Author Topic: iOS Canabalt Problems/Solutions  (Read 19044 times)

axcho

  • Active Member
  • ***
  • Posts: 174
  • Karma: +0/-0
    • View Profile
    • Evolution Live!
Re: iOS Canabalt Problems/Solutions
« Reply #20 on: Fri, Mar 11, 2011 »
Thanks for sharing your fix, IQpierce.

Lately I've been trying Cocos2D for iPhone game development, but after being spoiled on Flixel, it is so frustrating to have no built-in movement code in sprites, no straightforward way to animate a sprite given a spritesheet of frames, and having to write my own score data singleton class just to keep track of the player score independently of scenes and such. It feels like Cocos2D is missing so much.

So I'm wondering whether Flixel iOS is complete enough to justify a switch. Would you recommend using Flixel iOS over Cocos2D?

IQpierce

  • Gamewright
  • Member
  • **
  • Posts: 39
  • Karma: +2/-0
    • View Profile
    • Deep Plaid Games
Re: iOS Canabalt Problems/Solutions
« Reply #21 on: Sat, Mar 12, 2011 »
I don't see any signs of anyone else actually working on Flixel iOS games yet, which surprises me - but hopefully that means my game will be the first iOS game using the Flixel engine save SemiSecret's own games?

Anyway axcho, my experience with it has been good so far. I had prototyped a puzzle game in AS3 Flixel and had it in a solid/fun state just when Flixel iOS was released. A few nights later I basically did a long coding session to "port" the game - literally copied/pasted over my AS3 classes and functions and just "translated" from AS3 to Obj-C line by line - and sooner than you would think, I had my puzzle game up and running in the engine.

I've never actually used Cocos2D on iOS or any other platform, so I'm afraid I can't compare them. I can only say that, if you know how to code in Objective-C/Cocoa and are used to all the weird quirks of it (like the unbelievably clumsy syntax for manipulating NSArrays and NSDictionaries), then coding in the Flixel iOS engine will otherwise feel very pleasantly familiar.

There are some quirks; you'll see many places where the methods have odd names for Objective-C methods. Specifically where most Obj-C coders would name a function something like "attackTarget:WithWeapon:", you may see a Flixel function that looks like "attackParam1:Param2:". I realized that this was to ease automated translation from AS3 to Obj-C (which Adam has mentioned they were working on, but which they haven't released and possibly haven't finished): it makes it easier to translate an AS3 function call like "attack(trgt,wpn)".

Honestly what I miss most is the Greensock libraries (TweenLite/Max and TimelineLite/Max). Having such nice, well-animated tweens, and being able to setup and and "play" a dynamic script of events (and do it all with so few lines of code) are definitely things I miss. But that's not really Flixel-related so I'm digressing.

I did find that performance of my game was worse than I expected when I had many particles with collisions going on - but I only got that working in a rough form and I may not have been doing it the most optimal way. But I took out the collision on the particles (I didn't really need them to collide) and now it performs quite well with many particles moving onscreen at once (say 60+, with about 100 other less active sprites in the scene as well), even on my 3G and with little optimization (I'm not even reusing a pool of particles).
I'm just one guy trying to make some interesting decisions!

initials

  • Contributor
  • ****
  • Posts: 378
  • Karma: +0/-0
  • Initials
    • View Profile
    • Initials Blog. Code and other things.
Re: iOS Canabalt Problems/Solutions
« Reply #22 on: Sun, Mar 13, 2011 »
I don't see any signs of anyone else actually working on Flixel iOS games yet, which surprises me - but hopefully that means my game will be the first iOS game using the Flixel engine save SemiSecret's own games?

I'm working on an iOS port of my first Flixel game Picking Up Chicks Is Hard When Your Car Is A BMX. It was a moderately successful flash game, we'll see how it goes in the app store.

It does bother me about the lack of enthusiasm over the iOS Flixel release. Sure, lots of the news blogs picked up the story and it has probably been great for Semi Secret, but the Flixel iOS community seems to be lacking. Maybe we get our own board (or section of this board?) or a mailing list or something for the Flixel iOS devs to chat on.

It makes sense. Flash runs on PC/Mac/Linux and can be developed for free with Flash Develop. iOS needs a Mac, iPhone/pod/pad, and a $99 developer subscription. That's not cheap! And on top of the Objective C can be a brain bender at first.

------------

Note on the Flixel template, if you are using the fantastic Hello World template for Flixel, and you wish to use a texture atlas, there is a function called PreLoadTextureAtlases() (or similar, it's not in front of me right now), that is commented out. You need to uncomment this if you have a texture atlas (and I suggest you do!)
Initials: Super Lemonade Factory, Super Lemonade Factory Part Two, Above The Clouds, Revvolvver, Four Chambers of the Human Heart

initials

  • Contributor
  • ****
  • Posts: 378
  • Karma: +0/-0
  • Initials
    • View Profile
    • Initials Blog. Code and other things.
Re: iOS Canabalt Problems/Solutions
« Reply #23 on: Sun, Mar 13, 2011 »
I hope this can help someone, but I just stripped down the Canabalt source to get something simple to start from without losing all the iPhone specific start-up stuff.  So, here's a HelloWorld template for your xCode, easy to install.

Just drop the whole folder into Developers/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application

If you notice anything Canabalt-specific I forgot to remove, let me know!

Get it here: https://github.com/bigjko/Flx-iOS-template

If you use Texture Atlases, remember to uncomment out this:
 //preloadTextureAtlases();
in the AppDelegate.

Initials: Super Lemonade Factory, Super Lemonade Factory Part Two, Above The Clouds, Revvolvver, Four Chambers of the Human Heart

axcho

  • Active Member
  • ***
  • Posts: 174
  • Karma: +0/-0
    • View Profile
    • Evolution Live!
Re: iOS Canabalt Problems/Solutions
« Reply #24 on: Mon, Mar 14, 2011 »
Thank you both for your responses - I'm going to go ahead with Flixel iOS!

I noticed that some of the Flixel iOS methods have descriptive parameter names, while most of them are still methodWithParam1:param2:etc. I wonder if it would be helpful if someone (me?) went through and converted all of them to descriptive parameter names.

It's just as automate-able, because you can use the parameter names. For example, this:
Code: [Select]
- (void) drawWithParam1:(FlxSprite *)Brush param2:(int)X param3:(int)Y;
would become this:
Code: [Select]
- (void) drawWithBrush:(FlxSprite *)Brush x:(int)X y:(int)Y;
What do you think?

initials

  • Contributor
  • ****
  • Posts: 378
  • Karma: +0/-0
  • Initials
    • View Profile
    • Initials Blog. Code and other things.
Re: iOS Canabalt Problems/Solutions
« Reply #25 on: Mon, Mar 14, 2011 »
The methods that have non descriptive names are incredibly annoying. If you were a newbie to Flixel and starting with iOS, these would be hard to get your head around.

I've already made big progress on my game using the current flixel iOS version, but if you edit those methods Flixel would become much easier to use!

I still have to refer to the headers when finding what param4 and param5 mean.

If you make the replacements I volunteer to bug test for you.
Initials: Super Lemonade Factory, Super Lemonade Factory Part Two, Above The Clouds, Revvolvver, Four Chambers of the Human Heart

axcho

  • Active Member
  • ***
  • Posts: 174
  • Karma: +0/-0
    • View Profile
    • Evolution Live!
Re: iOS Canabalt Problems/Solutions
« Reply #26 on: Mon, Mar 14, 2011 »
Sounds good, I'll try revising then. I just didn't want to do that if it would mess up a bunch of people's projects, but it looks like not many people have started yet.


By the way, I just created a cleaned-up version of the Flixel HelloWorld project template that jonkk posted, plus file templates for FlxObject, FlxSprite, and FlxGroup.

Let me know if you want me to post these somewhere. :)

initials

  • Contributor
  • ****
  • Posts: 378
  • Karma: +0/-0
  • Initials
    • View Profile
    • Initials Blog. Code and other things.
Re: iOS Canabalt Problems/Solutions
« Reply #27 on: Mon, Mar 14, 2011 »
Those would definitely be helpful.
Post those for sure!

I've found the HelloWorld template is a great starting point. The only thing that caught me is the preloadTextureAtlas method is commented out, which I posted about somewhere on this board.
Initials: Super Lemonade Factory, Super Lemonade Factory Part Two, Above The Clouds, Revvolvver, Four Chambers of the Human Heart

axcho

  • Active Member
  • ***
  • Posts: 174
  • Karma: +0/-0
    • View Profile
    • Evolution Live!
Re: iOS Canabalt Problems/Solutions
« Reply #28 on: Mon, Mar 14, 2011 »
Okay, cool - once I revise the method parameters in Flixel iOS to be more descriptive.

So should I uncomment that preloadTextureAtlas() method then? I wasn't clear on whether that is okay to call if you aren't using atlases.

Also, in the Info.plist file, the only supported orientations are Landscape left and right. Does that need to be changed, or is it better to leave that in as a default?

initials

  • Contributor
  • ****
  • Posts: 378
  • Karma: +0/-0
  • Initials
    • View Profile
    • Initials Blog. Code and other things.
Re: iOS Canabalt Problems/Solutions
« Reply #29 on: Mon, Mar 14, 2011 »
So should I uncomment that preloadTextureAtlas() method then? I wasn't clear on whether that is okay to call if you aren't using atlases.

This might be a question for Big John if he's still on this forum. I assume it was commented out for a reason. It's just a huge gotcha. As a newbie to Flixel iOS (and I guess we all are), it took me a while to figure that one out, so I'm just trying to warn people.

Also, in the Info.plist file, the only supported orientations are Landscape left and right. Does that need to be changed, or is it better to leave that in as a default?

Good find! I hadn't thought of that. I am building a portrait game in Flixel and haven't checked this out yet.
Initials: Super Lemonade Factory, Super Lemonade Factory Part Two, Above The Clouds, Revvolvver, Four Chambers of the Human Heart

axcho

  • Active Member
  • ***
  • Posts: 174
  • Karma: +0/-0
    • View Profile
    • Evolution Live!
Re: iOS Canabalt Problems/Solutions
« Reply #30 on: Wed, Mar 16, 2011 »
By the way, I finished converting all the method names, according to this algorithm:

Code: [Select]
function FlashToObjectiveC(FunctionName:String, FunctionType:String, ParameterNames:Array, ParameterTypes:Array) : String
{
  var result:String = "- (" + FunctionType + ") " + FunctionName;
  if (ParameterNames.length == 1)
  {
    var parameter:String = ParameterNames[0];
    var parameterType:String = ParameterTypes[0];

    result += ":(" + parameterType + ")" + parameter + ";";
  }
  else if (ParameterNames.length > 1)
  {
    var parameter:String = ParameterNames[0];
    var parameterType:String = ParameterTypes[0];

    for (int i = 1; i < ParameterNames.length; i++)
    {
      parameter = ParameterNames[i];
      parameterType = ParameterTypes[i];

      if (i == 0)
      {
        if (result.lastIndexOf(parameter) != result.length - parameter.length)
        {
          result += "With" + parameter.substr(0, 1).toUpperCase() + parameter.substr(1);
        }
      }
      else
      {
        result += " " + parameter.substr(0, 1).toLowerCase() + parameter.substr(1);
      }
      result += ":(" + parameterType + ")" + parameter;
    }
  }
  return result;
}

:)

In the process, I discovered that a number of features are not implemented, such as the FlxSound class, and the FlxQuadTree (which explains why collision detection is slow!).

I'll see if I can do something about FlxQuadTree.

I also created icons for the Flixel iOS template! :D And I've been debugging the retina display issues. As it turns out, not only are there problems with portrait mode, but any zoom other than 1.0 doesn't work correctly on retina. Still working on that...

axcho

  • Active Member
  • ***
  • Posts: 174
  • Karma: +0/-0
    • View Profile
    • Evolution Live!
Re: iOS Canabalt Problems/Solutions
« Reply #31 on: Wed, Mar 16, 2011 »
After spending the entire day trying to fix the display issues associated with zoom > 1 and retina and iPad displays, I have decided to give up on trying to figure this out on my own, at least until I can talk with the original programmer, Eric Johnson.

Really tricky and weird stuff, and tons of permutations. Bleh. :P

initials

  • Contributor
  • ****
  • Posts: 378
  • Karma: +0/-0
  • Initials
    • View Profile
    • Initials Blog. Code and other things.
Re: iOS Canabalt Problems/Solutions
« Reply #32 on: Thu, Mar 17, 2011 »
Good work!
Where can I download it from?

The flixel template just got tweeted by Semi Secret! Good work guys.

Initials: Super Lemonade Factory, Super Lemonade Factory Part Two, Above The Clouds, Revvolvver, Four Chambers of the Human Heart

IQpierce

  • Gamewright
  • Member
  • **
  • Posts: 39
  • Karma: +2/-0
    • View Profile
    • Deep Plaid Games
Re: iOS Canabalt Problems/Solutions
« Reply #33 on: Thu, Mar 17, 2011 »
Need to check this thread more - as you say we Flixel iOS dev seem to be a small community. :) Maybe once we put our games out, if they have any success, the engine will get more attention among the iPhone community - as you say it seems like the existing Flixel userbase maybe isn't the most logical one for jumping over to iOS development. Objective-C is not exactly as easy to learn as AS3.

I hadn't dealt with the texture atlas issue, since my simple puzzle game uses so few textures that I haven't bothered with compiling an atlas.

Regarding the odd function names: when you think about it, it makes sense. The function names with "param1:param2" are exactly as descriptive as normal function names - which do not actually contain any descriptions of what the parameters are in the actual function NAME. Therefore when you make a function call in AS3:

takeAction("foo", 2);

When you just look at that code right there, you have no idea whatsoever what those parameters are.

This would normally be a strength of iOS, in that you could look at such a line and it would be:

[self takeActionWithName:@"foo" andNumTimes:2];

Much more informative...

BUT when you're trying to build a language-translator, you want to keep it simple; so when you come across the AS3 line above, your script has no idea how to translate that into the Obj-C line above - because from that line alone, it has no idea that it should name the parameters "Name" and "NumTimes".

Hence giving the params deterministic (but uninformative) names of Param1:, Param2:, etc., makes it easier to translate the code line-by-line.

And in AS3 etc., the only way to remind yourself what the parameters to such a function call ARE from looking at such a line is to use your IDE's dynamic info/autocomplete/whatever that tells you about the function. The real problem is that Obj-C/XCode has less great features for that case, since it usually doesn't need it.

Oh and I'm not surprised to hear that QuadTrees aren't in the iOS engine, given the slow collision and the fact that they were a later addition to Flixel AS3. If someone brings those over to AS3 it would be awesome.
I'm just one guy trying to make some interesting decisions!

jonkk

  • Member
  • **
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: iOS Canabalt Problems/Solutions
« Reply #34 on: Fri, Mar 18, 2011 »
Awesome work, axcho. Go ahead and upload it as a fork to my template on Github.  It's pretty straightforward, as far as I know.

axcho

  • Active Member
  • ***
  • Posts: 174
  • Karma: +0/-0
    • View Profile
    • Evolution Live!
Re: iOS Canabalt Problems/Solutions
« Reply #35 on: Fri, Mar 18, 2011 »
Thanks for the encouragement! :)

So, I just got in contact with Eric Johnson, so it looks like I'll try to keep working on these display bugs before I release the new template now. Though if you really want it right now, with the changed method names, just send me a PM and I'll email it to you or something.

As for forking your template on GitHub, I'm not sure that it would be so straightforward, since it uses a different folder structure, to include both the Project Templates and File Templates. When I finish preparing this Flixel iOS release I will probably want to start it as a new GitHub project, or maybe have Eric or Adam release it officially on theirs. We'll see. :)

axcho

  • Active Member
  • ***
  • Posts: 174
  • Karma: +0/-0
    • View Profile
    • Evolution Live!
Re: iOS Canabalt Problems/Solutions
« Reply #36 on: Fri, Mar 18, 2011 »
I just heard back from Eric Johnson, and one thing he said is that using FlxQuadTree was actually slower than brute-force collision detection, so he switched to brute-force. Not sure if the FlxQuadTree that is included in Flixel iOS is fully functional (if slow) or not.

FlxSound was not implemented for lack of time, but basic sound works through FlxG.play and such.

I'll let you know if I have any luck clearing out the display bugs.

axcho

  • Active Member
  • ***
  • Posts: 174
  • Karma: +0/-0
    • View Profile
    • Evolution Live!
Re: iOS Canabalt Problems/Solutions
« Reply #37 on: Mon, Mar 21, 2011 »
Okay, I had a chat with Eric Johnson, and now I know what to try next.

Basically, the useTextureBufferZoom option was a hack specifically for Canabalt in order to compensate for a bug in Apple's display code. I'll be taking it out, which will make things much cleaner in FlxGame. It shouldn't make a difference unless you are using OpenGL line-drawing calls in a pixelated game.

Then I'll try to come up with a better way to deal with zooming on iPad and retina displays, so you can choose to either mimic the proportions of the iPhone version or use the full resolution of the iPad to have a larger gameplay area. Right now there is an awkward way of using the zoom property of FlxGame and modelScale properties of FlxSprites to arrange this.

And maybe it would be nice to add accelerometer support as well. Any suggestions on the interface? (FlxG.accelerometer.x?)

IQpierce

  • Gamewright
  • Member
  • **
  • Posts: 39
  • Karma: +2/-0
    • View Profile
    • Deep Plaid Games
Re: iOS Canabalt Problems/Solutions
« Reply #38 on: Mon, Mar 21, 2011 »
That sounds great - I always had a feeling that the method I had chosen for fixing those retina/zoom issues was a bit of a hacky workaround. (But it works for me so I'm running with it for now.)

I agree with adding FlxG.accelerometer for sure. But in Flixel's spirit of also providing many "useful but simple" other utilities, I'd suggest that you also offer a "FlxG.accelerometerFiltered.x" value that returns the value tracked with a highpass filter (probably with a separate FlxG variable to control the factor applied to that filter): http://stackoverflow.com/questions/142944/how-do-you-implement-a-highpass-filter-for-the-iphone-accelerometer

That seems to be one of those things that everyone implements on every game, so why not put it in the engine so you don't have to rewrite it over and over? And having the accelerometer seems like it would be a boon since games with mechanics like Doodle Jump could then be made more easily.

I just remembered one of my major other complaints about Flixel on iOS: Buttons. Is it just me or are the buttons terrible? I didn't see any built-in way to do a "pushed" state (I ended up hacking/reusing the "disabled" state for this - the fact that it supported a disabled state but not a pushed state was boggling for me); and its method for detecting a push are pretty hacky so far as I can see (just a "finger released over this button" check, rather than ensuring that the finger was actually pressed down on that button to begin with - and very fast 1-frame-long taps seem to not register as presses at all).

Of course there were caveats about the iOS engine and maybe this was one. It seemed like methods for a proper push-detect were in the code, but commented out. I should probably stop complaining about it and go fix it instead - but I did want to mention it in this thread as a possible caveat around using the engine. If your gameplay is heavily based on GUI buttons, you may have some issues with the engine in its current form.
I'm just one guy trying to make some interesting decisions!

axcho

  • Active Member
  • ***
  • Posts: 174
  • Karma: +0/-0
    • View Profile
    • Evolution Live!
Re: iOS Canabalt Problems/Solutions
« Reply #39 on: Tue, Mar 22, 2011 »
Nice thinking about that filtered accelerometer idea - I'll try that. :)

I'll also plan on looking into the buttons. Maybe the "over" state could be used for a "down" state instead on iOS?