Cocos2d iphone 我觉得我不想这样工作

Cocos2d iphone 我觉得我不想这样工作,cocos2d-iphone,cgrect,Cocos2d Iphone,Cgrect,感谢您抽出时间来查看我的noob问题,我们将非常感谢您的帮助 首先,我尝试使用贝塞尔曲线(不想使用box2d)使对象从屏幕的一侧“反弹”到另一侧 该对象有4个状态,代表4个移动,当对象撞击(反应)地板时,它会从以前的状态移动到新状态,请参见下图 **我的问题是,我无法正确地使用CGRect将其从状态1转换到状态4。我目前可以让对象移动状态,但接下来会发生以下两种情况之一 1) 下面的代码将允许对象正确地从状态1更改为状态2,但在状态2结束时,它不会与地板发生反应(它只是在地板上移动),因此不会

感谢您抽出时间来查看我的noob问题,我们将非常感谢您的帮助

首先,我尝试使用贝塞尔曲线(不想使用box2d)使对象从屏幕的一侧“反弹”到另一侧

该对象有4个状态,代表4个移动,当对象撞击(反应)地板时,它会从以前的状态移动到新状态,请参见下图

**我的问题是,我无法正确地使用CGRect将其从状态1转换到状态4。我目前可以让对象移动状态,但接下来会发生以下两种情况之一

1) 下面的代码将允许对象正确地从状态1更改为状态2,但在状态2结束时,它不会与地板发生反应(它只是在地板上移动),因此不会更改为状态3

 -(void)updateStateWithDeltaTime:(ccTime)deltaTime andListOfGameObjects:(CCArray *)listOfGameObjects {


    [self setDebugLabelTextAndPosition];


    if ([self isOutsideOfScreen])
        return;

   CGPoint currentSpitePosition = [self position];

    floorCharacter = (GameCharacter*)[[self parent]
                                       getChildByTag:kfloorSpriteTagValue];

    CGRect floorBoudingBox = [floorCharacter adjustedBoundingBox];
    CGRect ballBoundingBox = [self adjustedBoundingBox];

    CGRect characterBox = [character adjustedBoundingBox];
    if (CGRectIntersectsRect(floorBoudingBox, ballBoundingBox)) {

        if (characterState == kStateTravelling) {
            [self changeState:kStateTravellingPoint2];
        }

        if (characterState == kStateTravellingPoint2) {
            [self changeState:kStateTravellingPoint3];

        }

    }
2) 下面的代码将在对象第一次触地时停止对象,但如果我在程序运行时移除地板一秒钟,对象将移动到状态3,并在它触地时再次停止,如果我再次移除地板,它将再次移动到状态4,而不添加其他状态(如下所示)所以每次都是重复状态2。我猜这是因为它一落地就返回真值,虽然它是真的,但不会起作用

