void GafFeatures::onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *unused_event) { if (!m_objects || !m_objects->count()) { return; } GAFObject * node = (GAFObject*)m_objects->getObjectAtIndex(0); cocos2d::Touch * pTouch = touches[0]; cocos2d::Point pt = pTouch->getLocation(); node->setPosition(pt.x, pt.y); }
void GafFeatures::addObjectsToScene() { using namespace std::placeholders; if (!m_asset) { StartCounter(); m_asset = GAFAsset::create(m_files[m_anim_index], nullptr); double loadingTime = GetCounter(); cocos2d::log("Loading time [%f]\n", loadingTime); std::ostringstream ss; ss << m_files[m_anim_index] << " "; ss << loadingTime; //m_loadingTimeLabel->setString(ss.str().c_str()); ss.str(""); ss << "VRAM: "; ss << m_asset->getTextureManager()->getMemoryConsumptionStat(); ss << " bytes"; m_vramStat->setString(ss.str()); CC_SAFE_RETAIN(m_asset); } if (!m_objects) { m_objects = cocos2d::__Array::create(); m_objects->retain(); } const cocos2d::Size size = cocos2d::Director::getInstance()->getWinSizeInPixels(); if (m_asset) { GAFObject *object = m_asset->createObject(); object->setLocalZOrder(0); addChild(object); float scaleFactor = cocos2d::Director::getInstance()->getContentScaleFactor(); object->setAnchorPoint(cocos2d::Vec2(0.5, 0.5)); object->setPosition(centerScreenPosition(size / scaleFactor)); object->setLocator(true); m_objects->addObject(object); m_objectSequencesNames.clear(); #if CC_TARGET_PLATFORM == CC_PLATFORM_IOS CocosDenshion::SimpleAudioEngine::getInstance()->stopAllEffects(); for(auto& effect : m_musicEffects) { CocosDenshion::SimpleAudioEngine::getInstance()->unloadEffect(effect.second.c_str()); } #endif m_musicEffects.clear(); const AnimationSequences_t& secDictionary = m_asset->getRootTimeline()->getAnimationSequences(); // TODO: only root timeline (temporary workaround) if (!secDictionary.empty()) { for (AnimationSequences_t::const_iterator i = secDictionary.begin(), e = secDictionary.end(); i != e; ++i) { const std::string& seqName = i->first; std::string::size_type pos = seqName.find("__audio:"); if (pos != std::string::npos) { std::string effectName = seqName.substr(pos + 8) + ".wav"; #if CC_TARGET_PLATFORM == CC_PLATFORM_IOS CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect(effectName.c_str()); #endif m_musicEffects[i->second.startFrameNo] = std::move(effectName); } else { m_objectSequencesNames.push_back(i->first); } } } enableSequenceControllers(!m_objectSequencesNames.empty()); // will work only if animation has a sequence object->playSequence("walk", true); object->setLooped(true, true); object->start(); object->setSequenceDelegate(std::bind(&GafFeatures::onFinishSequence, this, _1, _2)); object->setFramePlayedDelegate(std::bind(&GafFeatures::onFramePlayed, this, _1, _2)); } }