gpt4 book ai didi

iphone - 在CCSprite子类..中调用self.addChild时,iPhone应用程序崩溃。

转载 作者:行者123 更新时间:2023-12-03 16:02:00 26 4
gpt4 key购买 nike

我已经下载了ABC开源软件,并将源代码转换为cocos2d 1.01。
现在,我在初始化Sprite子类时遇到了问题。 (我的子类是@interface OrbSprite:CCSprite)

此代码是无穷循环和较旧的cocos2d版本。

-(id) init {
self = [super init];

if (self)
{
[self initWithFile:@"bubble1.png"];
Animation *bub = [Animation animationWithName:@"bubble" delay:0 images:@"bubble1.png", @"bubble2.png", nil];
self.bubble = bub;
[bub release];

[self addAnimation:bubble];

Label *l = [[Label alloc] initWithString:@"" dimensions:CGSizeMake(45, 45) alignment:UITextAlignmentCenter
fontName:@"Arial Rounded MT Bold" fontSize:18];
self.label = l;
[l release];

}

return self; }

我正在寻找解决方案,并且可以通过更改init方法的名称来解决。
-(id) initWithBubbleImage { 

if ((self = [super initWithFile :@"bubble1.png"]))
{
NSLog(@"OrbSprite init in if self Method");

bubblea = [NSArray arrayWithObjects:@"bubble1.png",@"bubble2.png",nil];

bub = [CCAnimation animationWithFrames:bubblea delay:0 ];
[[CCAnimationCache sharedAnimationCache] addAnimation:bub name:@"bubbleAnim"];
self.bubble = bub;
[bub release];

label = [[CCLabelTTF alloc] initWithString:@"" dimensions:CGSizeMake(45, 45) alignment:UITextAlignmentCenter
fontName:@"Arial Rounded MT Bold" fontSize:18];
}
return self; }

????问题是,当已经更改了初始名称时,我在同一子类的“-(void)setLabelStr:(NSString)str”中发现在调试区域中addChild:错误。
“**-[OrbSprite addChild:]中的断言失败,并且由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'参数必须为非'

这是同一子类中的方法
- (void) setLabelStr:(NSString *) str  {
[label setString:str];
[self addChild:label];
[label setAnchorPoint:ccp(0, 13)]; }

任何人都可以帮助我.......
非常感谢你。

================================================== ===================

E D I T-E D I T-E D I T-E D I T-E D I T-E D I T

我已经将此作为答复。
但还是不行
听到的是.h和.m代码

OrbSprite.h

this is code


#import "cocos2d.h"
@interface OrbSprite : CCSprite
{
CCLabelTTF *label;
CCAnimation *bubble;
BOOL isBubble;
BOOL isHidden;
int order;

CCSequence *popSequence;
}
@property (nonatomic, retain) CCLabelTTF *label;
@property (nonatomic, retain) CCSequence *popSequence;
@property (nonatomic, retain) CCAnimation *bubble;
@property (nonatomic, retain) NSArray *bubblea;
@property (readwrite) BOOL isBubble;
@property (readwrite) BOOL isHidden;
@property (readwrite) int order;
-(id)initWithBubbleImage;
- (void) pop;
- (void) setLabelStr:(NSString *) str;
- (void) showBubble;
- (void) reset;
@end

OrbSprite.m

this is code


#import "OrbSprite.h"
@implementation OrbSprite
@synthesize bubble;
@synthesize label;
@synthesize isBubble;
@synthesize isHidden;
@synthesize popSequence;
@synthesize order;
@synthesize bubblea;

-(id) initWithBubbleImage {

if ((self = [super initWithFile:@"bubble1.png"]))
{

bubblea = [NSArray arrayWithObjects:@"bubble1.png",@"bubble2.png",nil];

bubble= [CCAnimation animationWithFrames:bubblea delay:0 ];
[[CCAnimationCache sharedAnimationCache] addAnimation:bub name:@"bubbleAnim"];

label = [[CCLabelTTF alloc] initWithString:@"" dimensions:CGSizeMake(45, 45)
alignment:UITextAlignmentCenter fontName:@"Arial Rounded MT Bold" fontSize:18];
}
return self;
}

- (void) pop {
isBubble = NO;
popSequence = [CCSequence actions:[CCScaleTo actionWithDuration:.1 scale:.5],
[CCScaleTo actionWithDuration:.1 scale:2], [CCCallFunc actionWithTarget:self
selector:@selector(finishedPopSequence)], nil];
[self runAction:popSequence];
}

- (void) finishedPopSequence {
self.scale = 1;
[self setDisplayFrameWithAnimationName:@"bubble" index:0]; }

- (void) reset {
self.scale = 1;
[self setDisplayFrameWithAnimationName:@"bubble" index:0]; }

- (void)showBubble {
isBubble = YES;
[self removeChild:label cleanup:NO];
[self setDisplayFrameWithAnimationName:@"bubbleAnim" index:1];
self.scale = .5;
id Orbshowscale = [CCScaleTo actionWithDuration:1 scale:1.5];
id Orbshowscale2= [CCScaleTo actionWithDuration:.1 scale:1];
[self runAction:[CCSequence actions:Orbshowscale,Orbshowscale2 , nil]]; }

- (void) setLabelStr:(NSString *) str {
[label setString:str];
[self addChild:label]; //<<< *** Assertion failure in -[OrbSprite addChild:]
[label setAnchorPoint:ccp(0, 13)]; }

@end

我已经解决了过度发布的问题。
但它仍然不起作用..

还发现同样的问题是

***-[OrbSprite addChild:]中的断言失败

***由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“参数必须为非零”

多亏每个有同情心的人...

最佳答案

看起来好像您在init方法中过度释放了变量“bub”。您不会通过alloc或create方法调用来创建它,因此您不应该释放它。

关于iphone - 在CCSprite子类..中调用self.addChild时,iPhone应用程序崩溃。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10068813/

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