zoukankan      html  css  js  c++  java
  • 不让精灵移除屏幕外 重写setPosition方法

    -(void) setPosition:(CGPoint)pos
    {
        CGSize screenSize = [[CCDirector sharedDirector] winSize];
        float halfWidth = contentSize_.width * 0.5f;
        float halfHeight = contentSize_.height * 0.5f;
        
        // Cap the position so the Ship's sprite stays on the screen
        if (pos.x < halfWidth)
        {
            pos.x = halfWidth;
        }
        else if (pos.x > (screenSize.width - halfWidth))
        {
            pos.x = screenSize.width - halfWidth;
        }
        
        if (pos.y < halfHeight)
        {
            pos.y = halfHeight;
        }
        else if (pos.y > (screenSize.height - halfHeight))
        {
            pos.y = screenSize.height - halfHeight;
        }
        
        // must call super with the new position
        [super setPosition:pos];
    }
  • 相关阅读:
    java面试常见的类
    Day6
    DAY5
    Day4
    Day3
    Day2
    Day1
    echarts3关系图:力引导布局, 固定某些节点
    Hbuilder中配置cmd
    webpack 学习
  • 原文地址:https://www.cnblogs.com/gaoxiao228/p/2509266.html
Copyright © 2011-2022 走看看