CGContextSetFillColorWithColor(g, [UIColor greyColor].CGColor);
मैं ओ रेली की किताब, iPhone खेल विकास का पालन करने की कोशिश कर रही है, लेकिन पृष्ठ पर 73 अध्याय 3 मैं इस त्रुटि मिलती है: पुस्तक का errata page को यह में एक अपुष्ट शुद्धिपत्र है मुताबिकCGContextSetFillColorWithColor में UIColor की CGColor प्रॉपर्टी तक कैसे पहुंचे?
error: request for member 'CGColor' in something not a structure or union
किताब। उस लाइन को किस कार्यात्मक कोड से बदला जा सकता है?
अतिरिक्त विवरण
उदाहरण परियोजना here डाउनलोड किया जा सकता।
मैं पेज 73 के लिए पृष्ठ 72 से पुस्तक के निर्देशों के gsMain.m
कीसमारोह प्रस्तुत करना पर gsMain वर्ग (उदाहरण के परियोजना pg77 से अपनी अलग) का निर्माण करने के द्वारा समारोह प्रस्तुत करना पर त्रुटि का सामना कर रहा था कोड स्निपेट उस किताब gsMain वर्ग का निर्माण करने का निर्देश का पालन किया है:
//gsMain.h
@interface gsTest : GameState { }
@end
//gsMain.m
@implementation gsMain
-(gsMain*) initWithFrame:(CGRect)frame andManager:(GameStateManager*)pManager
{
if (self = [super initWithFrame:frame andManager:pManager]) {
NSLog(@"gsTest init");
}
return self;
}
-(void) Render
{
CGContextRef g = UIGraphicsGetCurrentContext();
//fill background with gray
CGContextSetFillColorWithColor(g, [UIColor greyColor].CGColor); //Error Occurs here
CGContextFillRect(g, CGRectMake(0, 0, self.frame.size.width,
self.frame.size.height));
//draw text in black
CGContextSetFillColorWithColor(g, [UIColor blackColor].CGColor);
[@"O'Reilly Rules!" drawAtPoint:CGPointMake(10.0,20.0)
withFont:[UIFont systemFontOfSize:[UIFont systemFontSize]]];
}
-(void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch* touch = [touches anyObject];
NSUInteger numTaps = [touch tapCount];
//todo: implement touch event code here
}
@end
Chapter3_Example_p77 77 के पेज 71 से अभ्यास के परिणाम दिखाने के लिए माना जाता है, लेकिन यह करने के लिए 71 में दी गई दिए गए निर्देशों से बहुत अलग है 77. निम्नलिखित कोड उपरोक्त से डाउनलोड पूर्ण, संकलित वर्ग है संपर्क।
//gsMain.h
#import <Foundation/Foundation.h>
#import "GameState.h"
@interface gsMain : GameState {
}
@end
// gsMain.m
// Example
// Created by Joe Hogue and Paul Zirkle
#import "gsMain.h"
#import "gsTest.h"
#import "Test_FrameworkAppDelegate.h"
@implementation gsMain
-(gsMain*) initWithFrame:(CGRect)frame andManager:(GameStateManager*)pManager {
if (self = [super initWithFrame:frame andManager:pManager]) {
//do initializations here.
}
return self;
}
- (void) Render {
[self setNeedsDisplay]; //this sets up a deferred call to drawRect.
}
- (void)drawRect:(CGRect)rect {
CGContextRef g = UIGraphicsGetCurrentContext();
//fill background with gray
CGContextSetFillColorWithColor(g, [UIColor grayColor].CGColor);
CGContextFillRect(g, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height));
//draw text in black.
CGContextSetFillColorWithColor(g, [UIColor blackColor].CGColor);
[@"O'Reilly Rules!" drawAtPoint:CGPointMake(10.0, 20.0) withFont:
[UIFont systemFontOfSize: [UIFont systemFontSize]]];
//fps display from page 76 of iPhone Game Development
int FPS = [((Test_FrameworkAppDelegate*)m_pManager) getFramesPerSecond];
NSString* strFPS = [NSString stringWithFormat:@"%d", FPS];
[strFPS drawAtPoint:CGPointMake(10.0, 60.0) withFont:[UIFont systemFontOfSize:
[UIFont systemFontSize]]];
}
//this is missing from the code listing on page 77.
-(void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch* touch = [touches anyObject];
NSUInteger numTaps = [touch tapCount];
if(numTaps > 1) {
[m_pManager doStateChange:[gsTest class]];
}
}
@end
धन्यवाद। आपकी मदद से मैं अंत में समस्या देखता हूं। मैं एक संस्करण संकलित कर रहा हूं जिसे मैंने पुस्तक के निर्देशों के बाद बनाया है (प्रश्न के अतिरिक्त विवरण में)। जिसे पी77 उदाहरण में संकलित किया गया है जिसे आपने संकलित किया है। 'P77 परिणाम' में रेंडर फ़ंक्शन P71-p73 में पुस्तक के निर्देशों से बहुत अलग है। मुझे लगता है कि मुझे वास्तविक पुस्तक पर निर्देशों का पालन करने के बजाय सिर्फ पी77 के जीएस मेन क्लास की प्रतिलिपि बनाना होगा। – Azeworai
मैंने उदाहरण पी 71 प्रोजेक्ट को संदर्भित करना शुरू कर दिया है और मैं आईफोनओएस 3.1.2 – Azeworai