Skip to content

Instantly share code, notes, and snippets.

@wtrebella
Created June 23, 2013 19:49
Show Gist options
  • Save wtrebella/5846287 to your computer and use it in GitHub Desktop.
Save wtrebella/5846287 to your computer and use it in GitHub Desktop.
This shows how the path in Pivvot is drawn (as well as the tapered player tail)
override public void PopulateRenderLayer()
{
if(_isOnStage && _firstFacetIndex != -1 && pathPointsToRender_ != null) // if this is false, the sprite hasn't been initiated correctly yet
{
_isMeshDirty = false;
int vertexIndex0 = _firstFacetIndex * 4;
int quadVerticeCount = (pathPointsToRender_.Length - 1) * 4;
Vector3[] quadVertices = _renderLayer.vertices;
Vector2[] quadUVVertices = _renderLayer.uvs;
Vector2[] pathVertices = new Vector2[pathPointsToRender_.Length * 2];
Color[] colors = _renderLayer.colors;
float actualWidth = pathWidth_;
for (int i = 0; i < pathPointsToRender_.Length - 1; i++) {
if (taper) actualWidth = i * pathWidth_ / pathPointsToRender_.Length;
Vector2 vNorm = (pathPointsToRender_ [i+1] - pathPointsToRender_ [i]);
vNorm.Normalize();
Vector2 vPerp = new Vector2(vNorm.y, -vNorm.x);
if (i == 0) {
pathVertices[0] = pathPointsToRender_[0] + vPerp * actualWidth / 2f;
pathVertices[1] = pathPointsToRender_[0] - vPerp * actualWidth / 2f;
}
pathVertices[(i+1)*2] = pathPointsToRender_[i+1] + vPerp * actualWidth / 2f;
pathVertices[(i+1)*2+1] = pathPointsToRender_[i+1] - vPerp * actualWidth / 2f;
if ((i+1)*2+1 == pathVertices.Length - 1) {
pathVertices[(i+1)*2] += vNorm * 10;
pathVertices[(i+1)*2+1] += vNorm * 10;
}
}
for (int i = 0; i < quadVerticeCount; i++) {
colors[vertexIndex0 + i] = _alphaColor;
}
for (int quadVerticeIndex = 0, firstPathVerticeIndex = 0; quadVerticeIndex < quadVerticeCount - 3; firstPathVerticeIndex += 2) {
_concatenatedMatrix.ApplyVector3FromLocalVector2(ref quadVertices[vertexIndex0 + quadVerticeIndex], pathVertices[firstPathVerticeIndex+0],0);
quadUVVertices[vertexIndex0 + quadVerticeIndex] = _element.uvTopLeft;
quadVerticeIndex++;
_concatenatedMatrix.ApplyVector3FromLocalVector2(ref quadVertices[vertexIndex0 + quadVerticeIndex], pathVertices[firstPathVerticeIndex+1],0);
quadUVVertices[vertexIndex0 + quadVerticeIndex] = _element.uvBottomLeft;
quadVerticeIndex++;
_concatenatedMatrix.ApplyVector3FromLocalVector2(ref quadVertices[vertexIndex0 + quadVerticeIndex], pathVertices[firstPathVerticeIndex+3],0);
quadUVVertices[vertexIndex0 + quadVerticeIndex] = _element.uvBottomRight;
quadVerticeIndex++;
_concatenatedMatrix.ApplyVector3FromLocalVector2(ref quadVertices[vertexIndex0 + quadVerticeIndex], pathVertices[firstPathVerticeIndex+2],0);
quadUVVertices[vertexIndex0 + quadVerticeIndex] = _element.uvTopRight;
quadVerticeIndex++;
}
_renderLayer.HandleVertsChange();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment