create a circle with python in blender game

Hello! I’ve got a problem with a python code I normally used in Blender Render.

With the code I create a circle and change the location of the vertices to coordinates I saved in a list. In Blender Render this works perfect.

here you can see the code:



bpy.ops.mesh.primitive_circle_add(vertices = a-1, fill_type = 'NGON')

i = 0
while (i < a):
    x = listx[i+1]
    y = listy[i+1]
        
    context=bpy.context
    
    
    for obj in context.selected_objects:
        obj.location = (0,0,-0.02)
        
        if obj.type=='MESH':
            for v in obj.data.vertices[i:(i+1)]:
                v.co = x,y,z
    
    i = i +1


I need this for a simulation and for that I have to do the same in Blender Game. I know that I can add objects from a other layout with scene.addObject … but in this case I have to create the circle new because I never know how muche vertices the circle have to has befor…

Is there anybody how knows if this is possible?

Thanks to all of you how read that and trying to help! Hope anybody can help me…

The BGE does not support creating meshes from scratch. You have to pre-create all your meshes and then you have some ability to move the vertices but you cannot add/remove them from a mesh.

If you only care about the visual appearance of the circle, then you could create a circle with a lot of vertices then stack adjacent vertices to create the appearance of fewer total vertices.

Another option would be to build your own circles. Create a single “line segment” model and compute the locations of the vertices on the circle yourself. Then you connect the vertices with your line segment and you have an approximated circle.

Hello kastoria,

thanks for your help I will try it that way!