Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios -Cocos2D中的[[U NSCFConstantString纹理]错误_Ios_Objective C_Cocos2d Iphone - Fatal编程技术网

Ios -Cocos2D中的[[U NSCFConstantString纹理]错误

Ios -Cocos2D中的[[U NSCFConstantString纹理]错误,ios,objective-c,cocos2d-iphone,Ios,Objective C,Cocos2d Iphone,我正在尝试为一个游戏创建精灵动画,当用户点击一个按钮时,它将产生1个单位/敌人,这将在运行的动画中在屏幕上移动。此时,当我运行游戏时,它将开始游戏,一旦我尝试生成一个单位,游戏就会崩溃,并给我一个-[\uu NSCFConstantString texture]:发送到实例0x11a15c的无法识别的选择器错误 这是装置本身的头文件: #import <Foundation/Foundation.h> #import "cocos2d.h" #import "mainGameLaye

我正在尝试为一个游戏创建精灵动画,当用户点击一个按钮时,它将产生1个单位/敌人,这将在运行的动画中在屏幕上移动。此时,当我运行游戏时,它将开始游戏,一旦我尝试生成一个单位,游戏就会崩溃,并给我一个-[\uu NSCFConstantString texture]:发送到实例0x11a15c的无法识别的选择器错误

这是装置本身的头文件:

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "mainGameLayer.h"

@class MainGameLayer, Waypoint, Tower;

@interface Unit : CCSprite {
    CGPoint myPosition;
    int maxHP;
    int currentHP;
    float walkingSpeed;
    Waypoint *destinationWaypoint;
    BOOL active;
    float centerToBottom;
    float centerToSides;
}

@property (nonatomic, assign) MainGameLayer *theGame;
@property (nonatomic, assign) CCSprite *mySprite;
@property (nonatomic, strong) CCAction *walkAction;

+(id) nodeWithTheGame: (MainGameLayer *)_game;
-(id) initWithTheGame: (MainGameLayer *)_game;
-(void) doActivate;
-(void) getRemoved;

@end
#导入
#导入“cocos2d.h”
#导入“mainGameLayer.h”
@类主游戏层、航路点、塔;
@接口单元:CCSprite{
CGPoint-myPosition;
int-maxHP;
int-currentHP;
漂浮行走速度;
航路点*目的航路点;
布尔活跃;
浮动中心至底部;
浮动中心侧;
}
@属性(非原子,分配)主游戏层*游戏;
@属性(非原子,赋值)CCSprite*mySprite;
@属性(非原子,强)cAction*walkAction;
+(id)在游戏中点头:(主游戏玩家*)\u游戏;
-(id)使用游戏初始化:(主游戏层*)\u游戏;
-(无效)未激活;
-(无效)被删除;
@结束
下面是实现文件。“self=super initWithPriteFrame”行当前抛出一条警告,指出“不兼容的指针类型正在将NSString*发送到类型为“CCSpriteFrame*”的参数”

此外,“CCSprite*frame=[[ccspriterameche…”行还抛出另一条警告,指出“标志0导致p转换说明符的未定义行为

#import "Unit.h"
#import "Tower.h"
#import "Waypoint.h"

#define HEALTH_BAR_WIDTH 20
#define HEALTH_BAR_ORIGIN -10

@implementation Unit

@synthesize mySprite, theGame;

+(id) nodeWithTheGame:(MainGameLayer *)_game
{
    return [[self alloc] initWithTheGame:_game];
}

-(id) initWithTheGame:(MainGameLayer *)_game
{
    if ((self = [super initWithSpriteFrame:@"hero_walk_00.png"])) {
        theGame = _game;
        maxHP = 40;
        currentHP = maxHP;
        active = FALSE;
        walkingSpeed = 0.5;
        centerToBottom = 39.0;
        centerToSides = 29.0;

        CCArray *walkFrames = [CCArray arrayWithCapacity: 8];

        for (int i = 0; i < 8; i++) {
            CCSprite *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"hero_walk_%02.png", i]];
            [walkFrames addObject: frame];
        }

        CCAnimation *walkAnimation = [CCAnimation animationWithSpriteFrames:[walkFrames getNSArray] delay:1.0/12.0];
        self.walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnimation]];

        Waypoint *waypoint = (Waypoint *)[theGame.waypoints objectAtIndex:([theGame.waypoints count]-1)];
        destinationWaypoint = waypoint.nextWaypoint;

        CGPoint pos = waypoint.myPosition;
        myPosition = pos;

        [mySprite setPosition: pos];
        [theGame addChild: self];

        [self scheduleUpdate];
    }

    return self;
}

-(void) doActivate
{
    active = TRUE;
}

-(void)  update:(ccTime)dt
{
    if (!active) {
        return;
    }

    if ([theGame circle:myPosition withRadius:1 collisionWithCircle:destinationWaypoint.myPosition collisionCircleRadius:1]) {
        if (destinationWaypoint.nextWaypoint) {
            destinationWaypoint = destinationWaypoint.nextWaypoint;
        } else {
            [theGame getHpDamage];
            [self getRemoved];
        }
    }

    CGPoint targetPoint = destinationWaypoint.myPosition;
    float movementSpeed = walkingSpeed;

    CGPoint normalized = ccpNormalize(ccp(targetPoint.x - myPosition.x, targetPoint.y - myPosition.y));
    mySprite.rotation = CC_RADIANS_TO_DEGREES(atan2(normalized.y, -normalized.x));

    myPosition = ccp(myPosition.x + normalized.x * movementSpeed, myPosition.y + normalized.y * movementSpeed);

    [mySprite setPosition: myPosition];
}

-(void) getRemoved
{
    [self.parent removeChild:self cleanup:YES];
    [theGame.units removeObject: self];

    // Notify the game that we killed an enemy so we can check if we can send another wave
    [theGame enemyGotKilled];
}

-(void) draw
{
    ccDrawSolidRect(ccp(myPosition.x + HEALTH_BAR_ORIGIN, myPosition.y + 16), ccp(myPosition.x + HEALTH_BAR_ORIGIN + HEALTH_BAR_WIDTH, myPosition.y + 14), ccc4f(1.0, 0, 0, 1.0));

    ccDrawSolidRect(ccp(myPosition.x + HEALTH_BAR_ORIGIN, myPosition.y + 16), ccp(myPosition.x + HEALTH_BAR_ORIGIN + (float)(currentHP * HEALTH_BAR_WIDTH)/maxHP, myPosition.y + 14), ccc4f(0, 1.0, 0, 1.0));
}

@end
#导入“Unit.h”
#导入“Tower.h”
#导入“航路点.h”
#定义健康条宽度20
#定义健康条形图原点-10
@执行单位
@合成mySprite,游戏;
+(id)在游戏中点头:(主游戏玩家*)\u游戏
{
return[[self alloc]initWithTheGame:_game];
}
-(id)使用游戏初始化:(主游戏层*)\u游戏
{
if((self=[super initWithSpriteFrame:@“hero\u walk\u 00.png]”){
游戏=_游戏;
maxHP=40;
currentHP=maxHP;
主动=假;
步行速度=0.5;
centerToBottom=39.0;
中心侧=29.0;
cArray*walkFrames=[cArray阵列容量:8];
对于(int i=0;i<8;i++){
CCSprite*frame=[[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:[NSString stringWithFormat:@“hero_walk_%02.png”,i]];
[walkFrames添加对象:帧];
}
cAnimation*walkAnimation=[cAnimation Animation WithPriteFrames:[walkFrames getNSArray]延迟:1.0/12.0];
self.walkAction=[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:WalkanAnimation]];
航路点*航路点=(航路点*)[theGame.waypoints对象索引:([theGame.waypoints计数]-1];
destinationWaypoint=航路点.nextWaypoint;
CGPoint pos=航路点.myPosition;
myPosition=pos;
[mySprite设置位置:pos];
[游戏添加孩子:自我];
[自计划更新];
}
回归自我;
}
-(无效)激活
{
主动=真;
}
-(无效)更新:(ccTime)dt
{
如果(!活动){
返回;
}
if([游戏圆:我的位置和半径:1碰撞圆:目的航路点。我的位置碰撞圆半径:1]){
if(目的航路点.下一个航路点){
destinationWaypoint=destinationWaypoint.nextWaypoint;
}否则{
[游戏受到伤害];
[自行删除];
}
}
CGPoint targetPoint=destinationWaypoint.myPosition;
浮动移动速度=行走速度;
CGPoint normalized=ccpNormalize(ccp(targetPoint.x-myPosition.x,targetPoint.y-myPosition.y));
mySprite.rotation=CC_弧度_到_度(atan2(normalized.y,-normalized.x));
myPosition=ccp(myPosition.x+归一化.x*移动速度,myPosition.y+归一化.y*移动速度);
[mySprite setPosition:myPosition];
}
-(无效)删除
{
[self.parent removeChild:self cleanup:YES];
[theGame.units移除对象:self];
//通知游戏我们杀死了一个敌人,这样我们就可以检查我们是否可以发送另一个波
[敌人被杀死的游戏];
}
-(作废)提款
{
ccDrawSolidRect(ccp(myPosition.x+健康条形图原点,myPosition.y+16)、ccp(myPosition.x+健康条形图原点+健康条形图宽度,myPosition.y+14)、ccc4f(1.0,0,0,1.0));
ccDrawSolidRect(ccp(myPosition.x+健康条形图原点,myPosition.y+16),ccp(myPosition.x+健康条形图原点+(浮点)(当前HP*健康条形图宽度)/maxHP,myPosition.y+14),ccc4f(0,1.0,0,1.0));
}
@结束
以下是主游戏层的头文件:

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

@interface MainGameLayer : CCLayer {
    CCSpriteBatchNode *_actors;
}

+ (CCScene *) scene;
- (BOOL) circle:(CGPoint)circlePoint withRadius:(float)radius collisionWithCircle:(CGPoint)circlePointTwo collisionCircleRadius:(float)radiusTwo;
void ccFillPoly (CGPoint *poli, int points, BOOL closePolygon);
- (void) enemyGotKilled;
- (void) getHpDamage;

@property (nonatomic, strong) NSMutableArray *towers;
@property (nonatomic, strong) NSMutableArray *waypoints;
@property (nonatomic, strong) NSMutableArray *units;

@end
#导入
#导入“cocos2d.h”
@接口MainGameLayer:CCLayer{
CCSpriteBatchNode*\u参与者;
}
+(场景*)场景;
-(BOOL)circle:(CGPoint)circlePoint with radius:(float)radius碰撞with circle:(CGPoint)circlePoint两个碰撞circleradius:(float)radius两个;
void ccFillPoly(CGPoint*poli、int点、BOOL闭合多边形);
-(无效)灌肠致死;
-(无效)造成损害;
@属性(非原子,强)NSM可变阵列*塔;
@属性(非原子,强)NSMutableArray*航路点;
@属性(非原子,强)NSMutableArray*单位;
@结束
以及实施文件:

#import "MainGameLayer.h"
#import "Tower.h"
#import "Waypoint.h"
#import "Unit.h"


@implementation MainGameLayer

@synthesize towers;
@synthesize waypoints;
@synthesize units;

+ (CCScene *) scene
{
    CCScene *scene = [CCScene node];

    MainGameLayer *layer = [MainGameLayer node];

    [scene addChild: layer];

    return scene;
}

- (id) init
{
    if ((self = [super init])) {
        // Initialize
        self.isTouchEnabled = TRUE;
        CGSize winSize = [CCDirector sharedDirector].winSize;

        // Setting the background (Map)
        CCSprite *background = [CCSprite spriteWithFile:@"layout.png"];
        [self addChild: background];
        [background setPosition: ccp(winSize.width/2, winSize.height/2)];

        [self addWaypoints];

        // In Game Buttons / Menu
        CCMenuItem *sampleButton = [CCMenuItemImage itemWithNormalImage:@"sample.jpg" selectedImage:@"sample.jpg" target:self selector:@selector(samplePurchased:)];

        CCMenu *PurchaseUI = [CCMenu menuWithItems:sampleButton, nil];
        [PurchaseUI setScale:0.5];
        [PurchaseUI setPosition:ccp(63, 51)];
        [PurchaseUI alignItemsHorizontally];
        PurchaseUI.isTouchEnabled = TRUE;
        [self addChild: PurchaseUI];

        // Set up the sprite sheets (Currently in testing)
        [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"pd_sprites.plist"];
        _actors = [CCSpriteBatchNode batchNodeWithFile:@"pd_sprites.pvr.ccz"];
        [_actors.texture setAliasTexParameters];
        [self addChild: _actors];
    }

    return self;

}

-(BOOL) canBuyTower
{
    return YES;
}

-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInView: [touch view]];

        location = [[CCDirector sharedDirector] convertToGL: location];
        CCLOG(@"X: %f Y: %f", location.x, location.y);

        if ([self canBuyTower]) {
            // Spend the gold later
            Tower *tower = [Tower nodeWithTheGame:self location: location];
            [towers addObject: tower];
        }
    }
}

