Okay, so I am copying a game that I have wrote in android studios over to swift for ios. I have figured out a lot of the syntax difference, but there is still some stuff that I cannot figure out. I will post the swift code first, then I will post the java code to compare with, and finally I will explain what is supposed to be happening:
func set(t: Int){
_type = 0; //For debugging otherwise equal to t
delay = 0;
current = 0;
last = 0;
count = 0;
switch (_type){
case 0:
pt = Array<normal>();
let p1 = normal(bpc: self, gameScene: gm);
let p2 = normal(bpc: self, gameScene: gm);
let p3 = normal(bpc: self, gameScene: gm);
length = 3; //for array length
pt?.append(p1);
pt?.append(p2);
pt?.append(p3);
hit = Array<Bool>();
hit?.append(false);
hit?.append(false);
hit?.append(false);
break;
Now for the equivalent java code which works:
void set(int t){
_type = t;
delay = 0;
current = 0;
last = 0;
count = 0;
switch (_type){
case 0:
pt = new normal[3];
hit = new boolean[3];
for (int i = 0; i < 3; i++){
pt[i] = new normal();
hit[i] = false;
}
break;
So The bottom code is the code in my android game that works. The code above is the code that I am trying to make work the same way, but I seem to be having problems with the array of object stuff. Also, I have the pt declared above as :
private var pt : [Poop_Type]?;
and java equivalent is:
private Poop_Type pt[];