SFML community forums

Bindings - other languages => Python => Topic started by: C with a C on July 25, 2017, 11:11:07 pm

Title: Can't copy VertexArrays with slice notation?
Post by: C with a C on July 25, 2017, 11:11:07 pm
I tried making a copy of a vertex array using the slice notation...
textLayer = extraTextBuffer[:]

... and this is what happens:
#  File "graphics.pyx", line 1587, in sfml.graphics.VertexArray.__getitem__ (src/sfml\graphics.cpp:26182)
#  TypeError: an integer is required

I'm confused as to why this happens. (EDIT: Probably because VertexArrays are not python Lists! I realized later.)

I want to copy the array by value, and I can copy it by iterating through it, but that's quite a slow process (because the array is BIG). My goal was to check if using slice notation was significantly faster or not.

Basically my idea here is to have a vertex array with default values (colors and tex_coords), and simply use it to "clear" the one I'm using every frame. I'm doing this to test how it might affect performance. Iterating through a vertexarray and reseting all the vertices is also a rather slow process. Perhaps even slower than copying vertices from another array.

Simply copying like
array1 = array2
seems to copy them by reference, as it would a python list.