arrays - Placing a Sprite on an Isometric map and detect if a sprite/object is already present - Swift 2 -


i building tower defense game isometric map. able build map , place walls on map 2d array such:

    let walldata = [[1,0,0,0,0,0,0,0,0,0,0,0],             [0,0,0,0,0,0,0,0,0,0,0,0],             [0,0,0,0,0,0,0,0,0,0,2,0],             [0,0,0,0,0,0,0,0,0,0,0,0],             [0,0,0,0,0,0,0,0,0,0,0,0],             [0,0,0,0,0,0,0,0,0,0,0,0],             [0,0,0,0,0,0,0,0,0,0,0,0],             [0,0,0,0,3,0,0,0,0,0,0,0],             [0,0,0,0,0,0,0,0,0,0,0,0],             [0,0,0,0,0,0,0,0,0,0,0,0],             [0,0,0,0,0,0,0,0,0,0,0,0],             [1,0,0,0,0,0,0,0,0,0,0,0]] 

where 1-3 different walls , 0 grass. should able put towers on grass (i.e. 0) not on walls.

in touchesmoved tower move selection menu , placed on grid touchesended. works fine.

in touchesended using loop loop through nodes in 2d array.

    x in 0..<walldata.count {     y in 0..<walldata[x].count {     if walldata[x][y] != 0 {     let coordinate = tilemap?.position(tilemap.pointforposition(tilemapposition))     tower.removefromparent()     createtower(coordinate!, withsprite: tower, name: tower.name!)     } 

this code still puts towers anywhere want on map.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -