I’m trying out the cocos2d-iphone javascript bindings so I can more easily port my current project to the web or android platforms when it’s complete. Right now it I’m just using xcode to run the js for ios devices.
I’m trying to figure out if there is a way to detect a retina display in the javascript. My sd/hd images seem to be loading just fine with the standard filename conventions (i.e., image.png and image@2x.png), but I’m having trouble with the BMLabels loading the correct versions of the font files. Checking the screen size returns the same pixel width for retina and non-retina displays, as expected. Normally in obj-c I’d just use CC_CONTENT_SCALE_FACTOR(), but I cannot find an equivalent in the javascript bindings.
I found this SO question/answer, and it’l come in very handy when this project is being viewed via a browser, but it doesn’t solve the ios device problem…
Example:
var label = cc.LabelBMFont.create("0123456789", "EuroBold24.fnt");
vs.
var label = cc.LabelBMFont.create("0123456789", "EuroBold24@2x.fnt");
Both of these work, but I need to know which one to call if the device is a retina enabled device. Any ideas? Thanks.
You shouldn’t use @2x with cocos2d-iphone. Use the custom file extension format using the following suffixes:
The @2x only works with image files, cocos2d’s custom file suffixes work with any supported asset, including bitmap font (.fnt) and tilemap (.tmx) files.