English 中文(简体)
目标-c-> 电话设计:延迟行动
原标题:Objective-c -> iphone design: delayed action

亲爱双方,但我处在一个小节点,我很想知道,在座各位能否给我一手。

我目前正在设计一场游戏,其中敌人出现在屏幕左边(边界外)并转向右边。 我已经使用了一些法典(这正在使用《巴斯罗尔框架》),而且与你一样,敌人的数量在增加。 i.e. lvl 1-> 1 fundamental, lvl 2-> 2 unilateral, lvl3-> 3 unilateral,...

我对制造敌人感到有些麻烦。 我在5条道路(NSMutableArray的序号)中有1条,由随机生成者选定,但是,他们常常走在同一道路上,1条走在另一条路上。

To produce the enemies, i am running a number of methods: addEnemy -> produces the enemies (animations) which then travel from left to right. onTouchEnemy -> if i touch the enemy, they die. activates drawEnemies drawEnemies -> calls addEnemy a number of times equal to your lvl. coded as:

for(int i = 0; i < level; i++){
  [self performSelector:@selector(addEnemy) withObject:nil afterDelay:3.0];
}

是否有办法进行规划,以便在敌对方的活跃之间出现拖延? 我在Delay之后试图这样做,但出于某种原因,该方案只是忽视了第二次3次拖延,而只是在1年才产生敌人。 这令人不安,因为我希望他们以更加有序的方式出席。

我感谢任何愿意向我伸出援手的人。 Sjkato。

最佳回答

<代码>performSelector:withObject:Delay:, 似乎由于该守则的执行方式而忽视了其延迟。 这种做法将几乎立即进行,把3条电话拨至<编码>addEnemy。 在3秒后,添加后的方法几乎同时执行。

为了取得更好的结果,请看<代码>。 NStimer。 你可以确定3秒的间隔,并告诉大家(在产生预期的敌人数目之后,你会使时间变得无效)。

类似:

// creates and returns a new timer
// the timer is retained by the run loop for as long as it is valid
// invalidating the timer will cause the runloop to release it.
myTimer = [NSTimer scheduledTimerWithTimeInterval:3.0
                                 target:self
                               selector:@selector(addEnemy)
                               userInfo:nil
                                repeats:YES];

这将导致每3秒发射一次的加内米方法。 你们应该把你们已经制造的多少敌人 keep起来,在最后的敌人制造之后,停止时间,以便再次开枪。

if (numberOfDesiredEnemies == numberOfEnemiesProduced)
{
    [myTimer invalidate], timer = nil;
}
问题回答

你们是否打算这样做,最终加上额外的“i”? 与此类似:

for(int i = 0; i < level; i++){
    [self performSelector:@selector(addEnemy) withObject:nil afterDelay:3.0 * i];
}

Try to look through NSTimer class.
There are some methods that provide ability to perform selectors with predefined delay and loop conditions.





相关问题
Python: Binding method

In following example I am trying to bind a method object via types.MethodType(...). It does not seem to work. Any suggestions? Thanks in advance. import types class Base: def payload(self, *args)...

Invoking an instance method without invoking constructor

Let s say I have the following class which I am not allowed to change: public class C { public C() { CreateSideEffects(); } public void M() { DoSomethingUseful(); } } and I have to call M ...

Behaviour of final static method

I have been playing around with modifiers with static method and came across a weird behaviour. As we know, static methods cannot be overridden, as they are associated with class rather than instance....

Setting the Page-Title in .Net using C# from a Class

Question, How do i set the title of a page from a class. Is it even possible? I can and have set the page title from a page itself and a usercontrol. Can I, How Do I do this via a class using C# ....

how to drag in the animation in iphone application?

Iphone application is using the static co-ordinates to reach at some points in the application,which is based on the button event. But what i want is when i drag the item than it should reach at some ...

热门标签