1
1
1k8-ru2015-06-15 13:41:59
iOS
1k8-ru, 2015-06-15 13:41:59

Translate code from as3 to swift?


Greetings, please help me to translate this cycle created in as3 to swift
. Thank you in advance.

for (var i:int = 0; i < 13; i++) 
      {
        for (var j:int = 0; j < 12; j++) 
        {
          arrTextureField[i] = new textureField();
          arrTextureField[i].x = arrTextureField[i].width * i+8;
          arrTextureField[i].y = arrTextureField[i].height * j+8;
          self.addChild(arrTextureField[i]);
        }
      }

decided to start with this
var fieldArr = NSArray()

for var i = 0; i < 13; i++ {
   for var j = 0; j <12; j++ {
   fieldArr[i] = SKSpriteNode(imageNamed: "field")
   }
}

but gives error "Cannot assign to the result of this expression"
Why? Why can't I assign an individual sprite to an array? or why can't I create an array from objects?
okay with the array I figured out you need to use NSMutableArray
how now to access the object inside the array?
fieldArr[i] = SKSpriteNode(imageNamed: "field")
fieldArr[i].size = CGSizeMake(20,20)

gives the same error

Answer the question

In order to leave comments, you need to log in

2 answer(s)
1
1k8-ru, 2015-06-16
@1k8-ru

somehow it works strangely, according to the logic of things, it should display everything by coordinates, I checked, they are there,
but it does not display correctly, although each sprite has the coordinates set correctly
, checked the zero element, displays it as expected, checked the 129th element, also puts it in place and
tries to display all the elements, and a strange thing happens, what is the trouble ??
Well, really? why??? I've already broken my whole brain .......
I figured it out, thanks, it's all about indexes))
603e3faaf30a476593349e45b064ce3b.png

A
An, 2015-06-15
@Flanker_4


NSArray and NSMutableArray
are NSFoundation classes, they can be used in Swift, but this is not a good
practice same as you wrote

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question