输出一个bool类型:
NSLog(@"ifReadOnly value: %@" ,ifReadOnly?@"YES":@"NO");
Event that is called every time the CCNode enters the 'stage'. If the CCNode enters the 'stage' with a transition, this event is called when the transition starts. During onEnter you can't access a sibling node. If you override onEnter, you shall call [super onEnter].
-(void) onEnter
{
...
}
Schedules a selector that runs only once, with a delay of 0 or larger
[self scheduleOnce:@selector(makeTransition:) delay:0];
//replaceScene:Replaces the running scene with a new one. The running scene is terminated. ONLY call it if there is a running scene.
//CCTransitionFade: Fade out the outgoing scene and then fade in the incoming scene.‘’'
//transitionWithDuration:creates the transition with a duration and with an RGB color Example: [FadeTransition transitionWithDuration:2 scene:s withColor:ccc3(255,0,0)]; // red color
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[HelloWorldLayer scene] withColor:ccRED]];
//Requirements: – Firmware: OS 2.2 or greater – Files: SimpleAudioEngine.,CocosDenshion. – Frameworks: OpenAL, AudioToolbox, AVFoundation
#import "SimpleAudioEngine.h"
//要从随机数说起,调用随机数函数 rand()的时候,实际得到的这个随机数并不是绝对随机的,它是以一个初始值,通过一个算法,计算出来的“伪随机数"数列,每次调用rand()时,从这个数列依次取出一个值,做为随机数。这个初始的值就是"随机数种子",也就是说,如果随机数种子相同,计算出的随机数数列是相同的。而srandom( x) 这个函数就是初始化随机数产生器,设定随机数种子用的。给定的x的就是随机数种子。可以验证,当你多次调用srandm(x)时,如果x取值相同,则得到的随机数数列是一样的。所以,若我们每次运行程序时,要得到不同的随机数序列,就应该用不同的种子来初始化这个随机数产生器。比如说,用时间初始化它,或者用getpid(),用进程的pid号初始化,由于每次运行程序时,它的pid号一般是不同的,所以能够产生不同的随机数序列。
//time():Returns the current calendar time encoded as a time_t object.
//time - pointer to a time_t object to store the time in or NULL
//Current calendar time encoded as time_t object on success, (time_t)(-1) on error. If the argument is not NULL, the return value is equal to the value stored in the object pointed to by the argument.
srandom((unsigned int)time(nil));
//NSIntegerMax:The maximum value for an NSInteger.
mapnode.order = (int)(CCRANDOM_0_1() * NSIntegerMax) % (int)(CCRANDOM_0_1() * NSIntegerMax);
//Returns an array that lists the receiving array’s elements in ascending order, as determined by the comparison method specified by a given selector.
//Parameters
// comparator
// A selector that identifies the method to use to compare two elements at a time. The method should return NSOrderedAscending if the receiving array is smaller than the argument, NSOrderedDescending if the receiving array is larger than the argument, and NSOrderedSame if they are equal.
//Return Value
// An array that lists the receiving array’s elements in ascending order, as determined by the comparison method specified by the selector comparator.
//Discussion
// The new array contains references to the receiving array’s elements, not copies of them.
// The comparator message is sent to each object in the array and has as its single argument another object in the array.
NSArray *sortarray = [array sortedArrayUsingSelector:@selector(myCompare:)];;
连续动画播放
//runAction:Executes an action, and returns the action that is executed. The node becomes the action’s target.
//CCShow:Show the node
id ac = [labelnum1 runAction:[CCShow action]];
//Scales a CCNode object a zoom factor by modifying its scale attribute.
id ac0 = [labelnum1 runAction:[CCScaleBy actionWithDuration:0.5 scale:2]];
id ac1 = [labelnum1 runAction:[CCHide action]];
id ac2 = [labelnum2 runAction:[CCShow action]];
id ac3 = [labelnum2 runAction:[CCScaleBy actionWithDuration:0.5 scale:2]];
id ac4 = [labelnum2 runAction:[CCHide action]];
id ac5 = [labelnum3 runAction:[CCShow action]];
id ac6 = [labelnum3 runAction:[CCScaleBy actionWithDuration:0.5 scale:2]];
id ac7 = [labelnum3 runAction:[CCHide action]];
id ac8 = [labelnum4 runAction:[CCShow action]];
id ac9 = [labelnum4 runAction:[CCScaleBy actionWithDuration:0.5 scale:2]];
id ac10= [labelnum4 runAction:[CCHide action]];
//CCSequence:Runs actions sequentially, one after another
//Delays the action a certain amount of seconds
[labelnum1 runAction:[CCSequence actions:[CCDelayTime actionWithDuration:0.5], ac , ac0, ac1, nil]];
[labelnum2 runAction:[CCSequence actions:[CCDelayTime actionWithDuration:1.0], ac2, ac3, ac4, nil]];
[labelnum3 runAction:[CCSequence actions:[CCDelayTime actionWithDuration:1.5], ac5, ac6, ac7, nil]];
[labelnum4 runAction:[CCSequence actions:[CCDelayTime actionWithDuration:2.0], ac8, ac9, ac10, nil]];
一个拐角的两个点:得出拐角点-----match_direct
两个拐角的两个点:得到一个点的东南西北四个方向所有点之一(循环),然后用这个点去做一个拐点的两个点的计算。
SimpleAudioEngine使用(多个音乐文件循环)
- (void)initSound
{
//sharedEngine:returns the shared instance of the SimpleAudioEngine object
//setBackgroundMusicVolume:Background music volume. Range is 0.0f to 1.0f. This will only have an effect if willPlayBackgroundMusic returns YES
[[SimpleAudioEngine sharedEngine] setBackgroundMusicVolume:0.3f];
//playBackgroundMusic:loop::plays background music, if loop is true the music will repeat otherwise it will be played once
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"back1.mp3" loop:NO];
//sharedManager:Returns the shared singleton
[[CDAudioManager sharedManager] setBackgroundMusicCompletionListener:self selector:@selector(soundFinish1)];
}
- (void)soundFinish1
{
//pauseBackgroundMusic:Pauses the background music
[[SimpleAudioEngine sharedEngine] pauseBackgroundMusic];
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"back2.mp3" loop:NO];
[[CDAudioManager sharedManager] setBackgroundMusicCompletionListener:self selector:@selector(soundFinish2)];
}
- (void)soundFinish2
{
[[SimpleAudioEngine sharedEngine] pauseBackgroundMusic];
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"back3.mp3" loop:NO];
[[CDAudioManager sharedManager] setBackgroundMusicCompletionListener:self selector:@selector(soundFinish1)];
}