gpt4 book ai didi

iphone - 找不到 Cocos2D CGRectIntersect?

转载 作者:行者123 更新时间:2023-11-29 13:17:35 26 4
gpt4 key购买 nike

我的 Cocos2D (v2.0) 游戏有问题。我遇到两个问题(我在代码部分对它们进行了评论)。这是 Bullet.m 文件:

-(BOOL)checkCollisions:(CGRect)r
{
BOOL x = NO;

if(CGRectIntersectsRect([theGame myRect:self.mySprite],r)) //FIRST ISSUE - Sending 'id' to parameter of incompatible type 'CGRect' (aka 'struct CGRect');
//SECOND ISSUE - Instance method'-myRect:' not found (return type defaults to 'id')
{
x=YES;
[self reset];
}
return x;
}

在这个文件的后面:

-(void)update
{
switch (self.whoFired)
{
case 1:
[self.mySprite setPosition:ccp(self.mySprite.position.x,self.mySprite.position.y + self.firingSpeed)];

for(Enemy * s in theGame.enemies)
{
if(ccpDistance(self.mySprite.position, s.mySprite.position)<30)
{
if([self checkCollisions:[theGame myRect:s.mySprite]]) //FIRST ISSUE - Sending 'id' to parameter of incompatible type 'CGRect' (aka 'struct CGRect')
//SECOND ISSUE - Instance method '-damage' not found (return type defaults to 'id')
{
[s damage];
}
}
}
break;
...

因此,两个错误是相同的:将“id”传递给不兼容类型“CGRect”(又名“struct CGRect”)的参数。另外两个是关于 Damage 和 MyRect 函数。它们当然存在(在 GameScene.m 和 Enemy.m 文件中;一切都由 .h 文件连接,我在 Damae 和 MyRect 函数中没有发现错误):

-(CGRect)myRect:(CCSprite *)sp
{
CGRect rect = CGRectMake(sp.position.x-sp.textureRect.size.width/2, sp.position.y-sp.textureRect.size.height/2, sp.textureRect.size.width, sp.textureRect.size.height);
return rect;
}


-(void)damage
{
self.hp--;
[self.mySprite runAction:[CCSequence actions:
[CCTintTo actionWithDuration:0.5 red:255 green:0 blue:0],
[CCTintTo actionWithDuration:0.5 red:255 green:255 blue:255],nil]];
if(hp<=0)
{
[self destroy];
}
}

有什么问题吗?为什么编译器看不到 myRect 并损坏函数?

最佳答案

为什么不能使用 CCSprite 的默认边界框?

if(CGRectIntersectsRect([self.mySprite boundingBox],r))

关于iphone - 找不到 Cocos2D CGRectIntersect?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15301536/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com