gpt4 book ai didi

ios - Cocos2d CCSprite 位置释放错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:23:11 25 4
gpt4 key购买 nike

当我使用以下代码运行我的游戏时,我的游戏崩溃了,当玩家与 enemy2 相交时,我在调试控制台中收到以下错误。

错误:*** -[CCSprite position]: 发送到释放实例 0xa8cabd0 的消息

代码:

// Check if enemy2 is a child of the layer
if (enemy2) {
CGRect enemy2Rect = CGRectMake(
enemy2.position.x - (enemy2.contentSize.width/2),
enemy2.position.y - (enemy2.contentSize.height/2),
80,
// ERROR HAPPENS HERE Stopped at thread 1
41);
// check if player intersects the enemy
if (CGRectIntersectsRect(playerRect, enemy2Rect)) {
// check if the power up is true
if (bustEmUp == TRUE) {
enemy2Hit = TRUE;
[self unschedule:@selector(collisionDetection)];
[self removeChild:enemy2 cleanup:YES];
id delay = [CCDelayTime actionWithDuration:15];
id addEnemy = [CCCallFunc actionWithTarget:self selector:@selector(addEnemy2)];
[self runAction:[CCSequence actions:delay,addEnemy, nil]];
[self schedule:@selector(collisionDetection) interval:0.01];
} else {
// if not then collide
[self schedule:@selector(collisionAlert)];
}
}
}

如果有帮助,这是我的回溯:

#0  0x01a83e1e in ___forwarding___ ()
#1 0x01a83ce2 in __forwarding_prep_0___ ()
#2 0x000e4fab in -[Survival collisionDetection] (self=0x12b975c0, _cmd=0x14a5e0) at Survival.m:521
#3 0x0005babb in -[CCTimer update:] (self=0x1281af50, _cmd=0x13347c, dt=0.0494979993) at CCScheduler.m:141
#4 0x00064a20 in -[CCScheduler tick:] (self=0xa8c9b70, _cmd=0x13c8fa, dt=0.0494979993) at CCScheduler.m:606
#5 0x0008d9ef in -[CCDirectorIOS drawScene] (self=0x9466d20, _cmd=0x136bdf) at CCDirectorIOS.m:152
#6 0x0008ffda in -[CCDirectorDisplayLink mainLoop:] (self=0x9466d20, _cmd=0x142bcd, sender=0x1208c2b0) at CCDirectorIOS.m:721
#7 0x005e22db in CA::Display::DisplayLink::dispatch ()
#8 0x005e21af in CA::Display::TimerDisplayLink::callback ()
#9 0x01af1966 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#10 0x01af1407 in __CFRunLoopDoTimer ()
#11 0x01a547c0 in __CFRunLoopRun ()
#12 0x01a53db4 in CFRunLoopRunSpecific ()
#13 0x01a53ccb in CFRunLoopRunInMode ()
#14 0x021c8879 in GSEventRunModal ()
#15 0x021c893e in GSEventRun ()
#16 0x00b63a9b in UIApplicationMain ()
#17 0x000c083f in main (argc=1, argv=0xbffff5a0) at main.m:14

这里是我初始化 enemy2 的地方:

enemy2 = [CCSprite spriteWithFile:@"SpaceShip2.png"];
enemy2.position = ccp(500,700);
[self addChild:enemy2];

最佳答案

enemy2 可能已经发布了。它会通过您的 if(enemy2) 检查,因为 enemy2 是一个地址而不是 nil,但该地址处的对象已被释放。

关于ios - Cocos2d CCSprite 位置释放错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9523211/

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