How can I detect inside the code that the user is using an iPad instead of an iPhone, to adjust the positions and loading the right assets?
I was following a book on cocos2d and trying to adapt the code to cocos2d-x, but I haven’t been able to find
a function called UI_USER_INTERFACE_IDIOM() which returns UIUserInterfaceIdiomPad when the user is using an iPad.
So far I’ve been thinking of checking the resolution using the director, but is there a cleaner way to do this?
I think 3 premises is required:
# iOS 3.2 and later SDK
# import “UIDevice.h”
# This marco uses objc syntax, so you need to rename your cpp file using this marco to .mm subfix
I think I found the solution, I just wrote this hope can give anyone who encounter the same problem as me.
The solution is just simple, if you want to migrate the object-c macro into your c*+ files.
You need to change the c*+ file type to “Objective-C*+ source” in “Identity and Type”, and vice versa.
I do this and my 999* errors just gone. It’s a big happy to see these annoying red symbols disappear.
Every file has a file type - .cpp is “C+ source" if you like to use Obj-C stuff you must make the file where you include Obj-C stuff to "Objective-C+” file like mentioned above.
Quick fix: rename your**.cpp file into *.mm
I have another way, and successfully used it in my game to scale content or do other stuff. But it’s kinda hacky, and very manual.
I check the current size (width or height) of the screen of device getting these information via normal CCDirector. You can see here http://haxpor.org/post/18772870651/pong-master-progress.
Sorry to dig up, but just to notify that I’ve tested including a condition checking for iPad 3 resolution but CCDirector::sharedDirector()->getWinSize().width still returns the same 1024.
I’m not sure whether this is not yet support or anything, I tested it via Simulator and set the device to iPad (Retina).
Thanks Wang Jabi, andHerman for suggestion.
I tested getWinSizeInPixels() and getting the scaling factor and do regular check with normal getWinSize(), it all works out. According to this, I found a fatal flaw in my code. Thanks for pointing me out !