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

      

  • 相关阅读:
    LINUX和git
    drf [Django REST Framework]
    python用法小技巧
    爬虫
    django入门到精通
    前端框架
    mysql数据库
    网络编程和并发编程
    面向对象
    python基础
  • 原文地址:https://www.cnblogs.com/sanjin/p/3278413.html
Copyright © 2011-2022 走看看