how to check window events?

2 views
Skip to first unread message

Rachel

unread,
Dec 12, 2013, 8:11:05 AM12/12/13
to iosDev...@googlegroups.com
i have a little game im making using the cocos2d framework 
basically i have a target and after it's hit, a points thing pops up.
to get rid of it im using a regular event @selector kind of thing:

[self schedule:@selector(getRidOfMyPoints:) interval:0.7];

but sometimes the target is hit twice in quick succession and the points sign stays up on screen.

i would like to check the window and if this thing is on the screen already,
get rid of it before the next one pops up. but not sure what built in functionality
already exists for this. any goto functions i could call?




briomusic

unread,
Dec 12, 2013, 8:24:06 AM12/12/13
to iosDev...@googlegroups.com
probably better to have a property in your own class like

@property (nonatomic) BOOL scoreIsShowing;

that you set and reset as required. 
scrolling through windows and views and subviews seems inefficient,
and prone to be broken if your (or Apples) view hierarchy ever changes.
if you are fading your score box out with an animation you can use the completion block:

    [UIView animateWithDuration:0.7

                     animations:^{

                         // animation to fade out your score view

                     } completion:^(BOOL finished) {

                         // remove your score view from the view hierarchy

                         self.scoreIsShowing = NO;

                     }]

Oliver Greschke

unread,
Dec 13, 2013, 1:20:15 AM12/13/13
to iosDev...@googlegroups.com
you could either use a BOOL, to detect, if the thing is already on the screen or a concept called "lazy instatiation" - if it's there, do b, if not do a ...

Ullrich Schäfer

unread,
Dec 16, 2013, 3:51:49 AM12/16/13
to iosDev...@googlegroups.com
Another way is something like this:

on Click do:
- (IBAction)click
{
  [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(clickAfterDelay) object:nil];
  [self performSelector:@selector(clickAfterDelay) afterDelay:0.7];

Chris Hardaker

unread,
Dec 16, 2013, 9:09:57 PM12/16/13
to iosDev...@googlegroups.com
Create the score and set an animation going to change the alpha to zero, changing the style to slow in fast out. This will ensure any orphaned points labels are not visible.
A little kludgy but I reserve a "tag space" and maintain a pointer when I have a large number of objects to create on the fly, you can then pass your clearing method the tag number and find it every time. Plus between episodes of the game, you have a finite tag space to clear to ensure there are not missed score objects sitting around.
Reply all
Reply to author
Forward
0 new messages