I was creating a small test script to convert the
example tile map to python, but I came across a problem. This is my code so far (it can contain other errors, I haven't made it work yet):
01 vertices = sf.VertexArray(sf.PrimitiveType.QUADS)
02
03 def createVertices(tiles, w, h):
04 global vertices
05 vertices.resize(w * h * 4)
06
07 for i in xrange(w):
08 for j in xrange(h):
09 tile = tiles[i + j*w];
10
11 tu = tile % (tileset.width / TS) # TS is tilesize
12 tv = tile / (tileset.width / TS)
13
14 quad = vertices[ (i+j*w) * 4 ]
15 print quad
16 # ^ <sfml.graphics.Vertex object at 0x0225A1F0>
17
18 # positioning
19 quad[0].position = sf.Vector2( i*TS, j*TS )
20 # ^ TypeError: 'sfml.graphics.Vertex' object does not support indexing
21
22 quad[1].position = sf.Vector2( (i+1)*TS, j*TS )
23 quad[2].position = sf.Vector2( (i+1)*TS, (j+1)*TS )
24 quad[3].position = sf.Vector2( i*TS, (j+1)*TS )
25
26 # tex coords
27 quad[0].tex_coords = sf.Vector2( tu*TS, tv*TS )
28 quad[1].tex_coords = sf.Vector2( (tu+1)*TS, tv*TS )
29 quad[2].tex_coords = sf.Vector2( (tu+1)*TS, (tv+1)*TS )
30 quad[3].tex_coords = sf.Vector2( tu*TS, (tv+1)*TS )
On line 14 I get a vertex back from that assignment while in the example they get an array of vertices. I'm a bit confused. How do I get the quads then?