objective c - Cocoa ScreenSaverView -


i trying play screensaverview in mac os x.

i followed tutorial http://cocoadevcentral.com/articles/000088.php , worked (can't flawlessly ,but worked). saw in part 2 of tutorial playing opengl stuff etc.

i have 2 general questions:

1)can use sprtekit within screensaver view?

2)what wrong code here -> compiles well, don't see except black screen (i want see *.png).

- (instancetype)initwithframe:(nsrect)frame ispreview:(bool)ispreview {     self = [super initwithframe:frame ispreview:ispreview];     if (self)     {         _imageview = [[nsimageview alloc]initwithframe:[self bounds]];         [_imageview setimage:[nsimage imagenamed:@"settingsbutton.png"]];         [self addsubview:_imageview];         [self setanimationtimeinterval:1.0];     }     return self; } 

edit: attempt use draw rect:

- (void)drawrect:(nsrect)rect0 {     [super drawrect:rect0];      nsimage *anotherimage = [nsimage imagenamed:@"settingsbutton.png"];     [anotherimage drawatpoint:nsmakepoint(10,100) fromrect:nsmakerect(0,0,[anotherimage size].width,[anotherimage size].height) operation:nscompositecopy fraction:1.0];       // calculate random color     cgfloat red = ssrandomfloatbetween( 0.0, 255.0 ) / 255.0;     cgfloat green = ssrandomfloatbetween( 0.0, 255.0 ) / 255.0;     cgfloat blue = ssrandomfloatbetween( 0.0, 255.0 ) / 255.0;      nscolor* color = [nscolor colorwithcalibratedred:red                                   green:green                                    blue:blue                                   alpha:1];       nscolor * color2 = [nscolor colorwithpatternimage:anotherimage];     [color2 set];      nsbezierpath * path = [nsbezierpath bezierpathwithrect:rect0];    [path fill]; } 

when set color works , can see screen filled random colors (fine meant)

when use color2 pattern image nothing works :-( -> tried different images same nothing there...

i checked in build phase copy images bundle resources

what problem ?

edit: ok after attempt in drawrect suspected imagenamed method causing troubles , rewrite origin attempt to:

- (instancetype)initwithframe:(nsrect)frame ispreview:(bool)ispreview {     self = [super initwithframe:frame ispreview:ispreview];     if (self)     {         _imageview = [[nsimageview alloc]initwithframe:[self bounds]];         nsbundle * tempbundle = [nsbundle bundleforclass:[self class]];      // load image, "top.tiff". don't forget release when done (not shown).         nsimage * theimage = [[nsimage alloc] initwithcontentsoffile:                           [tempbundle pathforimageresource:@"personal1.jpg"]];         [_imageview setimage:theimage];         [self addsubview:_imageview];         [self setanimationtimeinterval:1.0];      }     return self; } 

and whoaallaaa worked !!(kinda) see picture :-) !!!

as part1 of question -> yes possible tried , works ! little down side can exit screensaver cmd key xd

managed solve issue,by subclassing skview , delivering event next responder.

however gave me huge idea -> opens opportunity make simple sk game part of screensaver have been cute feature.

sadly can't submit app store :)

it's not clear me if spritekit view (skview) can used in normal osx/ios app. have searched in past , found nothing.

if spritekit other game frameworks (from borrows of structure) use traditional game loop; i.e. clear screen, draw everything, wait bit , repeat.

cocoa apps use runloop reacts events , take steps redraw needs redrawn.

so "no" first question.

as far second, code-related, question concerned, cannot see wrong it, not familiar init method; class subclass?


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -