zoukankan      html  css  js  c++  java
  • quick-cocos2d-x之testlua之VisibleRect.lua

    require "extern"
    --这个类找到了可视区域的9个点的坐标:左上、上的中点、右上、左的中点、左下、下的中点、右下、右的中点。一般用于使用相对坐标的场合,解决自适应屏幕的问题
    --改写自VisibleRect.cpp
    VisibleRect = class("VisibleRect")
    VisibleRect.__index = VisibleRect
    
    --CCRect VisibleRect::s_visibleRect; 
    --创建一个CCRect实例:s_visibleRect(初始高、宽都是0)
    VisibleRect.s_visibleRect = CCRect:new()
    --[[
    void VisibleRect::lazyInit() {
         if (s_visibleRect.size.width == 0.0f && s_visibleRect.size.height == 0.0f)     {
                  CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();         s_visibleRect.origin = pEGLView->getVisibleOrigin(); 
                    s_visibleRect.size = pEGLView->getVisibleSize(); 
              }
     } 
    ]]
    function VisibleRect:lazyInit()
        if (self.s_visibleRect.size.width == 0.0 and self.s_visibleRect.size.height == 0.0) then
            --sharedOpenGLView:get the shared main open gl window 
            local pEGLView = CCEGLView:sharedOpenGLView();
            self.s_visibleRect.origin = pEGLView:getVisibleOrigin();
            self.s_visibleRect.size = pEGLView:getVisibleSize();
        end
    end
    
    --返回一个CCRect,就是可视区域
    function VisibleRect:getVisibleRect()
        self:lazyInit();
        -- return CCRectMake(s_visibleRect.origin.x, s_visibleRect.origin.y, s_visibleRect.size.width, s_visibleRect.size.height);
        return CCRectMake(self.s_visibleRect.origin.x, self.s_visibleRect.origin.y, self.s_visibleRect.size.width, self.s_visibleRect.size.height);
        --CCRectMake,输入坐标、长宽,输出一个CCRect
    end
    
    function VisibleRect:left()
        self:lazyInit();
        return ccp(self.s_visibleRect.origin.x, self.s_visibleRect.origin.y+self.s_visibleRect.size.height/2);
    end
    
    function VisibleRect:right()
        self:lazyInit();
        return ccp(self.s_visibleRect.origin.x+self.s_visibleRect.size.width, self.s_visibleRect.origin.y+self.s_visibleRect.size.height/2);
    end
    
    function VisibleRect:top()
        self:lazyInit();
        return ccp(self.s_visibleRect.origin.x+self.s_visibleRect.size.width/2, self.s_visibleRect.origin.y+self.s_visibleRect.size.height);
    end
    
    function VisibleRect:bottom()
        self:lazyInit();
        return ccp(self.s_visibleRect.origin.x+self.s_visibleRect.size.width/2, self.s_visibleRect.origin.y);
    end
    
    function VisibleRect:center()
        self:lazyInit();
        return ccp(self.s_visibleRect.origin.x+self.s_visibleRect.size.width/2, self.s_visibleRect.origin.y+self.s_visibleRect.size.height/2);
    end
    
    function VisibleRect:leftTop()
        self:lazyInit();
        return ccp(self.s_visibleRect.origin.x, self.s_visibleRect.origin.y+self.s_visibleRect.size.height);
    end
    
    function VisibleRect:rightTop()
        self:lazyInit();
        return ccp(self.s_visibleRect.origin.x+self.s_visibleRect.size.width, self.s_visibleRect.origin.y+self.s_visibleRect.size.height);
    end
    
    function VisibleRect:leftBottom()
        self:lazyInit();
        return self.s_visibleRect.origin;
    end
    
    function VisibleRect:rightBottom()
        self:lazyInit();
        return ccp(self.s_visibleRect.origin.x+self.s_visibleRect.size.width, self.s_visibleRect.origin.y);
    end
  • 相关阅读:
    【STM32H7教程】第35章 STM32H7的定时器应用之高精度单次延迟实现(支持TIM2,3,4和5)
    【重大更新】AppWizard来了,emWin6.10版本来了
    【STM32H7教程】第34章 STM32H7的定时器应用之TIM1-TIM17的PWM实现
    【STM32H7教程】第33章 STM32H7的定时器应用之TIM1-TIM17的中断实现
    【性能测评】DSP库,MDK5的AC5,AC6,IAR和Embedded Studio的三角函数性能
    【实战经验分享】一劳永逸的解决网线随意热插拔问题
    基于STM32的无损压缩算法miniLZO移植,压缩率很高,20KB随机数压缩到638字节,耗时275us
    Java Number & Math类
    Java switch case语句
    java条件语句
  • 原文地址:https://www.cnblogs.com/sagacite/p/3372776.html
Copyright © 2011-2022 走看看