swift - How to add a set of sprites in a certain pattern -


i'm making game has player goes , down if hold screen. not important part though.

what need add enemies, come toward you.

i need know how add enemies in couple of different patterns.

like this:(look @ coins pattern, how can achieve this?)

coins pattern coins without

you define 2-dimensional array indicate coin should e.g.

var coinrow = [[int]]()  coinrow.append([0,1,1,1,1,1,1,0])  // '0' means 'no coin here' coinrow.append([1,1,1,1,1,1,1,1])  // '1' means 'put coin here' coinrow.append([0,1,1,1,1,1,1,0]) 

then treat each coin 'area' 3x8 grid given starting location of bottom-left hand corner (0,0), following:

let coinstart = cgpoint(0,0) coinpos = coinstart row in 0...2 {                       // iterate on rows     column in 0...7 {                // , columns         if coinrow[row][column] == 1 {   // should there coin here?             putcoin(at: coinpos)         // yes - draw 1         }         coinpos.x += coin.width + coinhorizontalseparation  // next coin location         }     coinpos.y += coin.height + coinverticalseparation  // position next row     coinpos.x = coinstart.x                           // reset position start of row } 

you wouldn't actually start @ (0,0), set coinstart required. if groups of coins appear in regular pattern, can calculate coinstart , make code generates block of coins function call, passing coinstart parameter.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -