• 地图跟着主角视角滚动


    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; }

      

  • 相关阅读:
    执迷不悟
    splunk设置索引周期和索引大小
    下载地址sqlserver2008r2
    蓝牙
    1、IdentityServer4
    翻译名义集
    sql 字符取数字
    Aerial Images Dataset 航空图像数据集 收集
    基于VGG16模型对猫狗分类任务进行迁移学习
    Apollo配置中心
  • 原文地址:https://www.cnblogs.com/sanjin/p/3278413.html
Copyright © 2020-2023  润新知