Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - tokyotron

Pages: [1] 2
iOS / Re: Retina / high res textures
« on: Sun, Feb 3, 2013 »

iOS / Re: Flixel and GC?
« on: Sun, Feb 3, 2013 »
Late but, with GC leaderboards you generally need a UIViewController to "add" the default leaderboard controller onto, or something like that. With Flixel we don't use UIViewControllers really so that made orientation etc problematic when I tried just adding my own UIViewController. So instead I decided to implement my own leaderboard interface. It's not rocket science, I just grab the GC leaderboard data and then create a new flixel screen in which I output that data.

This is the published game:,7050.msg39277.html#msg39277

I finished a Flixel iOS game last year. (made it for a client)

江頭2:50の 42.195km ~流石の俺も四苦八苦~

It uses Game Center, and also retina graphics for retina displays. Nothing very complicated, but it was my first game in like forever.
Maybe the coolest thing was the map editor, which was another binary/app really made for iPad. In our team, we used the iPad to make the level - the levels themselves synced automatically to the iPhone game app through iCloud. At the time of release, I just removed all of the iCloud code from the game. :-P It had a really WYSIWYG touch interface and at least I loved it. But had to kill it. :-P The game was released for the Japanese market, not sure now if it's available outside Japan App store or not.

iOS / Black screen at launch time
« on: Thu, Jul 26, 2012 »
I guess there aren't really anyone around here anymore. But I've got this irritating problem and just because...

The flow of starting an iOS app is basically

[user taps app icon] -> [launch pic displays] -> [first controller view displays]

No gaps anywhere...

Now with Flixel iOS it kind of looks like this

[user taps app icon] -> [launch pic displays] -> (black screen) -> [first state view displays]

There seems to be no way (that I know of yet...) to get rid of that first black screen. I get the feeling that Flixel initiates the game engine openGL stuff and directly puts that first empty buffer to the screen, then goes on to load/cache the first state, and only when that is done the state's contents are drawn to screen. If you've got a lot of stuff in that first state, that could take a while, resulting in a long black screen... I tried stripping down the first state to only show like one picture, but there is still a noticable black screen appearing for like 1/100th second or something.

Going to other states after the initial state however renders no black screen AFAIK.

Any ideas?

^ There was a problem with the scales... Basically retina displays render the text half size. I finally managed to fix that by not using initWithView... but by properly converting to UIImage and going from there. :-P

iOS / Re: [SOLVED] FlxG follow...why doesn't it follow?
« on: Tue, Jul 24, 2012 »
Some of the functions in FlixeliOS have undescriptive parameters (maybe a problem caused by something that ported the code).

I tried to change up some of that to make the code more legible awhile back.
Looking at my code now for this section this is probably what would help you:
Code: [Select]
[FlxG followBoundsWithParam1:0 param2:0 param3:stageLength param4:5000 param5:TRUE];
does really mean

Code: [Select]
[FlxG followBoundsWithMinX:0 minY:0 maxX:INT_MAX maxY:320];
Hmm ok one parameter less but you get the idea. Change the 2nd parameter (param2) to a negative value and then you can have it follow negative Y values.

I did have follow negative X values and know it works, although I never tried negative Y values.

iOS / Re: "Auto" playing
« on: Tue, Jul 24, 2012 »
Great. If it only were Flixel iOS...

Okay here are bits of the code that I use to put any font in there... you can add any (that you have rights to ;-) ) font and use that. So you can use any font bundled with iOS or your own font. No need to work hard with mapping tables :-)

This code could be put in some categories or built into the FlxSprite class or even FlxText maybe... I just copy these functions into the state controller though... then add some stuff to FlxSprite and SemiSecretTexture.

First the code in state class:

