So, I am trying to make a function that will display a certain picture OR play a video depending on whether the variable passed to the function as an argument is a picture (data type PImage) or a video (data type Movie). I am kinda stumped on how to let the function work with both data types. (Some context: I am making an instructions screen for my game and when the player presses a next button, the next game topic to be demonstrated is drawn. That can either be a short clip or an image.) Here’s what I have so far:
void newInstructionSlide(<< pic or vid variable>>, String filename)
{
String type; // to be defined later
// takes the extension of the input file
String extension = filename.substring(filename.length()-3);
if (extension=="mov" || extension=="mp4")
{
type="movie"; // distinguish media as video
} else if (extension=="png" || extension=="jpg")
{
type="picture"; // distinguish media as picture
} else
{
// give error to console
println("error distinguishing file type; double-check filename");
}
if (type=="movie")
{
(draw video)
} else if (type=="picture")
{
(draw picture)
} else
{
(throw error)
}
Any help is appreciated!