Hi, I’m using display.newMesh to draw a trail behind my character and I’m in trouble. For perfomance purpose, I want to avoid to make a new mesh each frame as I can just initialize my mesh at the start of my app and move the vertices to follow my character position. My basic approach is to initialize all vertices at 0,0 coordinates when creating the mesh and then set the vertices at correct positions each frame. But I’m facing a strange “bug” and I would like to know what’s is happening exactly. I’ve made a real short peace of code to show you the problem.
Here is a basic mesh that displays a white square at the topleft corner of the screen :
mesh = display.newMesh( { x=0.01, y=0.01, mode = "strip", vertices = { 0,0, 0,0, 0,0, 0,0 } }) mesh.path:setVertex(1, 0, 0) mesh.path:setVertex(2, 0, 100) mesh.path:setVertex(3, 100, 0) mesh.path:setVertex(4, 100, 100) print(mesh.path:getVertex(4)) print(mesh.path:getVertexOffset())
If I remove the x=0.01 and y = 0.01 params of the display.newMesh method and set them to 0, it does not work anymore, the mesh is not displayed and I want to know why? Hell it’s just a 0.01 offset. I’m 100% sure something is hapenning behind the scene with vertex offset being equal to zero or something divided by zero?
The debug log print the same output in both case but in one case I see my mesh and in the other case I don’t.
I can also remove the x=0.01 and y = 0.01 and put random positions for vertices in the display.newMesh as they will be set correctly on each frame but I want to know why I can’t set all of them to 0,0. What are the hidden calculations?
If I just display.newMesh everyframe and set correct positions directly in the “constructor” and not by calling setVertex each frame, of course it works. But I really want to avoid calling display.newMesh each frame.