PSModalAlert based on Rombos's iPhone class.

PSModalAlert based on Rombos's iPhone class.
0.0 0


I found I needed a modal alert dialog, and I wanted it to be cross-platform.

Rombos had a blog post for a cocos2d-iphone one he did:

It seemed sane, so I spent the morning porting it to cocos2d-x/C*+ — the main difference from his version is that Objective-C has those helpful code-block/anonymous function/lambda thingies that C*+ doesn’t have. [Correct me if I’m wrong!] So instead the C++ version requires SEL_CallFunc functions and targets to call them on.

The code is up on github for anyone that wants to try it:

One thing I don’t like about it, is that it requires images for the dialog background and button backgrounds to be in your project. They’re supplied, and you can replace them with similar sized versions of your color-scheme/art-style, but I kind of wish that was optional.

Let me know if you find any bugs (I’ll be sure to blame them on Rombos :slight_smile: ).

Also let me know if these work on other platforms: I’ve only tried them on iOS.


Hi Philippe Chaintreuil,

Thanks for such a good extension. I’ve just utilized it in my hello world example. It worked nearly in the way I wanted except for a small defect— without effectively swalling the touches events. In detail, when the dialog appears, I can still click the lower-right cocos2d button to exit the window or even click the bottom sprite which can respond to the usual touch event. This is indeed a defect! Expect your further better improvement…



So much code for a dialog?

This article by the MOAI SDK team is great. It’s also true for C++ games.

Avoid writing big systems and data structures.
Only code what you need when you need it.
Favor code re-use through stateless libraries of functions instead of stateful systems and classes.
Use composition, not inheritance.