English 中文(简体)
NSObject的 Coco2d列表方法
原标题:Cocos2d schedule method in NSObject

这再次给我带来可可问题。 : D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D. D.

我把我即将到来的游戏作为国家科学学会目标的一个子类。 这一类财产为锡石、锡石和所有 st子。 但现在我有以下问题。

I want to schedule a method for animating the sprite. That action which should be scheduled every second. But because I m using a subclass of NSObject to hold all my data, I cannot use [self schedule:@selector(action:) interval:1.0]. Is there another way? I don t want to use NSTimer, because I then can t you the CCDirector anymore to break the game. It d really be helpful if you could help me. :-D

Sandro Meier

最佳回答

偷渡者,但这里有少数:

  • Subclass CCNode instead of NSObject and call [yourClass schedule: interval:]
  • Expose a simplified selector that internally calls [self.sprite schedule: interval:]
  • Externally call [yourClass.sprite schedule: interval:]
  • Internally call [self.sprite schedule: interval:]
问题回答
//SomeObject.h
@interface SomeObject : NSObject 
{
}
-(void) initObject;
@end    

//SomeObject.m
#import "cocos2d.h"
#import "SomeObject.h"
@implementation SomeObject

-(id) init
{
    return [super init];
}

-(void) initObject
{
    [[CCScheduler sharedScheduler] scheduleUpdateForTarget:self priority:0 paused:NO];
}

-(void) update:(ccTime) dt
{
}

-(void) dealloc
{
    [[CCScheduler sharedScheduler] unscheduleUpdateForTarget:self];
    [super dealloc];
}
@end

并研究这一问题

[[CCScheduler sharedScheduler] scheduleSelector:@selector(ping) forTarget:self interval:2.f paused:NO];

-(void) ping
{
}




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签