I'm making a side scrolling game. When a player enters a rectangle, I would like it to trigger displaying a message.
At the start of the program, I read an XML file with this parser:
The XML file looks like this:
Every time the character moves it checks whether their frame intersects with the message trigger frame.
It logs that I set off the message trigger, but it crashes before logging what the message is. It tells me that "Thread 1rogram received signal: "EXC_BAD_ACCESS"" If I take out the log and setting the messageLable.text, it runs fine and properly shows and hides the UILabel.
Edit: In the parser I can get an NSLog that says what [attributeDict valueForKey"message"] is, and I can also get an NSLog to give me what messages[messageCount] is right afterwards. Both work fine and display the correct message.
At the start of the program, I read an XML file with this parser:
Code:
-(void)parseXMLFileAtURL:(NSURL *)file
{
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:file];
[parser setDelegate:self];
[parser setShouldProcessNamespaces:NO];
[parser setShouldReportNamespacePrefixes:NO];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
[parser release];
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:@"messageTrigger"])
{
float x = [[attributeDict valueForKey:@"x"] floatValue];
float y = [[attributeDict valueForKey:@"y"] floatValue];
float w = [[attributeDict valueForKey:@"w"] floatValue];
float h = [[attributeDict valueForKey:@"h"] floatValue];
messageTriggers[messageCount] = CGRectMake(x, y, w, h);
messages[messageCount] = [attributeDict valueForKey:@"message"];
messageCount++;
}
}
The XML file looks like this:
Code:
<adalez map="test" author="xxx">
<!-- Messages -->
<messageTrigger x="480" y="300" w="480" h="100" message="You are on a hidden platform!"/>
</adalez>
Every time the character moves it checks whether their frame intersects with the message trigger frame.
Code:
int i;
for (i = 0; i < messageCount; i++)
{
if (CGRectIntersectsRect(frame, messageTriggers[i]))
{
NSLog(@"Detected that you set off the message trigger.");
NSLog(@"The message is: %@", messages[i]);
messageLabel.text = messages[i];
messageLabel.alpha += 0.05;
break;
}
else messageLabel.alpha -= 0.01;
}
It logs that I set off the message trigger, but it crashes before logging what the message is. It tells me that "Thread 1rogram received signal: "EXC_BAD_ACCESS"" If I take out the log and setting the messageLable.text, it runs fine and properly shows and hides the UILabel.
Edit: In the parser I can get an NSLog that says what [attributeDict valueForKey"message"] is, and I can also get an NSLog to give me what messages[messageCount] is right afterwards. Both work fine and display the correct message.
Last edited: