我開始將我的java knowlege轉換爲最近的目標c,並開始用xcode製作應用程序。儘管如此,我還是有一些困惑的東西。首先在Java中,當我在做自上而下的遊戲,要拍彈的,我會做到這一點有點像:創建類對象objective c
public class Bullet{
int x,y;
public bullet(double x, double y){
this.x = x;
this.y = y;
}
public void tick(){
//logic goes in here to move bullet
}
}
,那麼我有一類具有一個ArrayList:
public class MainClass{
ArrayList<Bullet> bulletlist;
public main(){
//create an arraylist that takes Bullet objects
bulletlist = new ArrayList<Bullet>();
//add a new bullet at the coordinate (100,100)
bulletlist.add(new Bullet(100,100));
}
//gameloop(we'll pretend that this gets called every millisecond or so)
public void gameloop(){
//loop through list
for(int i = 0; i < bulletlist.size(); i++){
//run the method tick() at the current index
bulletlist.get(i).tick();
}
}
}
所以......我的問題是如何將此代碼轉換爲目標c。或者換句話說,我該如何創建一個類似於創建類的對象的示例中的數組列表,然後通過這個循環並調用一個循環方法或者我在裏面創建的任何方法。
Java和Objective-C是完全不同的語言,具有完全不同的對象模型。 – 2013-05-05 22:45:46
其實我可以轉移我的知識......除此之外,它一直很好。我得到了NSMutableArrays的工作,但我想知道如何添加一個實際的類到該數組。 – 36redsoxfan 2013-05-05 22:49:26
你是什麼意思「添加一個實際的課程」? Objc沒有像Java和C++這樣的泛型,你只需要在它之前添加一個對象,就像在1.5之前的java中那樣,當時沒有泛型。 – Kevin 2013-05-05 22:51:33