Yes, you can do that. It sounds like your object has a rigid shape and you want it to stop instantly when some condition is met. Not gradually slow down or distort. And it sounds like you will have multiple objects that may be released over time. I'd use a data table with one row per object, with column names similar to these:
Xpos Ypos Xvel Yvel XdeltaVel TdeltaVel IsActive IsDrawing Color Size Shape
Then I'd write two functions: UpdateRow( row number, deltaTime ) and DrawRow( row number ). UpdateRow might look something like this (untested, approximately right...):
UpdateRow = function({rowNumber, deltaTime}
if( dtQ:isActive[rowNumber],
dtQ:Xpos[rowNumber] += dtQ:Xvel[rowNumber] * deltaTime;
dtQ:Ypos[rowNumber] += dtQ:Yvel[rowNumber] * deltaTime;
// you might want the velocity to change as well, possibly using the deltaVelocity,
// make sure the Xs and Ys stay together
// do a test to see if still active
if( dtQ:y[rowNumber] <= 0, // whatever condition makes it stop
dtQ:isActive[rowNumber] = 0;
dtQ:isDrawing[rowNumber] -= 1; // count down until vanishes
)
}
When you add a row to the table (dtQ
, above, I tend to use dt for a table not delta time!) make sure to set the row's value for isActive to 1, and if you want the non-active objects to eventually expire, set the isDrawing to 100 or 1000 to control how many cycles go by before it stops drawing.
The DrawRow function looks something like this:
DrawRow = function({RowNumber},
if( dtQ:isDrawing[RowNumber],
// your code goes here. Add the dtQ:Xpos[RowNumber] to your X coords
// and same for Ypos/Y.
// .... use the color/size/shape values from the row if you find them useful
)
);
Now the graphics script becomes a pair of loops over dtQ, the first to apply the updates, and the second to do the drawing. You don't have to keep them separated, but you might find it helpful later if you decide to handle collisions.
In this example, the data table in dtQ could also be displayed with graph builder by plotting the xpos, ypos, color, size, shape values. GraphBuilder will update automatically and you don't need the DrawRow function. I've never used it but I think there might be a custom shape drawing mechanism for the points.
If you are trying to make a video (rather than an interactive, real-time display), settle on 30 or 60 FPS and let the delta time be constant from frame to frame. Above, I picked numbers that made it work on my machine. But if I picked 1/30 and made a set of numbered images, they would make a very smooth video.
Craige