bool AppDelegate::applicationDidFinishLaunching() { log("cocos version: %s", cocos2dVersion()); // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { glview = GLViewImpl::create("My Game"); director->setOpenGLView(glview); } // turn on display FPS director->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this director->setAnimationInterval(1.0 / 60); // create a scene. it's an autorelease object auto scene = TitleScene::createScene(); // run director->runWithScene(scene); return true; }
bool Configuration::init() { _valueDict["cocos2d.x.version"] = Value(cocos2dVersion()); #if CC_ENABLE_PROFILERS _valueDict["cocos2d.x.compiled_with_profiler"] = Value(true); #else _valueDict["cocos2d.x.compiled_with_profiler"] = Value(false); #endif #if CC_ENABLE_GL_STATE_CACHE == 0 _valueDict["cocos2d.x.compiled_with_gl_state_cache"] = Value(false); #else _valueDict["cocos2d.x.compiled_with_gl_state_cache"] = Value(true); #endif #if COCOS2D_DEBUG _valueDict["cocos2d.x.build_type"] = Value("DEBUG"); #else _valueDict["cocos2d.x.build_type"] = Value("RELEASE"); #endif return true; }
bool CCDirector::init(void) { CCLOG("cocos2d: %s", cocos2dVersion()); // scenes m_pRunningScene = NULL; m_pNextScene = NULL; m_pNotificationNode = NULL; m_dOldAnimationInterval = m_dAnimationInterval = 1.0 / kDefaultFPS; m_pobScenesStack = new CCArray(); // Set default projection (3D) m_eProjection = kCCDirectorProjectionDefault; // projection delegate if "Custom" projection is used m_pProjectionDelegate = NULL; // FPS m_bDisplayStats = false; m_uTotalFrames = m_uFrames = 0; m_pszFPS = new char[10]; m_pLastUpdate = new struct cc_timeval(); // paused ? m_bPaused = false; // purge ? m_bPurgeDirecotorInNextLoop = false; m_obWinSizeInPixels = m_obWinSizeInPoints = CCSizeZero; // portrait mode default m_eDeviceOrientation = CCDeviceOrientationPortrait; m_pobOpenGLView = NULL; m_bRetinaDisplay = false; m_fContentScaleFactor = 1; m_bIsContentScaleSupported = false; // scheduler m_pScheduler = new CCScheduler(); // action manager m_pActionManager = new CCActionManager(); m_pScheduler->scheduleUpdateForTarget(m_pActionManager, kCCPrioritySystem, false); // touchDispatcher m_pTouchDispatcher = new CCTouchDispatcher(); m_pTouchDispatcher->init(); // create autorelease pool CCPoolManager::sharedPoolManager()->push(); return true; }
bool CCDirector::init(void) { CCLOG("cocos2d: %s", cocos2dVersion()); CCLOG("cocos2d: Using Director Type: CCDirectorDisplayLink"); // scenes m_pRunningScene = NULL; m_pNextScene = NULL; m_pNotificationNode = NULL; m_dOldAnimationInterval = m_dAnimationInterval = 1.0 / kDefaultFPS; m_pobScenesStack = new CCMutableArray<CCScene*>(); // Set default projection (3D) m_eProjection = kCCDirectorProjectionDefault; // projection delegate if "Custom" projection is used m_pProjectionDelegate = NULL; // FPS m_bDisplayFPS = false; m_nFrames = 0; m_pszFPS = new char[10]; m_pLastUpdate = new struct cc_timeval(); // paused ? m_bPaused = false; // purge ? m_bPurgeDirecotorInNextLoop = false; m_obWinSizeInPixels = m_obWinSizeInPoints = CCSizeZero; // default values m_ePixelFormat = kCCPixelFormatDefault; m_eDepthBufferFormat = kCCDepthBufferNone; // 0 // portrait mode default m_eDeviceOrientation = CCDeviceOrientationPortrait; m_pobOpenGLView = NULL; m_bRetinaDisplay = false; m_fContentScaleFactor = 1; m_bIsContentScaleSupported = false; // create autorelease pool CCPoolManager::getInstance()->push(); return true; }
bool ClickedMe(const EventMouse* event, const Node *node) { auto rect = node->getBoundingBox(); Vec2 click; if (std::string(cocos2dVersion()) == "cocos2d-x 3.5") { // Maybe a bug in cocos2d-x 3.4 - https://github.com/cocos2d/cocos2d-x/issues/8536 auto dir = Director::getInstance(); click = dir->convertToGL(Vec2( event->getLocation().x, event->getLocation().y - Director::getInstance()->getVisibleSize().height) ); } else { click = event->getLocation(); } return rect.containsPoint(click); }
// // NOTE: track event on windows / mac platform // void RuntimeEngine::trackEvent(const std::string &eventName) { if (!_eventTrackingEnable) { return ; } #if ((CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)) #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) const char *platform = "win"; #elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) const char *platform = "mac"; #else const char *platform = "UNKNOWN"; #endif char cidBuf[64] = {0}; auto guid = player::DeviceEx::getInstance()->getUserGUID(); snprintf(cidBuf, sizeof(cidBuf), "%x", XXH32(guid.c_str(), (int)guid.length(), 0)); auto request = extra::HTTPRequest::createWithUrl(NULL, "http://www.google-analytics.com/collect", kCCHTTPRequestMethodPOST); request->addPOSTValue("v", "1"); request->addPOSTValue("tid", "UA-58200293-1"); request->addPOSTValue("cid", cidBuf); request->addPOSTValue("t", "event"); request->addPOSTValue("an", "simulator"); request->addPOSTValue("av", cocos2dVersion()); request->addPOSTValue("ec", platform); request->addPOSTValue("ea", eventName.c_str()); request->start(); #endif // ((CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)) }
void jsb_register_cocos2d_config( JSContext *_cx, JSObject *cocos2d) { // Config Object JSObject *ccconfig = JS_NewObject(_cx, NULL, NULL, NULL); // config.os: The Operating system // osx, ios, android, windows, linux, etc.. #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) JSString *str = JS_InternString(_cx, "ios"); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) JSString *str = JS_InternString(_cx, "android"); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) JSString *str = JS_InternString(_cx, "windows"); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE) JSString *str = JS_InternString(_cx, "marmalade"); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) JSString *str = JS_InternString(_cx, "linux"); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_BADA) JSString *str = JS_InternString(_cx, "bada"); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY) JSString *str = JS_InternString(_cx, "blackberry"); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) JSString *str = JS_InternString(_cx, "osx"); #else JSString *str = JS_InternString(_cx, "unknown"); #endif JS_DefineProperty(_cx, ccconfig, "os", STRING_TO_JSVAL(str), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); // config.deviceType: Device Type // 'mobile' for any kind of mobile devices, 'desktop' for PCs, 'browser' for Web Browsers // #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) // str = JS_InternString(_cx, "desktop"); // #else str = JS_InternString(_cx, "mobile"); // #endif JS_DefineProperty(_cx, ccconfig, "platform", STRING_TO_JSVAL(str), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); // config.engine: Type of renderer // 'cocos2d', 'cocos2d-x', 'cocos2d-html5/canvas', 'cocos2d-html5/webgl', etc.. str = JS_InternString(_cx, "cocos2d-x"); JS_DefineProperty(_cx, ccconfig, "engine", STRING_TO_JSVAL(str), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); // config.arch: CPU Architecture // i386, ARM, x86_64, web #ifdef __LP64__ str = JS_InternString(_cx, "x86_64"); #elif defined(__arm__) || defined(__ARM_NEON__) str = JS_InternString(_cx, "arm"); #else str = JS_InternString(_cx, "i386"); #endif JS_DefineProperty(_cx, ccconfig, "arch", STRING_TO_JSVAL(str), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); // config.version: Version of cocos2d + renderer str = JS_InternString(_cx, cocos2dVersion() ); JS_DefineProperty(_cx, ccconfig, "version", STRING_TO_JSVAL(str), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); // config.usesTypedArrays #if JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES JSBool b = JS_FALSE; #else JSBool b = JS_TRUE; #endif JS_DefineProperty(_cx, ccconfig, "usesTypedArrays", BOOLEAN_TO_JSVAL(b), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); // config.debug: Debug build ? #if COCOS2D_DEBUG > 0 b = JS_TRUE; #else b = JS_FALSE; #endif JS_DefineProperty(_cx, ccconfig, "debug", BOOLEAN_TO_JSVAL(b), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); // Add "config" to "cc" JS_DefineProperty(_cx, cocos2d, "config", OBJECT_TO_JSVAL(ccconfig), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); }