Game Development Reference
In-Depth Information
Modifiers Return_value FunctionName(ParameterType1 Parameter1, ...)
{
// Code Body
}
An example of a function from our Vector3 class in our “Hello Droid” example at the end of this chapter is:
static Vector3 CrossProduct(Vector3 a, Vector3 b)
{
Vector3 result = new Vector3(0,0,0);
result.x= (a.y*b.z) - (a.z*b.y);
result.y= (a.z*b.x) - (a.x*b.z);
result.z= (a.x*b.y) - (a.y*b.x);
return result;
}
Also in Java, all parameters that are objects are passed by reference.
Calling the Parent Function
A function in a derived class can override the function in the parent or superclass, using the @Override
annotation. This is not required but helps to prevent programming errors. If the intention is to override a
parent function but the function does not in fact do this, then a compiler error will be generated.
In order for the function in a derived class to actually call its corresponding function in the parent
class, you use the super prefix as seen below.
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Create a MyGLSurfaceView instance and set it
// as the ContentView for this Activity
m_GLView = new MyGLSurfaceView(this);
setContentView(m_GLView);
}
Additional Java tutorials can be found on http://docs.oracle.com/javase/tutorial/ .
Note
The Basic Android Java Program Framework
In this section, I cover the basic Android Java program framework. This framework applies to all
Android programs, not just Android 3D games or games in general. I start off with an overview of the
activity life cycle. Then I cover key cases in the life cycle and follow up by code additions where you
can see for yourself the changes in the Activity's life cycle through the use of debug statements.
 
 
Search WWH ::




Custom Search