setNeedsDisplay
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
here is the code for awakeFromNib and the drawRect one
here is the code that is run when you press the set bacground button
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
Code:
#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;
@endhere is the code for awakeFromNib and the drawRect one
Code:
- (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
Code:
- (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.......
Try looking at /Developer/Examples/AppKit/DotView
It demonstrates using an NSView subclass, bezier path drawing, and an NSColorWell, and is heavily commented.
It demonstrates using an NSView subclass, bezier path drawing, and an NSColorWell, and is heavily commented.
i looked at the drawDot appl thin in the appkit examples, and in IB they didn't instantiate the DotView, how did they connect the interface to the buttons? and color wells? do i need to make a middleman class?
is that it?
is that it?
Coin-o Wrote:i dont really know what a first project should be so i figured a worm type game (the one on old cell phones)
WHAT!!! "old cell phones"
I DON'T THINK SO BUSTER.
"Snake", "Dragon" etc. etc. were made on the atari and NES, and in arcades.
(long before the internet was even made)
Ok, I'll cut you a break from my MOST favorite type of "old" game.

I found when I had a problem that I could solve it by looking
at references (books, http://developer.apple.com, http://www.google.com)
I find A TON of help there....
so you should look around (if you haven't already
)
Global warming is caused by hobos and mooses
Coin Wrote:i looked at the drawDot appl thin in the appkit examples, and in IB they didn't instantiate the DotView, how did they connect the interface to the buttons? and color wells? do i need to make a middleman class?Yes, they do instantiate the dotView. It is the main view in the window, and the color well and slider are attached to it. Look closer at the connections.
Often it is good to instantiate a controller class (or use the nib's owner) to handle the glue logic, but for this simple of an application the view subclass can handle everything via the nib.
ah, yea ok, i was looing for it in the little window with files owner and first responder
It is in that window-- click the icons on the right edge of the window to toggle between icon and list view, then you can examine all of the objects and the connections.
off subject but how do you clear off an NSBezierPath object?
If you mean removing the NSBezierPath's contents (to reuse the alloc'd object), [NSBezierPath removeAllPoints]. See the documentation.
If you mean clearing the canvas after drawing a NSBezierPath (to animate), you have to erase the view with your background color. See the DotView sample code's drawRect method.
If you mean clearing the canvas after drawing a NSBezierPath (to animate), you have to erase the view with your background color. See the DotView sample code's drawRect method.
yea sorry i asked that, i noticed it about .7 seconds after i posted and, forgot to delete/edit it away.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| how to call fathers setNeedsDisplay from child. | iluzone | 5 | 5,564 |
Dec 7, 2006 04:11 AM Last Post: iluzone |
|
| drawRect: is not executed after setNeedsDisplay:YES | Moridin | 7 | 6,694 |
Oct 19, 2005 12:42 AM Last Post: Moridin |
|

