Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This depends on how you have implemented your game thus far, i.e., using 2D graphics like in Cocoa or using OpenGL. Fruit Ninja, for example, uses the latter, because its fruits are 3D models. In that case, your Render() chain will typically draw all your 3D objects, then change projection to orthographic to render things like sprite fonts or untransformed 2D sprites (like a HUD) on top of everything. Each of these "sprites" is a quad (2 triangles forming a rectangle) with a texture image mapped to it. Once the texture is loaded into graphics memory, the GPU can draw it over &amp; over really fast, and stretch it or rotate it with no additional cost!</p> <p>So that's the way I'd do it: a quad with a transparent texture that looks like the "streak" you want. Then watch for the touch point and keep track of the previous (or multiple previous) touch coordinates. Calculate the distance between the two points (Google "distance formula") and its angle vector (just two division operations on deltaX,deltaY now that you have the distance). Apply these to the 4x4 matrix you'll use to transform your quad, so that you stretch it (scale X by the distance), rotate it according to your vector, and translate it to the X,Y of the most recent touch point. When the touch is lifted, you can shrink/fade the streak easily.</p> <p>There's another approach you could use to handle curved swipes. It's more difficult but would look better. Use a TRIANGLE STRIP with your "streak" image applied (texture coordinates 0.0 to 1.0) across the vertices along its length. Then based on all those previous touch points, set all the the vertex coordinates yourself, calculating lines between the points and offsetting vertices perpendicularly. Make sense? I hope so! This approach is fun and it's not as painful as it might sound, I promise!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload