Objective c 不要移动我的船

Objective c 不要移动我的船,objective-c,ios,cocos2d-iphone,Objective C,Ios,Cocos2d Iphone,我的船出现在图层上。当按下发射按钮时,飞船应该移动到一个计算出的位置。检测到触碰,坐标计算正确,但船不会移动。我已经阅读了这个论坛上关于runAction的500+Q和A,但没有任何帮助。我还重新启动了Xcode并清理了目标 以下是ShipManager的界面: #import <Foundation/Foundation.h> #import "Common.h"//imports cocos2d.h @interface ShipManager : NSObject {

我的船出现在图层上。当按下发射按钮时,飞船应该移动到一个计算出的位置。检测到触碰,坐标计算正确,但船不会移动。我已经阅读了这个论坛上关于runAction的500+Q和A,但没有任何帮助。我还重新启动了Xcode并清理了目标

以下是ShipManager的界面:

#import <Foundation/Foundation.h>
#import "Common.h"//imports cocos2d.h

@interface ShipManager : NSObject {
    GameLayer *layer;
    CCSprite *ship;
    ...
    NSArray *shipTargetArray;
    CCArray *shipArray;
    int podValue;
    int podKey;
    int topPod;
    int botPod;
    float x;
    float y;    
}

@property (nonatomic, retain) CCSprite *ship;
@property (nonatomic, retain) CCSprite *pod;
...

-(id)initWith:(GameLayer *)gameLayer;
-(void)updateShip;
-(void)resetShip;
-(void)touchedExtinguishButton;    
@end
#导入
#导入“Common.h”//imports cocos2d.h
@接口ShipManager:NSObject{
游戏层*层;
CCSprite*船;
...
NSArray*shipTargetArray;
CCArray*船舶阵列;
int值;
intpodkey;
int托普德;
int-botPod;
浮动x;
浮动y;
}
@财产(非原子,保留)CCSprite*船;
@属性(非原子,保留)CCSprite*pod;
...
-(id)initWith:(GameLayer*)GameLayer;
-(无效)更新IP;
-(b)重置船舶;
-(无效)触摸Extinguish按钮;
@结束
实施文件的部分内容:

#import "ShipManager.h"
#import "PodGroupManager.h"
#import "GameLayer.h"   

@implementation ShipManager

@synthesize ship;
...

int loadState;

//LAUNCH SHIP
-(void)launchShip {
    NSNumber *theTarget;
    CGPoint targetPosition;
    int shipTarget = absInt(topPod * botPod);

    theTarget = [NSNumber numberWithInt:shipTarget];
    NSInteger targetIndex = [shipTargetArray indexOfObject:theTarget];
    NSLog(@"target = %i; index = %i",shipTarget,targetIndex);//LOG:target = 20; index = 12

    self.ship = [shipArray objectAtIndex:0];//NEW CODE. 
    NSLog(@"ship tag = %i",ship.tag);//LOG:ship tag = 100
    NSLog(@"%@",shipArray);//LOG" <CCArray = 055209A0> = ( <CCSprite = 05520A40 | Rect = (2.00,2.00,148.00,200.00) | tag = 100 | atlasIndex = 10>, )

    x = ship.position.x;
    y = ship.position.y + 10 +34 * targetIndex;

    targetPosition = ccp(x,y);
    NSLog(@"target x = %f; y = %f",x, y);//LOG: target x = 384.000000; y = 754.000000

    //WHAT I WANT THE SHIP TO DO
    id action = [CCSequence actions:
              [CCMoveTo actionWithDuration:1.0f position:targetPosition],
              [CCDelayTime actionWithDuration:1.0f],
              [CCMoveTo actionWithDuration:.05f position:SHIP_START_POS],
              nil];
    [ship runAction:action];//SHIP DOES NOT MOVE*/
    //ALSO TRIED: [self.ship runAction:action]; NO MOVEMENT

    //ABOVE NOT WORKING -- TRYING SIMPLER MOVE
    //CCMoveTo* move = [CCMoveTo actionWithDuration:1.0f position:targetPosition];
    //[ship runAction:move]; //TRYING SIMPLER ACTION - STILL NO MOVEMENT


    //JUST TRYING TO GET THE SHIP THERE
    //ship.position = targetPosition; //NO MOVEMENT EITHER

    if (missionState == SHIP_EXT) {
        NSLog(@"extinguish fuse");//logs button press correctly
    }       
}
...
//RESET SHIP TO LAUNCHING PAD
-(void)resetShip {
    ship.position = SHIP_START_POS;
    [self setShipState:SHIP_EMPTY];
    [self setMissionState:SHIP_IDLE];
    ship.visible = YES;
}

//SETUP SHIP
-(void) setupShip {
    shipArray  = [[CCArray alloc]initWithCapacity:1];//just added - latest attempt
    ship = [CCSprite spriteWithSpriteFrameName:@"ship.png"];

    [layer.batchNode addChild:ship z:SHIP_Z tag:SHIP_TAG];
    [shipArray addObject:ship];//just added - latest attempt
    [self resetShip];       
}
...
//INITIALIZE SHIPMANAGER
-(id)initWith:(GameLayer *)gameLayer {
    if ((self = [super init]) ) {
        layer = gameLayer;
        [self setupShip];
        ...         
        [self setTopPod:0];
        [self setBotPod:0];

        //MAKE SHIPTARGET ARRAY
        shipTargetArray = [[NSArray alloc] initWithObjects:
                           [NSNumber numberWithInt:1],
                           ...
                           [NSNumber numberWithInt:25],
                           nil];
    }    
    return self;
}

-(void) dealloc {

    [shipTargetArray release];
    [shipArray release];
    self.ship = nil;

    [super dealloc];
}    
@end
#导入“ShipManager.h”
#导入“PodGroupManager.h”
#导入“GameLayer.h”
@实施ShipManager
@综合船舶;
...
int-loadState;
//发射舰
-(无效)发射船{
NSNumber*目标;
CGPoint目标位置;
int shipTarget=absInt(顶部*底部);
目标=[NSNumber Number Withint:shipTarget];
NSInteger targetIndex=[shipTargetArray索引对象:目标];
NSLog(@“target=%i;index=%i”,shipTarget,targetIndex);//LOG:target=20;index=12
self.ship=[shipArray objectAtIndex:0];//新代码。
NSLog(@“ship tag=%i”,ship.tag);//LOG:ship tag=100
NSLog(@“%@”,shipArray);//LOG“=(,)
x=船舶位置x;
y=船舶位置y+10+34*目标指数;
目标位置=ccp(x,y);
NSLog(@“target x=%f;y=%f”,x,y);//LOG:target x=384.000000;y=754.000000
//我想让船做什么
id action=[CCO序列操作:
[CCMoveTo ACTION WITH DUCTION:1.0f位置:targetPosition],
[CCDelayTime actionWithDuration:1.0f],
[CCMoveTo操作持续时间:.05f位置:发货\u开始\u位置],
零];
[船舶运行操作:操作];//船舶不移动*/
//也尝试过:[self.ship runAction:action];没有移动
//上面没有工作--尝试更简单的移动
//CCMoveTo*move=[CCMoveTo actionWithDuration:1.0f position:targetPosition];
//[ship runAction:move];//尝试更简单的操作-仍然没有移动
//只是想把船开到那里
//ship.position=targetPosition;//也不移动
如果(任务状态==发货时间){
NSLog(@“熄灭保险丝”);//记录按钮按下是否正确
}       
}
...
//将船舶重置为发射台
-(无效)重置船舶{
ship.position=ship\u START\u POS;
[自设置发货状态:发货为空];
[自我设置任务状态:船舶闲置];
ship.visible=是;
}
//安装船
-(无效)船舶{
shipArray=[[CCArray alloc]initWithCapacity:1];//刚刚添加-最新尝试
ship=[CCSprite spritewithpriteframename:@“ship.png”];
[layer.batchNode addChild:ship z:ship_z标记:ship_标记];
[shipArray addObject:ship];//刚刚添加-最新尝试
[自我重置];
}
...
//初始化SHIPMANAGER
-(id)initWith:(GameLayer*)GameLayer{
if((self=[super init])){
层=游戏层;
[自建船舶];
...         
[self-setTopPod:0];
[self-setBotPod:0];
//制作目标阵列
shipTargetArray=[[NSArray alloc]initWithObjects:
[NSNumber numberwhithint:1],
...
[NSNumber NUMBER WITHIN:25],
零];
}    
回归自我;
}
-(无效)解除锁定{
[ShipTargetAray发布];
[船舶阵列发布];
self.ship=零;
[super dealoc];
}    
@结束
我知道正在执行launchShip方法,因为所有NSLog都按预期打印,结果都是正确的。我在launchShip中尝试了3种不同的选项,并依次对它们进行注释/取消注释,以查看是否有任何工作—无任何工作。
我是Objective-c和cocos2d的新手,我怀疑问题在于我试图告诉runAction运行操作的方式。我确信有一种方法可以正确发送消息,如果您能以正确的方式提供帮助,我们将不胜感激。
提前感谢您的帮助

在船舶下水之前,将2个燃料舱装载到船舶上。燃料舱具有数值。这些数值确定船舶的目标目的地。所有这些都在工作。燃料舱已装载并计算出正确的目的地

ship = [shipArray objectAtIndex:0];
此分配将不会保留。请将其更改为

self.ship = [shipArray objectAtIndex:0];
在后面的dealoc方法中

self.ship = nil;

释放它。对其他变量(
shipTargetArray
shipArray
)也一样处理。

谢谢您的响应。尝试过了,仍然不起作用。还有其他想法吗?@JoAnnC您能将代码更新到当前状态吗?并显示一些NSLog输出吗?