CGContextSetFillColorWithColor(g, [UIColor greyColor].CGColor);
Ben O'Reilly kitabı, iPhone Oyun Geliştirme izlemeye çalışıyorum, ancak sayfada 73 Bölüm 3 bu hatayı alıyorum: Bu bir doğrulanmamış doğrularını olan kitabın errata page göreCGContextSetFillColorWithColor'daki UIColor'un CGColor özelliğine nasıl erişilir?
error: request for member 'CGColor' in something not a structure or union
kitap. Bu satır hangi fonksiyonel kodla değiştirilebilir?
Ek Detaylar
örnek proje here indirilebilir.
Ben
gsMain.m
render fonksiyonuna gsMain sınıfını (örneğin proje pg77 onun farklı) inşa etmek sayfa 73 sayfa 72 Kitabın talimatları izleyerek hale fonksiyonuna hatayı karşılaşmadan edildi kitap gsMain sınıf oluşturmak için talimat bu kod pasajı takip gibidir://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 sayfa 71'den egzersizlerin sonucunu göstermek gerekiyordu ama 71 ila verilen verilen talimatlara çok farklıdır 77. Aşağıdaki kod, yukardan yüklenen tamamlanmış, tamamlanabilir sınıftır. bağlantı.
//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
teşekkür ederiz. Yardımınla sonunda problemi görüyorum. Kitabın talimatlarını takip ederek oluşturduğum bir sürümü derledim (sorunun ek detaylarında). Hangi derlenmiş p77 örneğiyle sonuçlanması gerekiyordu. 'P77 sonucundaki' render işlevi, p71-p73'deki kitabın talimatlarından çok farklıdır. Sanırım p77'nin gsMain sınıfını, gerçek kitaptaki talimatları takip etmek yerine kopyalamak zorunda kalacağım. – Azeworai
Örnek p71 projesine başvurmaya başladım ve iPhoneOS 3.1.2 – Azeworai