小编Abh*_*nav的帖子

使用[NSBundle mainBundle]写入文件失败

我试图从一个文件中取出内容并将其写入另一个文件.我读得很好,但我无法将其写入另一个文件.

我有一个单词数据库.我想根据字母数将单词分成不同的文件.所有四个字母单词都放在一个文件中,依此类推.我在我的资源中添加了一个名为"4letter"的txt文件,以下是我的代码:

NSError *error;

//READ
NSString *dbFile = [[NSBundle mainBundle] pathForResource:@"words" ofType:@"txt"];
NSString *test = [NSString stringWithContentsOfFile:dbFile encoding:NSUTF8StringEncoding error:&error];

//convert from string to array
NSArray *lines = [test componentsSeparatedByString:@"\n"]; 

NSFileHandle *logFile = nil;
logFile = [NSFileHandle fileHandleForWritingAtPath:[[NSBundle mainBundle] pathForResource:@"4letter" ofType:@"txt"]];

//Test if write works
for (int i=0; i<5; i++) 
{
    NSString *randomAnagram = [[lines objectAtIndex:i] lowercaseString];
    [logFile writeData: [randomAnagram dataUsingEncoding: NSNEXTSTEPStringEncoding]];
}
Run Code Online (Sandbox Code Playgroud)

file-io cocoa-touch objective-c ios

15
推荐指数
4
解决办法
1万
查看次数

如何在Box2D机身上施加恒定力?

我正在为iPhone制作Box2d游戏.我需要对代表我主角的身体施加一个力量.实体实际上是一个圆形顶部的矩形,使用旋转关节连接.我正在使用它作为我的角色的骨架,应该在游戏中运行(任何建议或对此的反馈也将受到赞赏).

我需要一种力量来连续施加,这样才能使他保持活力.最好的方法是什么?

我目前正在tick方法中应用线性速度.

_world->Step(dt, 10, 10);

if(gamestarted)
{
    b2Vec2 force = b2Vec2(6, -3);
    _bottomBody->SetLinearVelocity(force);
}
Run Code Online (Sandbox Code Playgroud)

但是这种力量会不断加起来并加速身体?

iphone box2d

4
推荐指数
1
解决办法
6310
查看次数

标签 统计

box2d ×1

cocoa-touch ×1

file-io ×1

ios ×1

iphone ×1

objective-c ×1