zoukankan      html  css  js  c++  java
  • 地图跟着主角视角滚动

    roleSprite

    map

    map:addChild(roleSprite)  //角色加在地图上,

    先设置role的位置,再调用下面函数设置地图位置

    roleSprite:setPotion()

    void setSceneScrollPosition() 
    { 
        CCPoint position = roleSprite->getPosition(); 
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); 
        CCSize mapSizeInPixel = CCSizeMake(map->getMapSize().width * map->getTileSize().width,  map->getMapSize().height * map->getTileSize().height); 
     
        if (mapSizeInPixel.width>screenSize.width) 
        { 
            float x=position.x-screenSize.width/2.0f; 
            limit(0.0f,x,mapSizeInPixel.width-screenSize.width); 
            map->setPosition(ccp(-x,this->getPosition().y)); 
        } 
     
        if (mapSizeInPixel.height>screenSize.height) 
        { 
            float y=position.y-screenSize.height/2.0f; 
            limit(0.0f,y,mapSizeInPixel.height-screenSize.height); 
            map->setPosition(ccp(this->getPosition().x,-y)); 
        }    
    } 

      

    //防止滚出地图黑边
    template<typename T> inline void limit(T min,T &val, T max) { if (val<min) val=min; else if (val>max) val=max; }

      

  • 相关阅读:
    Section 3.1 Shaping Regions
    3D@OpenSource
    查找资料
    Section 3.1 Shaping Regions Again
    USACO Contact IOI’98 TLE
    事项ON丰宁坝上草原
    四叉树@POJ1610 Quad Trees
    在TabCtrl上放View@MFC
    CUGB的一场周赛
    贴图程序进展
  • 原文地址:https://www.cnblogs.com/sanjin/p/3278413.html
Copyright © 2011-2022 走看看