zoukankan      html  css  js  c++  java
  • cocos2d-x:Layer::setPosition

    如果Node的实际类型是Layer或者其派生类,

    setPosition是不是有猫腻?

    std::string menuImage = "menu.png";
    
    auto menuItem = MenuItemImage::create(menuImage,menuImage,NULL,this);
    
    auto menu = Menu::create(menuItem,NULL);
    
    auto menuItemPoint = Point(...,...);
    
    //具体按钮位置是由menuItem的setPosition调用决定。而不是Menu的setPosition.
    
    menuItem->setPosition(menuItemPoint);
    
    //貌似设置menu的anchor没作用
    
    //menu->setAnchorPoint(Point::ZERO);
    
    //这个setPosition ....打酱油?。可又是,去掉不显示.
    
    //但又不是按menu的anchor点显示在父Layer的ZERO位置
    
    menu->setPosition(Point::ZERO);
    
    
    
    //添加到父Layer中
    
    addChild(menu,1);
    

    新建一个Layer对象,调用其 getContentSize(),返回是(0,0)

    auto label = LabelTTF::create( "left_bottom", "Arial", 24);
    label->setPosition(Point::ZERO);
    label->setAnchorPoint(Point::ZERO);
    addChild(label);
    

    label 却会按anchor正常显示在左下角..  

    ----------

    在一个Layer的anchor放置一个精灵,将这个Layer设置到父Layer的ZERO位置,精灵却不在ZERO位置

    	auto layer = Layer::create();
    	auto layersize = layer->getContentSize();
    	auto layerAnchor = layer->getAnchorPoint();
    	auto sprite = Sprite::create(s_pathClose);
    	auto anchorPoint = Point(layersize.width * layerAnchor.x,layersize.height * layerAnchor.y);
    	sprite->setPosition(anchorPoint);
    	layer->addChild(sprite);
    	layersize = layer->getContentSize();
    	//Point  layPoint = Point::ZERO;
    	layer->setPosition(Point::ZERO);
    	addChild(layer);
    

      

    这篇博文 :http://blog.csdn.net/xuguangsoft/article/details/8425623 

    有讲Layer的anchor是左下角,一切就都对上了,但是Layer::getAnchorPoint()返回的是(0.5,0.5)..

  • 相关阅读:
    vue中使用sass
    vue2项目使用axios发送请求
    css正方形贴图
    用vue-cli 工具搭建项目
    反调试与破反调试笔记
    低功耗蓝牙UUID三种格式转换
    【原创】Android 5.0 BLE低功耗蓝牙从设备应用
    金山助手流氓软件-被进程sjk_daemon.exe坑死
    bower安装教程
    intellij idea快捷键
  • 原文地址:https://www.cnblogs.com/ezhong/p/3452779.html
Copyright © 2011-2022 走看看