-(void)updateStateWithDeltaTime:(ccTime)deltaTime andListOfGameObjects:(CCArray *)listOfGameObjects {

    [self setDebugLabelTextAndPosition];

    if ([self isOutsideOfScreen])
        return;

   CGPoint currentSpitePosition = [self position];
   floorCharacter = (GameCharacter*)[[self parent]
                                       getChildByTag:kfloorSpriteTagValue];

    CGRect floorBoudingBox = [floorCharacter adjustedBoundingBox];
    CGRect ballBoundingBox = [self adjustedBoundingBox];

    isfloorWithinBoundingBox =
    CGRectIntersectsRect(floorBoudingBox, ballBoundingBox) ?
    YES : NO;

    if (isfloorWithinBoundingBox) {

        [self changeState:kStateTravellingPoint2];

    }
如果地板在“反弹”运动中处于活动状态,我希望它在4种状态之间移动,因此一旦状态1完成,它将撞击地板并移动到状态2,直到它完成曲线运动并再次撞击地板,然后移动到状态3等


对,我有上述工作,但不完全明白我是如何做到的

我尝试使用screenSize来确定对象所在的位置,并以此为基础创建CGRect,但一开始它不起作用。然后我保留了代码,但添加了“CGSize screenSize=[CCDirector sharedDirector].winSize;”方法,然后对象,按照我想要的方式执行

但是,我现在在使用screenSize时出现以下错误。。 'screenSize'隐藏实例变量的本地声明'

我想知道的是,在我在方法中声明screenSize之前,它为什么不能使用screenSize(因为它已经在导入到这个类中的另一个类中声明)。

再次感谢所有花时间阅读本文的人

我的代码在下面

-(void)updateStateWithDeltaTime:(ccTime)deltaTime andListOfGameObjects:(CCArray *)listOfGameObjects {

    [self setDebugLabelTextAndPosition];

    if ([self isOutsideOfScreen])
        return;

   CGPoint currentSpitePosition = [self position];

    floorCharacter = (GameCharacter*)[[self parent]
                                       getChildByTag:kfloorSpriteTagValue];

    CGRect floorBoudingBox = [floorCharacter adjustedBoundingBox];
    CGRect ballBoundingBox = [self adjustedBoundingBox];

    CGPoint floorPosition = [floorCharacter position];


    *Below is where I have added screenSize*
    CGSize screenSize = [CCDirector sharedDirector].winSize;

    isfloorWithinBoundingBox =
    CGRectIntersectsRect(floorBoudingBox, ballBoundingBox) ?
    YES : NO;

    if ((characterState == kStateTravelling) && (isfloorWithinBoundingBox == YES)) {{

                [self changeState:kStateTravellingPoint2];
    }

        return;
    }

    if ((characterState == kStateTravellingPoint2)&&(isfloorWithinBoundingBox == YES) && (floorPosition.x > screenSize.width*0.32f) && (floorPosition.x < screenSize.width*0.45f)) {{

                [self changeState:kStateTravellingPoint3];  
    }

        return;
    }

    if ((characterState == kStateTravellingPoint3)&&(isfloorWithinBoundingBox == YES) && (floorPosition.x > screenSize.width*0.45f) && (floorPosition.x < screenSize.width*0.55f)) {{

        [self changeState:kStateTravellingPoint4];
    }

        return;
    }
-(void)updateStateWithDeltaTime:(ccTime)deltaTime和listOfGameObjects:(CCArray*)listOfGameObjects{
[self-SetDebuggeLabelTextAndPosition];
如果([屏幕外的自我隔离])
返回;
CGPoint currentSpitePosition=[自身位置];
floorCharacter=(GameCharacter*)[[自父]
getChildByTag:kfloorSpriteTagValue];
CGRect floorCharacter BoundingBox=[floorCharacter Adjusted BoundingBox];
CGRect BallbundingBox=[自调整边界框];
CGPoint floorPosition=[floorCharacter位置];
*下面是我添加屏幕大小的地方*
CGSize screenSize=[CCDirector sharedDirector].winSize;
isfloorWithinBoundingBox=
CGRectIntersectsRect(地板盒、球盒)?
是:不是;
if((characterState==kstate)和&(isfloorWithinBoundingBox==YES)){{
[自更改状态:KStateTravelingPoint2];
}
返回;
}
如果((characterState==kstateTravelingPoint2)&&(isfloorWithinBoundingBox==YES)&&(floorPosition.x>screenSize.width*0.32f)&&(floorPosition.xscreenSize.width*0.45f)&&(floorPosition.x
嗨,我真的很抱歉,但我想我已经删除了我关于上述内容的第一篇帖子。我也让上述内容发挥了作用(尽管不是100%是如何做到的)因此,我用我所做的一切来回答我的问题,但也添加了一个问题和答案。我现在猜这是不允许的,所以我再次道歉。谢谢你纠正我的错误。你应该用答案回答你自己的问题。你不会因此得到任何分数,但这可能会帮助其他有同样问题的人。另外,还有人le会知道这个问题得到了回答。嗨,Divanov,我知道了,但是Brad Larson删除了我的答案,并将其添加到了上面的问题中,因为我在答案中问了另一个问题。大约走到一半的时候,你会看到下面的内容……“是的,我已经完成了上面的工作,但不完全理解我是如何完成的!”然后我离开了正在工作的c下面是ode。很抱歉出现了混乱,但是这个网站和编程新手,所以不知道在回答中不要再问其他问题(常识让我暂时离开了!)。是的,你的回答更像是后续问题。在这种情况下,最好编辑原始问题。