dポイントプレゼントキャンペーン実施中!

調べてみたところ、NSTimerと言う関数を見つけて
0.05fずつ反応する媒体が出来ました。

-(id)init{

timer = [NSTimer
scheduledTimerWithTimeInterval:0.05f
target:self
selector:@selector(timetime:)
userInfo:nil
repeats:YES
];

return self;
}

-(void)timetime:(NSTimer *)time{i++;
NSLog(@"この機能を利用してノベル風テキスト出力をしたいです");
}

コレを利用してノベルゲーム風に1文字ずつ表示したいのですが、
何か方法はありませんか?

A 回答 (1件)

あまり詳しくはないのですが、UILabelを使って実装してみました。



@implementation MyViewController
UILabel *label;

- (void)viewDidLoad
{
[super viewDidLoad];

label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 30)];
[self.view addSubview:label];
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timetime:) userInfo:@"メッセージメッセージメッセージ" repeats:YES];
}

-(void)timetime:(NSTimer *)time
{
static int i;
NSString *message = time.userInfo;
label.text = [message substringToIndex:i];
if(message.length <= i){
[time invalidate];
i=0;
return;
}
i++;
}

@end

ノベルゲーム「風」に1文字ずつ出ると思います。
本当にノベルゲームを作るのであれば、複数行やスキップなど
色々問題がありそうですね。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!