yes, this is still way off the mark.. sorry.

I think you should consider starting from a simple app, not trying to integrate with teh existing GameGeek code.

with you init or awake the view, you need to create the layer, and assign it to the view using these in this order



[whicheverView setLayer:[CALayer layer]];
[whicheverView setWantsLayer:YES];
[[whicheverView layer] setDelegate: whicheverView];


this causes you (not the view) to be responsible for providing content.

so, you can then remove the -drawRect there entirely


now add back in your delegate drawing code..

- (void)drawLayer:(CALayer *)theLayer
       inContext:(CGContextRef)theContext {

   CGRect theRect = CGRectMake(0.5, 0.5, 1, 1);
   CGContextSetRGBFillColor(theContext, 1, 0, 1, 1);
   CGContextFillEllipseInRect(theContext, theRect );
}


if you put all this into a single class and try to run it nothing will be displayed. The reason is that you have to tell the layer that it needs to cache its content. You do that by using something like [[whicheverView layer] setNeedsDisplay];

after doing that you should see the ellipse in the layer.


On Apr 15, 2008, at 6:49 PM, Greg Sabo wrote:
I retained the layer object, and now the program no longer crashes! I'll be sure to read up more on retaining objects, as that is clearly an important
concept.

Now just to get the circle to display. I'm not quite sure what you mean by "set the layer to a view to be displayed," which means that I'm probably not
doing that. How would I go about doing this?

Here is the class as it is now:
//*********************************************
#import "GameBoard.h"

@implementation GameBoard

- (id) initWithFrame:(NSRect) frame {
   if (self = [super initWithFrame: frame]) {
       animateLayer = [CALayer layer];
       [animateLayer setDelegate:self];
       [animateLayer retain];
   }
   return self;
}

- (void) awakeFromNib {
   [[self window] setAcceptsMouseMovedEvents: YES];
}

- (BOOL) acceptsFirstResponder {
   return NO;
}

//draws the view
- (void)drawRect:(NSRect)rect {
   [self drawBoardBackgroundInRect:rect];
   [animateLayer setNeedsDisplay];
}

- (void)drawBoardBackgroundInRect:(NSRect)rect {
   [NSBezierPath fillRect:rect];
}

- (void)drawLayer:(CALayer *)theLayer
       inContext:(CGContextRef)theContext {

   CGRect theRect = CGRectMake(0.5, 0.5, 1, 1);
   CGContextSetRGBFillColor(theContext, 1, 0, 1, 1);
   CGContextFillEllipseInRect(theContext, theRect );
}

On Mon, Apr 14, 2008 at 9:23 PM, Michael Vannorsdel <[EMAIL PROTECTED] >
wrote:

In your initWithFrame: method you need to retain the layer object or the autorelease pool may deallocate it. Also, where do you set the layer to a
view to be displayed?


On Apr 14, 2008, at 6:26 PM, Greg Sabo wrote:

I think I'm doing those things, see below:

//Setting object as delegate for CALayer
- (id) initWithFrame:(NSRect) frame {
  if (self = [super initWithFrame: frame]) {
      animateLayer = [CALayer layer];
      [animateLayer setDelegate:self];
  }
  return self;
}

//drawing the view and setting setNeedsDisplay of CALayer to YES
- (void)drawRect:(NSRect)rect {
  [self drawBoardBackgroundInRect:rect];
//whenever this next line is not commented out, the program crashes
  //when I try to resize the window
  [animateLayer setNeedsDisplay];
}

//Implementation of drawLayer: inContext:
- (void)drawLayer:(CALayer *)theLayer
      inContext:(CGContextRef)theContext {

  CGRect theRect = CGRectMake(0.5, 0.5, 1, 1);
  CGContextSetRGBFillColor(theContext, 1, 0, 1, 1);
  CGContextFillEllipseInRect(theContext, theRect );
}

Thanks for your help, you guys are awesome!

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/gregsabo%40gmail.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/scott%40cocoadoc.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to