@property float value;
其實就是
- (float)value;
- (void)setValue:(float)newValue;
的宣告(?!)
要在.m檔加上@synthesize value
-----------------------------------------------------------------------------------------------
製作MENU:
CCMenuItemImage *OBJECT = [CCMenuItemImage itemWithNormalImage:@"OBJECT.png" //顯示的
selectedImage:@"OBJECT.png" //操作的
target: self //放在哪裡?!
selector:@selector(FUNC:)]; //點了後要做什麼事
CCMenu *MENU = [CCMenu menuWithItems:OBJECT, nil];
-(void) FUNC:(id)sender{ }
切換Scene:
[[CCDirector sharedDirector]replaceScene:[CCTransitionFlipX transitionWithDuration:1 scene:[SCENE node]]];
移動Sprites:
id Act = XXXXXXX;
id Rac = [Act reverse]; //和Act 恰恰相反
id Seq = [CCSequence actions: Act, Rac, nil ]; //一連串的動作(若一步步執行,會全部黏在一起)
id Spa = [CCSpawn actions: Act, Rac, nil ]; //正統的黏在一起的動作
id Rep = [CCRepeat actionWithAction: Act, times 3];//重複動作
id ReF = [CCRepeatForever actionWithAction: Act];//無限重複
id Eas = [CCEaseInOut actionWithAction: Act, rate 3];//有加速度
[CCJumpBy actionWithDuration:0.2 position:ccp(0,0) height: 200 jumps: 2]//跳躍多少
[CCMoveBy actionWithDuration:0.2 position:ccp(40,20)]//移多少
[CCScaleBy actionWithDuration:0.2 scale:3];//放大多少
ps. 改成To,就會是『變成原來的幾倍』,非『變成現在的幾倍』
//停住他的動作
[miku stopAllActions];
//執行某一動作
[miku runAction:*CCACTION];
-----------------------------------------------------------------------------------------------
製作MAP:
在 .h 檔中
@interface HelloWorldLayer : CCLayer
{
CCTMXTiledMap *theMap;
CCTMXLayer *bgLayer;
}
@property (nonatomic, retain) CCTMXTiledMap *theMap;
@property (nonatomic, retain) CCTMXLayer *bgLayer;
在 .m 檔中
-(id) init
{
if( (self=[super init]) ) {
self.theMap = [CCTMXTiledMap tiledMapWithTMXFile:@"bg.tmx"];
self.bgLayer = [theMap layerNamed:@"BG"];
[self addChild:theMap z:-1]; // z=-1是位在第幾層
}
return self;
}
- (void) dealloc
{
//將他們的記憶體釋放
self.theMap = nil;
self.bgLayer = nil;
[super dealloc];
}
-----------------------------------------------------------------------------------------------
基本非可操控部分:
iphone: 480 * 320
圖:resources
CCSprite *OBJECT;
在 init 裡頭的 if 裡頭
// 印出OBJECT
OBJECT = [CCSprite spriteWithFile: @"OBJECT.png" ];
OBJECT.position = ccp( X座標, Y座標 );
[self addChild: OBJECT];
// 移動OBJECT(依據測試dt為一固定值)
[self schedule:@selector(FUNC:):];
-(void) FUNC:(ccTime) dt{
miku.position = ccp( miku.position.x+A*dt, miku.position.y+B*dt ); // A, B 是常數
}
ps: 依據我的推設,函式打+是在每次都會做,打-則是要被呼叫。
-----------------------------------------------------------------------------------------------
觸控式部分:
#import "CCTouchDispatcher"
//舊的(不贊成使用)
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
//新版(較佳?!)
[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
四種Touch方式:
ccTouchBegan, ccTouchEnded, ccTouchMove, ccTouchCancelled
因為一定要有開始所以一定要加:
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
return YES;
}
當把手移開時要做什麼勒?://得到位置
-(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event{
//一開始得到的POS是UIKit的位置,以左上當(0, 0),但openGL是以左下當(0,0)
CGPoint POS = [touch locationInView:[touch view]];
CGPoint CON = [[CCDirector sharedDirector]convertToGL:POS];
}
沒有留言:
張貼留言