-(void) addWaypoints
{
    waypoints = [[NSMutableArray alloc] init];

    Waypoint * waypoint1 = [Waypoint nodeWithTheGame:self location:ccp(-25,360)];
    [waypoints addObject:waypoint1];

    Waypoint * waypoint2 = [Waypoint nodeWithTheGame:self location:ccp(73,360)];
    [waypoints addObject:waypoint2];
    waypoint2.nextWaypoint =waypoint1;

    Waypoint * waypoint3 = [Waypoint nodeWithTheGame:self location:ccp(467,360)];
    [waypoints addObject:waypoint3];
    waypoint3.nextWaypoint =waypoint2;

    Waypoint * waypoint4 = [Waypoint nodeWithTheGame:self location:ccp(905,360)];
    [waypoints addObject:waypoint4];
    waypoint4.nextWaypoint =waypoint3;

    Waypoint * waypoint5 = [Waypoint nodeWithTheGame:self location:ccp(1050,360)];
    [waypoints addObject:waypoint5];
    waypoint5.nextWaypoint =waypoint4;
}

-(BOOL) circle:(CGPoint)circlePoint withRadius:(float)radius collisionWithCircle:(CGPoint)circlePointTwo collisionCircleRadius:(float)radiusTwo
{
    float xdif = circlePoint.x - circlePointTwo.x;
    float ydif = circlePoint.y - circlePointTwo.y;

    float distance = sqrt(xdif*xdif + ydif*ydif);

    if (distance <= radius + radiusTwo) {
        return TRUE;
    }

    return FALSE;
}

