NS_CC_EXT_BEGIN #define SCROLL_DEACCEL_RATE 0.95f #define SCROLL_DEACCEL_DIST 1.0f #define BOUNCE_DURATION 0.15f #define INSET_RATIO 0.2f #define MOVE_INCH 7.0f/160.0f #define BOUNCE_BACK_FACTOR 0.35f static float convertDistanceFromPointToInch(float pointDis) { auto glview = Director::getInstance()->getOpenGLView(); float factor = ( glview->getScaleX() + glview->getScaleY() ) / 2; return pointDis * factor / Device::getDPI(); }
float UIWidget::getAbsoluteScaleX() { if (m_bScaleXDirty) { float scaleX = getScaleX(); UIWidget* parent = getWidgetParent(); while (parent) { scaleX *= parent->getScaleX(); parent = parent->getWidgetParent(); } m_fAbsoluteScaleX = scaleX; m_bScaleXDirty = false; } return m_fAbsoluteScaleX; }
void Plane::update(float dt) { setPositionX(getPositionX()+speedX); if (getScaleX()>0) { if (getPositionX()<-getContentSize().width) { unscheduleUpdate(); planes->removeObject(this); getParent()->removeChild(this); } } else { if (getPositionX()>visibleSize.width+getContentSize().width) { unscheduleUpdate(); planes->removeObject(this); getParent()->removeChild(this); } } }
START_GAME_NS // PATCH - sprite from csb file use content scale factor void fixSpriteContentScale(Node* parentNode) { auto childrenNodes = parentNode->getChildren(); for (auto it = childrenNodes.begin(); it != childrenNodes.end(); it++) { auto childNode = *it; if (dynamic_cast<Sprite*>(childNode) != NULL) { auto sprite = dynamic_cast<Sprite*>(childNode); sprite->setScale(sprite->getScaleX() * Director::getInstance()->getContentScaleFactor(), sprite->getScaleY() * Director::getInstance()->getContentScaleFactor()); } fixSpriteContentScale(childNode); } }
NS_CC_WIDGET_BEGIN #define CSCORLLVIEW_RELOCATE_DURATION 0.2f #define CSCROLLVIEW_DEACCELERATE_VA 2000.0f #define CSCROLLVIEW_DEACCELERATE_MAX 400.0f #define CSCROLLVIEW_DEACCELERATE_INTERVAL 0.245f #define CSCROLLVIEW_DEACCELERATE_PERCENTAGE 0.955f #define CSCROLLVIEW_MOVE_INCH 7.0f/160.0f #define CSCROLLVIEW_MOVE_ACTION_TAG 1 #define CSCROLLVIEW_MOVE_EASEIN_RATE 0.5f float ccScrollconvertPointToInch(float pointDis) { auto glView = Director::getInstance()->getOpenGLView(); float factor = ( glView->getScaleX() + glView->getScaleY() ) / 2; return pointDis * factor / Device::getDPI(); }
void WebViewImpl::draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags) { if (flags & cocos2d::Node::FLAGS_TRANSFORM_DIRTY) { auto directorInstance = cocos2d::Director::getInstance(); auto glView = directorInstance->getOpenGLView(); auto frameSize = glView->getFrameSize(); auto winSize = directorInstance->getWinSize(); auto leftBottom = this->_webView->convertToWorldSpace(cocos2d::Point::ZERO); auto rightTop = this->_webView->convertToWorldSpace(cocos2d::Point(this->_webView->getContentSize().width,this->_webView->getContentSize().height)); auto uiLeft = frameSize.width / 2 + (leftBottom.x - winSize.width / 2 ) * glView->getScaleX(); auto uiTop = frameSize.height /2 - (rightTop.y - winSize.height / 2) * glView->getScaleY(); setWebViewRectJNI(_viewTag,uiLeft,uiTop, (rightTop.x - leftBottom.x) * glView->getScaleX(), (rightTop.y - leftBottom.y) * glView->getScaleY()); } }
void ClipNode::visit( Renderer *pRenderer, const Mat4& parentTransform, uint32_t parentFlags ) { glEnable( GL_SCISSOR_TEST ); const float fScaleX = getScaleX(); const float fScaleY = getScaleY(); Point worldPosition = getPosition(); if ( getParent() ) { worldPosition = getParent()->convertToWorldSpace( worldPosition ); } Director::getInstance()->getOpenGLView()->setScissorInPoints( worldPosition.x - _gg_ClipSize.width * fScaleX * _gg_ClipAnchor.x, worldPosition.y - _gg_ClipSize.height * fScaleY * _gg_ClipAnchor.y, _gg_ClipSize.width * fScaleX, _gg_ClipSize.height * fScaleY ); Node::visit( pRenderer, parentTransform, parentFlags ); glDisable( GL_SCISSOR_TEST ); }
void WebViewImpl::draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, int flags) { if (flags & cocos2d::Node::FLAGS_TRANSFORM_DIRTY) { auto directorInstance = cocos2d::Director::getInstance(); auto glView = directorInstance->getOpenGLView(); auto frameSize = glView->getFrameSize(); auto winSize = directorInstance->getWinSize(); auto leftBottom = this->_webView->convertToWorldSpace(cocos2d::Point::ZERO); auto rightTop = this->_webView->convertToWorldSpace(cocos2d::Point(this->_webView->getContentSize().width,this->_webView->getContentSize().height)); auto uiLeft = frameSize.width / 2 + (leftBottom.x - winSize.width / 2 ) * glView->getScaleX(); auto uiTop = frameSize.height /2 - (rightTop.y - winSize.height / 2) * glView->getScaleY(); Evas_Coord width = (rightTop.x - leftBottom.x) * glView->getScaleX(); Evas_Coord height = (rightTop.y - leftBottom.y) * glView->getScaleY(); evas_object_resize(_ewkView, width, height); evas_object_move(_ewkView, uiLeft, uiTop); evas_object_show(_ewkView); } }
void DebugActor::doUpdate(const UpdateState &us) { static int fps = 0; ++_frames; if (_frames > 50) { timeMS this_time = getTimeMS(); if (this_time != _startTime) { fps = int(((float)_frames/(this_time - _startTime))*1000); } _startTime = this_time; _frames = 0; } int mem_used = -1; int mem_free = -1; #ifdef __S3E__ mem_used = s3eMemoryGetInt(S3E_MEMORY_USED); mem_free = s3eMemoryGetInt(S3E_MEMORY_FREE); #endif stringstream s; s << "fps=" << fps << " mem=" << mem_used << endl; s << "mfree=" << mem_free << endl; #ifdef OXYGINE_DEBUG_TRACE_LEAKS s << "objects=" << (int)ObjectBase::__getCreatedObjects().size() << endl; #endif s << "batches="<< _videoStats.batches << " triangles=" << _videoStats.triangles << endl; s << "update=" << getRoot()->_statUpdate << "ms "; s << "render=" << getRoot()->_statRender << "ms "; s << "textures=" << NativeTexture::created << " "; s << "\nlisteners=" << getRoot()->getListenersCount() << ""; s << "\n"; s << _debugText; _debugText = ""; _text->setText(s.str()); setHeight(_text->getTextRect().size.y + 2.0f); _bg->setSize(getSize()); float scale = getScaleX(); Vector2 parentSize = getParent()->getSize(); Vector2 realSize = getSize() * scale; setX(0); setY(0); switch(_corner) { case 1: setX(parentSize.x - realSize.x); setY(0); break; case 2: setPosition(parentSize - realSize); break; case 3: setX(0); setY(parentSize.y - realSize.y); break; } }
bool GallaryList::init() { if (!Layer::init()) { return false; } visibleSize = Director::getInstance()->getVisibleSize(); thumbWidth = visibleSize.width/4; thumbSpace = visibleSize.width/3.5; currentThumb = 0; isClick = false; GallaryLayer::setGallaryState(0, true); GallaryLayer::setGallaryState(1, true); GallaryLayer::setGallaryState(3, true); GallaryLayer::setGallaryState(4, true); GallaryLayer::setGallaryState(5, true); GallaryLayer::setGallaryState(9, true); for (int i = 0; i != picCount; ++i) { char name[30]; sprintf(name, "gallary/gallary%d.png", i); auto listItem = Sprite::create(name); this->addChild(listItem); thumbs.push_back(listItem); listItem->setScale(thumbWidth/listItem->getContentSize().width, visibleSize.height/listItem->getContentSize().height/4); listItem->setPosition(Vec2(visibleSize.width/2+thumbSpace*i, 0)); if (!GallaryLayer::getGallaryState(i)) { listItem->setOpacity(100); } auto itemFrame = Sprite::create("frame/Data-Pic.png"); // TODO: need to be change this->addChild(itemFrame, -1); itemFrame->setPosition(Vec2(visibleSize.width/2+thumbSpace*i, 0)); itemFrame->setAnchorPoint(Point(0.5, 0.5)); itemFrame->setScale(thumbWidth/itemFrame->getContentSize().width*1.03, visibleSize.height/itemFrame->getContentSize().height/4*1.05); touchListener = EventListenerTouchOneByOne::create(); touchListener->setSwallowTouches(true); touchListener->onTouchBegan = [&, listItem](Touch *touch, Event *event) { isClick = true; event->getCurrentTarget()->stopActionByTag(tag_loadPic); startPoint = touch->getLocation(); movePoint = startPoint; // touch on list auto locationInNode = listItem->convertToNodeSpace(touch->getLocation()); auto rect = cocos2d::Rect(0, 0, listItem->getContentSize().width, listItem->getContentSize().height); if (rect.containsPoint(locationInNode)) { touchListener->setSwallowTouches(true); return true; } // touch on pic auto displayPic = static_cast<GallaryContent*>(this->getParent())->getDisplayPic(); auto locationInNode2 = displayPic->convertToNodeSpace(touch->getLocation()); auto rect2 = cocos2d::Rect(0, 0, displayPic->getContentSize().width*displayPic->getScaleX(), displayPic->getContentSize().height*displayPic->getScaleY()); if (rect2.containsPoint(locationInNode2)) { touchListener->setSwallowTouches(true); return true; } return false; }; touchListener ->onTouchMoved = [&](Touch *touch, Event *event) { auto currentPoint = touch->getLocation(); this->setPositionX(this->getPositionX() + currentPoint.x - movePoint.x); if (currentPoint.x - movePoint.x > 50 || currentPoint.x - movePoint.x < 100) { isClick = false; } movePoint = currentPoint; return true; }; touchListener->onTouchEnded = [&](Touch *touch, Event *event) { touchListener->setSwallowTouches(false); auto target = static_cast<GallaryList*>(event->getCurrentTarget()); currentThumb = static_cast<int>((event->getCurrentTarget()->getPositionX()-thumbSpace/2)/thumbSpace); // log("posx: %d", currentThumb); if (-currentThumb >= picCount) { currentThumb = -picCount + 1; } if (isClick) { auto displayPic = static_cast<GallaryContent*>(this->getParent())->getDisplayPic(); auto locationInNode = displayPic->convertToNodeSpace(touch->getLocation()); auto rect = cocos2d::Rect(0, 0, displayPic->getContentSize().width*displayPic->getScaleX(), displayPic->getContentSize().height*displayPic->getScaleY()); // open display mode if (rect.containsPoint(locationInNode) && GallaryLayer::getGallaryState(-currentThumb)) { // target->onPicClick(-currentThumb); this->onPicClick(-currentThumb); } } else { if (currentThumb >= 0) { target->runAction(MoveTo::create(0.2, Vec2(0, target->getPositionY()))); } else if (currentThumb < -picCount+1) { target->runAction(MoveTo::create(0.2, Vec2(thumbSpace*(-picCount+1), target->getPositionY()))); } else { target->runAction(MoveTo::create(0.2, Vec2(thumbSpace*currentThumb, target->getPositionY()))); } // target->thumbs.at(-currentThumb)->runAction(); // change pic target->onPicChange(-currentThumb); } return true; }; _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this); } return true; }
void UILabel::setTouchScaleChangeEnabled(bool enable) { _touchScaleChangeEnabled = enable; _normalScaleValueX = getScaleX(); _normalScaleValueY = getScaleY(); }
void Sprite2d::setHeight(const float& h){ setScale(getScaleX() , h/m_Sprite->getLocalBounds().height); }
/** @brief タッチリスナーの設定 @param[in] なし @return なし */ void RelayGameLayer::_SetTouchListener() { // シングルタッチイベントリスナー作成 //auto listener1 = EventListenerTouchOneByOne::create(); // マルチタッチリスナー auto multiListener1 = EventListenerTouchAllAtOnce::create(); auto dispatcher = this->getEventDispatcher(); //listener1->setSwallowTouches(true); multiListener1->setEnabled(true); multiListener1->onTouchesBegan = ([&, this](const std::vector<Touch*>& touches, Event* event)->void { m_touchNum++; log("Began m_touchNum:%d", m_touchNum); if (m_isAnimation) return;// false; // 最初のタッチのみ if (m_touchNum > 1) return; auto touch = touches.front(); switch (m_flowPhase) { case RelayGameLayer::FlowPhase::CHECK: // 自分の順番を表示 { // テーマ表示 auto board = this->getChildByName<Sprite*>("BigBoard"); auto top = board->getChildByName<Label*>("TopLabel"); auto bottom = board->getChildByName<Label*>("BottomLabel"); // ボード表示 board->setVisible(true); std::stringstream ss; if (m_drawOrder[m_nowDrawer] == m_playerNum) { // 解答者 top->setString("あなたが"); ss << "最後に解答してください"; } else { top->setString("あなたは"); ss << m_drawOrder[m_nowDrawer] << "番目に描いてください"; } m_pMiddleLabel->setString(ss.str()); if (++m_nowDrawer == m_playerNum) { // 最後の人 m_flowPhase = FlowPhase::HIDE; //ss << "確認したらタッチしてテーマを見た順に、描き始めてください"; bottom->setString("確認したらタッチして1番目の人に渡してください\n次はテーマ発表です"); } else { // まだ他に見る人がいる std::stringstream next; next << "次(" << (m_nowDrawer + 1) << "人目)の人がタッチしてください。"; bottom->setString(next.str()); } } break; case RelayGameLayer::FlowPhase::HIDE: { m_flowPhase = FlowPhase::THEME; auto board = this->getChildByName("BigBoard"); auto top = board->getChildByName<Label*>("TopLabel"); auto bottom = board->getChildByName<Label*>("BottomLabel"); top->setString("テーマ発表です。周りの人に見られないように"); m_pMiddleLabel->setString(""); bottom->setString("画面をタッチしてください"); } break; case RelayGameLayer::FlowPhase::THEME: { m_flowPhase = FlowPhase::START; // テーマ表示 this->_ShowTheme(); } break; case RelayGameLayer::FlowPhase::START: { // お絵かき開始 this->_StartDrawing(); } break; case RelayGameLayer::FlowPhase::PLAY: // お絵かき中 { // メインフェーズ switch (m_phase) { case RelayGameLayer::Phase::ANNOUNCE: //return false; break; case RelayGameLayer::Phase::DRAWING: { auto canvas = this->getChildByName<LayerCanvas*>("Canvas"); auto target = event->getCurrentTarget(); Point locationInNode = target->convertToNodeSpace(touch->getLocation()); //* //Size s = target->getContentSize(); //Rect rect = Rect(0, 0, s.width, s.height); Size s = canvas->getContentSize(); s.width *= canvas->getScaleX(); s.height *= canvas->getScaleY(); Rect rect(canvas->getPositionX() - canvas->getAnchorPoint().x*s.width, canvas->getPositionY() - canvas->getAnchorPoint().y*s.height, s.width, s.height); // キャンバス内なら if (rect.containsPoint(locationInNode)) //*/ { // 時間計測停止 m_isCounting = true; // 点打ち始め size_t i = m_touchPoints[m_nowPage].size(); for (; i <= m_nowLine; ++i) { m_touchPoints[m_nowPage].push_back(points()); } m_touchPoints[m_nowPage][m_nowLine].push_back(locationInNode); // 描いた m_isDrew = true; } else { // 描かなかった m_isDrew = false; break; } } break; case RelayGameLayer::Phase::CONFIRM: //return false; break; default: break; } } break; case RelayGameLayer::FlowPhase::SHOW: // ひとり前の絵を見ている { // 次のキャンバスへ this->_NextCanvas(); // フェーズ戻し m_flowPhase = FlowPhase::PLAY; // 時間初期化 m_oneDrawTime = 0.f; this->_UpdateTimeLabel(); } break; //case RelayGameLayer::FlowPhase::JUDGE: // // 画伯発表と正誤発表 //{ //} // break; case RelayGameLayer::FlowPhase::REPEAT: // 再プレイ? { } break; default: break; } //return true; }); // タッチが移動した場合 multiListener1->onTouchesMoved = [&](const std::vector<Touch*>& touches, Event* event) { log("Move m_touchNum:%d", m_touchNum); // 最初のタッチのみ if (m_touchNum > 1) return; if (m_isAnimation) return; // おっきなふぇーず if (m_flowPhase != FlowPhase::PLAY) return; // メインフェーズ if (m_phase != Phase::DRAWING) return; // 描きすぎ if (ONE_DRAW_TIME <= m_oneDrawTime) return; auto touch = touches.front(); auto target = event->getCurrentTarget(); Point locationInNode = target->convertToNodeSpace(touch->getLocation()); auto canvas = this->getChildByName("Canvas"); Size s = canvas->getContentSize(); s.width *= canvas->getScaleX(); s.height *= canvas->getScaleY(); Rect rect(canvas->getPositionX() - canvas->getAnchorPoint().x*s.width, canvas->getPositionY() - canvas->getAnchorPoint().y*s.height, s.width, s.height); if (rect.containsPoint(locationInNode)) { if (m_touchPoints.size() >= m_nowPage && m_touchPoints[m_nowPage].size() > m_nowLine) { m_touchPoints[m_nowPage][m_nowLine].push_back(locationInNode); } } }; multiListener1->onTouchesEnded = [&](const std::vector<Touch*>& touches, Event* event) { m_touchNum--; log("Ended m_touchNum:%d", m_touchNum); // おっきなふぇーず if (m_flowPhase != FlowPhase::PLAY) return; // メインフェーズ if (m_phase != Phase::DRAWING) return; if (!m_isDrew) return; // 最初のタッチのみ if (m_touchNum > 0) return; //this->getChildByName("OverTouchLayer")->setVisible(false); // タッチしてない時間初期化 m_nonTouchTime = 0.f; // 次の線へ ++m_nowLine; }; //dispatcher->addEventListenerWithSceneGraphPriority(listener1, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(multiListener1, this); //_eventDispatcher->addEventListenerWithFixedPriority(listener1, 1); }
void UILabel::setTouchScaleChangeEnabled(bool enable) { m_bTouchScaleChangeEnabled = enable; m_fNormalScaleValueX = getScaleX(); m_fNormalScaleValueY = getScaleY(); }
void EditBoxImplAndroid::setNativeFont(const char* pFontName, int fontSize) { auto director = cocos2d::Director::getInstance(); auto glView = director->getOpenGLView(); setFontEditBoxJNI(_editBoxIndex, pFontName, fontSize * glView->getScaleX()); }
void UI::createIngameUI() { m_pIngame->removeAllChildren(); m_playerMuni = nullptr; Size visibleSize = Director::getInstance()->getVisibleSize(); //################################################ m_pPlayer = pHelloWorld->getPlayer(); lastLife = m_pPlayer->getHealth(); m_pPlayerLife = new Sprite*[3]; for (int i = 0; i < 3; ++i) { std::string str = std::string("Resources/GUI/life"); str.append(std::to_string(i + 1)); str.append(".png"); m_pPlayerLife[i] = Sprite::create(str); m_pPlayerLife[i]->setPosition( 135.0f + m_pPlayerLife[i]->getContentSize().width * 0.5f, 95.0f + m_pPlayerLife[i]->getContentSize().height * 0.5f); m_pPlayerLife[i]->setVisible((lastLife - 1) == i); m_pIngame->addChild(m_pPlayerLife[i], 2); } lastCrystal = CollectibleCrystal::getCrystalCount(); m_pCrystals = new Sprite*[4]; for (int i = 0; i < 4; ++i) { std::string str = std::string("Resources/GUI/"); str.append(std::to_string(i + 1)); str.append(".png"); m_pCrystals[i] = Sprite::create(str); m_pCrystals[i]->setPosition( 202.0f + m_pCrystals[i]->getContentSize().width * 0.5f, 42.0f + m_pCrystals[i]->getContentSize().height * 0.5f); m_pCrystals[i]->setVisible((lastCrystal - 1) == i); m_pIngame->addChild(m_pCrystals[i], 2); } m_polle = Sprite::create("Resources/GUI/holybell.png"); m_polle->setPosition(270.0f, 66.0f); m_polle->setVisible(lastCrystal > 0); m_crystal = Sprite::create("Resources/GUI/crystall.png"); m_crystal->setPosition(175.0f, 61.0f); m_crystal->setVisible(lastCrystal > 0); m_pGameOver = LabelTTF::create("GAME OVER", "Resources/fonts/Comic Book.ttf", 64); m_pGameOver->setPosition(visibleSize.width * 0.5f, visibleSize.height * 0.5f); m_pGameOver->setVisible(false); lastMuni = m_pPlayer->getNuts(); createMuniLabel(); Sprite* bg = Sprite::create("Resources/GUI/bg.png"); bg->setPosition( 5 + bg->getContentSize().width * 0.5f, 5 + bg->getContentSize().height *0.5f); m_pIngame->addChild(m_polle, 2); m_pIngame->addChild(m_crystal, 2); m_pIngame->addChild(bg, 1); //################################################ auto closeItem = MenuItemImage::create( "Resources/pictures/generic/CloseNormal.png", "Resources/pictures/generic/CloseSelected.png", CC_CALLBACK_1(MainLayer::menuCloseCallback, pHelloWorld)); closeItem->setScale(2.0f); closeItem->setPosition( visibleSize.width - closeItem->getScaleX() * closeItem->getContentSize().width * 0.5f, closeItem->getScaleY() * closeItem->getContentSize().height * 0.5f); // create menu, it's an autorelease object auto menu = Menu::create(closeItem, NULL); menu->setPosition(Point::ZERO); m_pIngame->addChild(menu, 1); m_pIngame->addChild(m_pGameOver, 9999); }
void FightLayer::initCard(){ auto fightBackground = Sprite::create("textures/IMG_Background/fight_background.png"); auto cs = fightBackground->getContentSize(); _bgSize = cs; _nFight = LayerColor::create(Color4B(255,0,0,0),cs.width,cs.height); _nFight->setAnchorPoint(Point(0.5,0)); _animalNode = Node::create(); auto p = VisibleRect::topRight()-Point(cs.width,cs.height); _nFight->setPosition(p.x/2,p.y/2); _animalNode->setPosition(Point(cs.width/2,cs.height/2)+Point(p.x/2,p.y/2)); addChild(_nFight); addChild(_animalNode); auto node = Node::create(); node->setPosition(cs.width/2,cs.height/2); node->addChild(fightBackground); _nFight->addChild(node); for(auto id=0;id<_myVec.size();id++){ auto myCard = _myVec.at(id); auto scale = myCard->getScaleX(); node->addChild(myCard); auto myAn = myCard->getAnimal()->getThisLayer(); auto dcp = myCard->getPosition(); auto dp = myAn->getPosition(); auto np = dcp + Point(0, dp.y*scale); auto nd = Node::create(); myAn->setScale(scale); myAn->setPosition(myAn->getPosition().x,0); nd->addChild(myAn); updatePoint(nd, np); _animalNode->addChild(nd); } for(auto ic = 0;ic<_monsterVec.size();ic++){ auto msCard = _monsterVec.at(ic); auto cScale = msCard->getScaleX(); node->addChild(msCard); auto msAn = msCard->getAnimal()->getThisLayer(); auto cDcp = msCard->getPosition(); auto cDp = msAn->getPosition(); auto dNp = cDcp+Point(0,cDp.y*cScale); auto cNd = Node::create(); msAn->setScale(cScale); msAn->setPosition(msAn->getPositionX(),0); cNd->addChild(msAn); updatePoint(cNd, dNp); _animalNode->addChild(cNd); } }
void InteractiveBlock::updateDistanceFromPlayer() { auto blockAsset = dynamic_cast<LHAsset*>(this->getParent()); if (blockAsset) { b2Body* body = this->getBox2dBody(); b2Vec2 playerBodyPosition = _player->getBox2dBody()->GetPosition(); b2Vec2 blockBodyPosition = body->GetPosition(); b2Vec2 distanceBodyVector = blockBodyPosition - playerBodyPosition; const float kPixelsPerMeter = PTM_RATIO; float widthFactor = ((_player->getContentSize().width * fabs(_player->getScaleX())) / 2) + ((blockAsset->getContentSize().width * fabs(blockAsset->getScaleX())) / 2); float heightFactor = ((_player->getContentSize().height * fabs(_player->getScaleY())) / 2) + ((blockAsset->getContentSize().height * fabs(blockAsset->getScaleY())) / 2); widthFactor /= kPixelsPerMeter; heightFactor /= kPixelsPerMeter; if ((fabs(distanceBodyVector.x) > (widthFactor + 0.1f + fabs(sin(body->GetAngle())))) || ((fabs(distanceBodyVector.y) > heightFactor) && fabs(sin(body->GetAngle())) < .1f )) { float horizontalVelocity = body->GetLinearVelocity().x; if (fabs(horizontalVelocity) > 0.1f) { Utility::setDensity(this, 1.0f); body->SetGravityScale(10.0f); if (_player->getIsPushingLeft()) { _player->setPushingSide(-1.0f, false); } else if (_player->getIsPushingRight()) { _player->setPushingSide(1.0, false); } } } } }
void GameMap::updateView() { Point posView = gHero->getPosition()+Point(0,85.f); Rect rect; Size viewSize = gDirector->getVisibleSize(); Point viewOrigin = gDirector->getVisibleOrigin(); Point offsetLD; Point offsetRU; rect.setRect(viewOrigin.x+m_viewPoint.x+offsetLD.x,viewOrigin.y+m_viewPoint.y+offsetLD.y,(viewSize.width+offsetRU.x)/getScaleX(),(viewSize.height+offsetRU.y)/getScaleY()); Point posMin = Point(rect.getMaxX()-rect.getMidX(),rect.getMaxY()-rect.getMidY()); Point posMax = Point(GetMaxViewX()+rect.getMaxX()-rect.getMidX(),GetMaxViewY()+rect.getMaxY()-rect.getMidY()); // 限制地图出屏 if( posView.x<posMin.x ) posView.x = posMin.x; if( posView.x>posMax.x ) posView.x = posMax.x; if( posView.y<posMin.y ) posView.y = posMin.y; if( posView.y>posMax.y ) posView.y = posMax.y; SetView(posView); }
float Sprite2d::getWidth() const{return (m_Sprite->getLocalBounds().width*getScaleX());}
int32_t LuaDrawable::getScaleX(lua_State *L) { auto drawable = Lua::getObject<Drawable>(L, 1, LuaType::Drawable); Lua::pushNumber(L, drawable->getScaleX()); return 1; }