Code: [Select]
-(void)createMylabels {
FlxSprite* spriteLabel1 = [[self class] spriteFromString:@"My text!" color:[UIColor whiteColor]];
spriteLabel1.x = 5;
spriteLabel1.y = 15;
FlxSprite* spriteLabel2 = [[self class] spriteFromString:@"Something else..." color:[UIColor whiteColor]];
spriteLabel2.x = 5;
spriteLabel2.y = 50;

[self add:spriteLabel1];
[self add:spriteLabel2];

+(FlxSprite*)spriteFromString:(NSString*)string color:(UIColor*)color {
FlxSprite* sprite = [FlxSprite sprite];
UILabel* label = [self labelFromString:string color:color];
[sprite loadGraphicFromView:label animated:NO reverse:NO width:label.frame.size.width height:label.frame.size.height unique:NO modelScale:[FlxSprite deviceScale]];
return sprite;

+(UILabel*)labelFromString:(NSString*)string color:(UIColor*)color {
NSString* theText = string;
UILabel* label = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
label.font = [UIFont fontWithName:@"CourierNewPSMT" size:25]; // Change to any font (need at least iOS 4.x something probably. CourierNewPSMT is monospace and thus easy to use for layout.
label.textColor = color;
const CGSize TEXTSIZE = [theText sizeWithFont:label.font];
label.text = theText;
label.frame = CGRectMake(label.frame.origin.x, label.frame.origin.y, TEXTSIZE.width, TEXTSIZE.height);
return label;

Then add to FlxSprite.h/m:

Code: [Select]
width:(unsigned int)Width
height:(unsigned int)Height
modelScale:(float)ModelScale {
//DLog(@"loadGraphic: %@ ModelScale: %f", Graphic, ModelScale);
modelScale = ModelScale;

//reset colors to all white...
[self fill:0xffffff];
filled = NO;

_bakedRotation = 0;

[texture autorelease];
texture = [[[self class] getTextureFromView:View param2:Unique modelScale:ModelScale] retain];

if (Reverse)
_flipped = ((int)(texture.size.width)) >> 1;
_flipped = 0;

if (Width == 0)
if (Animated) {
Width = texture.size.height/modelScale;
else {
Width = texture.size.width/modelScale;
width = frameWidth = Width;
if (Height == 0)
if (Animated)
Height = width;
Height = texture.size.height/modelScale;
height = frameHeight = Height;
if (Animated)
texture.animated = YES;
[self resetHelpers];

+ (SemiSecretTexture *) getTextureFromView:(UIView *)View param2:(BOOL)Unique modelScale:(float)ModelScale {
SemiSecretTexture* texture = [SemiSecretTexture textureWithView:View modelScale:ModelScale];

return texture;

And add to SemiSecretTexture.h/m:

Code: [Select]
+ (id) textureWithView:(UIView *)view modelScale:(float)ModelScale {
return [[[self alloc] initWithView:view modelScale:ModelScale] autorelease];

- (id) initWithView:(UIView *)view modelScale:(float)ModelScale {
if ((self = [super init])) {
[self prepareWithWidth:view.bounds.size.width * [FlxSprite deviceScale] height:view.bounds.size.height * [FlxSprite deviceScale]];
if (data == NULL) {
[self release];
return nil;

CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(data,

//why the two of these back to back? can be replaced with one? (copied from previous implementation)
CGContextTranslateCTM(context, 0.0, paddedSize.height-size.height);
CGContextTranslateCTM(context, 0.0, size.height);
CGContextScaleCTM(context, 1.0, -1.0);
// size.width *= [FlxSprite deviceScale];
// size.height *= [FlxSprite deviceScale];
[view drawRect:CGRectMake(0, 0, size.width, size.height)];


[self createTexture];
[self setupVerticesTexCoords];

return self;

Btw you could probably replace [FlxSprite deviceScale] with FlxG.screenScale

iOS / "Auto" playing
« on: Wed, Jul 11, 2012 »
This turned out to be more complicated (to me) than I first thought it would be.

I'm wanting to implement a scripted "CPU player" playing the game by itself... Kind of like those arcade games in the 80s where the game played by itself and with the "Insert coin to start play!" message on top. Some ideas I had:

* As the character's movement is controlled by FlxG.touches being in different states at different times (FlxG.touches are probably handled in the FlxGame->update function) , I thought about building something that stores and injects these touches. The problem is, I wouldn't be able to get it exact... there would be timing issues. I think. At least a few milliseconds could be off, and that's enough to make this not work as intended - impossible to script and replay something like a "power play".. etc.

* Store every full screen as a complete frame, and playback those frames as a movie. Problem: Not sure yet how to really store frames :-P Shouldn't be impossible though. However several minutes of frames would be huge (think 30 (or 60?) frames/second) for one or several minutes. Not sure this would work with memory issues, loading times, etc even - changing a FlxSprite the whole size of the screen 30/60 times a second... hmm I'm not sure this port was engineered to do that.

Anyone did something like this before? Got any ideas?

iOS / Re: Facebook integration
« on: Fri, Jul 6, 2012 »
I think it's already official that there's a new framework in iOS 6 that abstracts FB and similar platforms into one API...  Like Twitter and a Chinese SNS. Imagine your sales when 2 billion Chinese people chat online about your game. And oh FB is banned in China, and wait, maybe Twitter too :-)

iOS / Re: Performance
« on: Fri, Jul 6, 2012 »
Oh btw I guess there is an explanation somewhere but FPS maxes out at 60 on iPhone 4, and 30 on iPhone 3G. Not sure about other devices. Guess if I you reach those numbers you're safe. :-P

iOS / Performance
« on: Thu, Jul 5, 2012 »
Anyone got anything to say about Performance?

Ie you make a game, and after awhile

* things start going slow, like you get low FPS (there's an easy way to turn on FPS output to console)
* you just wanna get a general hunch where your game spends most of the time

Well a quick googling turned up this page for Cocos2d, another game engine, but I guess a lot of that can be applied with iFlixel as well.

At least the part about Instruments seem useful - using "Time Sampler" within Instruments. With Cocos2d there is supposedly a "CCDirector mainLoop" being the main loop of the game... Of course we have a similar thing in iFlixel as well, but it's named differently. I guess it's simply "FlxGame update". I guess the general idea is to dig down there and see where most of time is spent. Lots of time spent would mean a bottleneck and supposedly where optimization work should start.

I'm not familiar with TTF/OTF format, or any other font format, but you'd think the glyph mapping table would be included in the font itself?

Anyway iOS has custom font support (since 3.2) which makes it pretty easy to add another font, and use that with UILabel etc. I really never needed to use that. However thinking about this, and that you can create FlxSprite from UIView:s (UILabel is subclass of UIView), it should be more or less easy to create FlxSprites from any ttf/otf (that you also can get working with UILabel, I guess some fonts aren't compatible for other reasons).

I tried this of course. It kind of works, but I ran into some problems with the retina scale (again... always...) that made the FlxSprite render in low res. But it does work, just gotta fix those last bits. If using Canabalt 2x sized graphics it might just work out of the box. Not sure what you need Flixel's font classes for really...

iOS / Re: Retina / high res textures
« on: Tue, Jun 12, 2012 »
I just couldn't read the source of FlxTileblock so I rewrote it from scratch to learn. It works, I can now use tiles of arbitrary resolution (1x, 2x (retina) or whatever). I just couldn't get it to work with graphics loaded from atlases so for now I just add the tile graphics one by one. Not sure if there's any performance boost of using atlases anyway, at least in this case. What I did learn from the original FlxTileblock was to use "stitching" before drawing the first column of any new line which is not the first line.
Uh, and, despite doing all this I haven't really measured any performances differences but at least instead of using hundreds/thousands of FlxSprites in my case I'm just using a few tile blocks that really just draw vertices from an array.
Kind of makes you wonder what makes FlxSprites so slow in the first place...

If anyone's interested I could share this class.

iOS / Re: Dynamic FlxSprite coloring
« on: Mon, Jun 11, 2012 »
You can also try encapsulating glDrawArrays with GL_COLOR_ARRAY...

   glColorPointer(4, GL_UNSIGNED_BYTE, 0, gRectColors);
   glDrawArrays(GL_TRIANGLE_STRIP, 0, vertexCount);

Where gRectColors could look like this

static const GLubyte gRectColors[] =   {
   255, 0, 0, 255, // red?
   0, 255, 0, 255, // g?
   0, 0, 255, 255 // b?

It would allow more different kinds of colorings with nice gradients and stuff.
Now if you look at FlxSprite again you can see that glEnableClientState(GL_COLOR_ARRAY); is already in there, but it seems disabled or only active under some circumstances (_alpha != 1.0 || filled). So should be possible maybe already provided _colors is really used. Not really sure what "filled" and that stuff means yet but if needed I'm sure it wouldn't be too hard to work it out.

iOS / Re: Canabalt's HUD class
« on: Tue, May 22, 2012 »
goshki yes you're on the right track. I finally got around to deal with this. Sure there are texture coords (called UV) but also triangle vertices. They are packed into the same array which is fed to OpenGL in bottom of HUD.m. It's set to draw triangle strips but afaik there is no optimization done thag would make use of the triangle strip way of reducing vertices. I learned all of this from that iTunes U lecture on OpenGL ES and some Q&A on the net.

I was able to write up my own class with similar way of drawing, that also supports retina sized gfx. The big aha for me was that you're only supposed to scale the size of the UV coords, not the triangle sizes. Should make sense after all. I was scaling the wrong stuff first and if something goes wrong there's normally just garbled or no output at all.

iOS / Re: flixel-iOS for native mac games?
« on: Wed, May 16, 2012 »
If you figure it out, you should post how you did it.

For the simulator, I just built the original Canabalt source. Didn't try anything else yet.

iOS / Re: Sound effects
« on: Wed, May 16, 2012 »
I think I found out how I could do it, if I would really need it:

This is Apple's sample app - how to convert sounds. I just tried converting an mp3, then used it inside Flixel and it works. I output a PCM of 44100 hz. There's a function in there called DoConvertFile(), that should pretty much be enough to do this. You would need to convert the sound files when the app launches and put in cache or something like that.

Well, converting mp3s on the fly might be enough in some ways...

iOS / Re: flixel-iOS for native mac games?
« on: Wed, May 16, 2012 »
At the same time games work great in the simulator...
So should be possible.

iOS / Re: Sound effects
« on: Tue, May 15, 2012 »
Ok well it's possible to play multiple sounds using several AVAudioPlayer:s too, for instance. But I tried your fix from another thread and it works, so all is kind of well.  8)
Anyway I guess OA does not support mp3 etc and other compressed formats. I might have to think of a workaround if I'm gonna use lots of sounds... wanna keep app size down...

Pages: [1] 2