-(void) samplePurchased: (id)sender
{
    Unit *tempUnit = [Unit nodeWithTheGame: self];
    [units addObject: tempUnit];
    [tempUnit doActivate];
}

@end
#导入“MainGameLayer.h”
#导入“Tower.h”
#导入“航路点.h”
#输入“单位h”
@主游戏层的实现
@合成塔;
@综合航路点;
@合成单元;
+(场景*)场景
{
CCScene*scene=[CCScene节点];
MainGameLayer*层=[MainGameLayer节点];
[场景添加子对象:层];
返回场景;
}
-(id)init
{
if((self=[super init])){
//初始化
self.isTouchEnabled=TRUE;
CGSize winSize=[CCDirector sharedDirector].winSize;
//设置背景(地图)
CCSprite*background=[CCSprite spriteWithFile:@“layout.png”];
[自我添加孩子:背景];
[背景设置位置:ccp(winSize.width/2,winSize.height/2)];
[自添加航路点];
//游戏中的按钮/菜单
CCMenuItem*sampleButton=[CCMenuItemImage itemWithNormalImage:@”样本。
[super initWithSpriteFrame:@"hero_walk_00.png"]
[super initWithSpriteFrameName:@"hero_walk_00.png"]
CCSprite *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] 
             spriteFrameByName:[NSString stringWithFormat:@"hero_walk_%02.png", i]];
CCSpriteFrame *frame = ...