我有这个游戏,例如doodlejump
我在播放器上插入了一些怪物和子弹
玩家发射子弹并删除目标
我向两者都插入了一个nslog,所以我知道子弹是否发射了并且目标显示了
模拟器ios 4.0中一切正常
但是每次我在设备上安装它时
子弹和目标似乎没有出现(是的,只有这两个游戏仍然运行平稳)
但是每次我检查控制台时,我都可以看到项目符号和目标的nslog
我在3种不同的手机ios 4.0、5.0和4.2上尝试过
现在我很困惑,如果这似乎是问题
我在Google上检查了同样的问题,但我似乎找不到一个
我还检查了拼写和小问题,但仍然在发生。
似乎是什么引起了这个问题?
PS:我正在开发的应用程序已经过时,它是COCOS2d的旧版本。做这个
影响吗?我尝试升级,但是我有很多错误,我没有
知道那就是为什么我回到默认值。
怪物出现约0.5秒,然后突然消失是因为spriteMoveFinished吗?
以下是代码(目标):
-(void)addTarget {
Sprite *target =[Sprite spriteWithFile:@"him.png"];
CGSize winSize = [[Director sharedDirector]winSize];
int minX = winSize.width/6;
int maxX = winSize.width - target.contentSize.width/2;
int rangeX = maxX - minX;
int actualX = (arc4random() % rangeX) + minX;
target.position = ccp(actualX,500);
NSLog(@"Location:%f",target.position);
[self addChild:target];
int minDuration = 2.0; int maxDuration = 4.0;
int rangeDuration = maxDuration - minDuration;
int actualDuration = (arc4random() % rangeDuration)+minDuration;
id actionMove = [MoveTo actionWithDuration:actualDuration position:ccp(actualX, -target.contentSize.height/2)];
id actionMoveDone = [CallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
[target runAction:[Sequence actions:actionMove,actionMoveDone, nil]];
target.tag = 1;
[_targets addObject:target];
}
(项目符号):
-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
AtlasSpriteManager *spriteManager = (AtlasSpriteManager*)[self getChildByTag:kSpriteManager];
AtlasSprite *bird = (AtlasSprite*)[spriteManager getChildByTag:kBird];
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
location = [[Director sharedDirector]convertCoordinate:location];
Sprite *projectile = [Sprite spriteWithFile:@"psn.png"];
projectile.position = ccp(bird.position.x,bird.position.y);
CGSize winSize = [[Director sharedDirector]winSize];
int offX = location.x - projectile.position.x;
int offY = location.y - projectile.position.y;
[self addChild:projectile];
float scalarX = 1.0f;
if(offX < 0.0f) scalarX = -1.0f;
int realX = scalarX * (winSize.width + (projectile.contentSize.width/2));
float ratio = (float) offY / (float) offX;
int realY = (realX *ratio) +projectile.position.y;
CGPoint realDest = ccp(realX,realY);
int offRealX = realX - projectile.position.x;
int offRealY = realY - projectile.position.y;
float length = sqrtf((offRealX*offRealX)+(offRealY*offRealY));
float velocity = 480/1;
float realMoveDuration = length/velocity;
[projectile runAction:[Sequence actions:[MoveTo actionWithDuration:realMoveDuration position:realDest],
[CallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)], nil]];
NSLog(@"Shoot!");
projectile.tag = 2;
[_projectiles addObject:projectile];
}
谢谢,我希望这会解决...
最佳答案
奇。可以快速尝试的事情是:
从设备本身中删除该应用程序(按住应用程序图标,直到出现“ x”并删除它),然后进行干净的构建。这将强制在电话上替换所有资产。
您是否启用了视网膜支持?如果是这样,您的资源中是否有一个名为“ him-hd.png”的文件已损坏?如果检测到视网膜设备,它将首先尝试加载该设备。
它在视网膜设备的模拟器上是否失败?您可以在iOSSimulator菜单栏中更改要模拟的设备。
将图像添加到项目时,是否选择了“将项目复制到目标组的文件夹(如果需要)”?这很重要,因为否则图像将不包含在包装中
最后,您是否检查了图像的目标成员身份,以便将其设置为应用程序目标?您可以通过在xCode中选择图像并查看File Inspector-> Target Membership来检查它。您的应用程序旁边应有一个检查。