Coin
2005.01.05, 02:13 AM
i am BRAND new to trying graphics in Obj-C,
ive made otehr things... a calculator, a hangman game (interface builder only), and a few other weird things, but i dont know how to operate them custom views.
i dont really know what a first project should be so i figured a worm type game (the one on old cell phones) no inported graphics just drawing lines, i havnt even really started
so far i have the app launches and shows a brown square, then i figued i should, have some preferences for background/worm color, so i have color wells, i cant even get a button to change the color of the view to the color of the color well, here is what i have
header file
#import <Cocoa/Cocoa.h>
@interface gameView : NSView
{
IBOutlet NSColorWell* bgColor;
IBOutlet NSColorWell* wormColor;
IBOutlet NSTextField* nameField;
IBOutlet NSWindow* gameWindow;
IBOutlet NSWindow* welcomeSheet;
IBOutlet NSView* stretchView;
IBOutlet NSColorWell* test;
NSColor * wc;
NSColor * bgc;
NSBezierPath *worm;
NSString *name;
}
- (IBAction)saveColors:(id)sender;
- (IBAction)newGame:(id)sender;
- (IBAction)continue:(id)sender;
@end
here is the code for awakeFromNib and the drawRect one
- (void)awakeFromNib
{
bgc = [NSColor brownColor];
wc = [NSColor orangeColor];
[wormColor setColor:wc];
[bgColor setColor:bgc];
//wormColor is the worm colorwell
//bgColor is the background color
}
- (void)drawRect:(NSRect)rect
{
NSRect bounds = [self bounds];
[bgc set];
[NSBezierPath fillRect:bounds];
}
here is the code that is run when you press the set bacground button
- (IBAction)saveColors:(id)sender
{
bgc = [[bgColor color] retain];
wc = [wormColor color];
[stretchView setNeedsDisplay:YES];
}
this same question has been sitting on the createMacGames fourm for a week, so someone please help.......
ive made otehr things... a calculator, a hangman game (interface builder only), and a few other weird things, but i dont know how to operate them custom views.
i dont really know what a first project should be so i figured a worm type game (the one on old cell phones) no inported graphics just drawing lines, i havnt even really started
so far i have the app launches and shows a brown square, then i figued i should, have some preferences for background/worm color, so i have color wells, i cant even get a button to change the color of the view to the color of the color well, here is what i have
header file
#import <Cocoa/Cocoa.h>
@interface gameView : NSView
{
IBOutlet NSColorWell* bgColor;
IBOutlet NSColorWell* wormColor;
IBOutlet NSTextField* nameField;
IBOutlet NSWindow* gameWindow;
IBOutlet NSWindow* welcomeSheet;
IBOutlet NSView* stretchView;
IBOutlet NSColorWell* test;
NSColor * wc;
NSColor * bgc;
NSBezierPath *worm;
NSString *name;
}
- (IBAction)saveColors:(id)sender;
- (IBAction)newGame:(id)sender;
- (IBAction)continue:(id)sender;
@end
here is the code for awakeFromNib and the drawRect one
- (void)awakeFromNib
{
bgc = [NSColor brownColor];
wc = [NSColor orangeColor];
[wormColor setColor:wc];
[bgColor setColor:bgc];
//wormColor is the worm colorwell
//bgColor is the background color
}
- (void)drawRect:(NSRect)rect
{
NSRect bounds = [self bounds];
[bgc set];
[NSBezierPath fillRect:bounds];
}
here is the code that is run when you press the set bacground button
- (IBAction)saveColors:(id)sender
{
bgc = [[bgColor color] retain];
wc = [wormColor color];
[stretchView setNeedsDisplay:YES];
}
this same question has been sitting on the createMacGames fourm for a week, so someone please help.......