Game Development Reference
In-Depth Information
With the resource group in memory, we can access the individual resources in
one of two ways. The first way is to ask the CIwResGroup instance itself to locate a
particular resource for us. Here's how we do this:
CIwResource* pResource;
pResource = pResGroup->GetResNamed(name, type, flags);
In the call to GetResNamed , the name parameter is a null terminated string containing
the name of the resource we want to access. This is the value that is specified using
the name attribute in an ITX file. If no name value is explicitly specified, the name of
the first resource encountered in the GROUP file (minus any extension) will be used
for the name. In the example GROUP file in the previous section this name would
become titlescreen , since the first resource in the file is the titlescreen.png ile.
The type parameter indicates the class of the resource that we are trying to locate.
This parameter is also a string and is simply the class name of the resource type.
Finally there is the flags parameter that we can normally leave out entirely as it
defaults to a value of zero. There are various flags we can use that alter the way the
search for our resource is performed. For example, IW_RES_PERMIT_NULL_F will
prevent an assert from being fired if the required resource could not be found. Check
the Marmalade documentation for more information on these flags, though in most
cases the default value of zero is what we need to use.
If the resource can't be found, the GetResNamed call will return NULL , otherwise it
returns our resource as a pointer to a CIwResource instance, which we can then cast
to the required class type.
The second way of accessing a resource is to ask the resource manager to find it by
searching through all the currently loaded groups. This can be very useful since it
means we don't have to know exactly which resource group to search in. Obviously
a full search of all currently loaded resource groups will be slower, but it means we
don't have to keep track of every resource group we load. After all, that's what the
resource manager is for! The call required to search all loaded groups for a particular
resource is as follows:
CIwResource* pResource;
pResource = IwGetResManager()->GetResNamed(name, type, flags);
The parameters are exactly the same as calling the CIwResGroup::GetResNamed
method.
Finally, we can remove a resource group and everything it contains from memory
by making the following call:
IwGetResManager()->DestroyGroup(pResGroup);
 
Search WWH ::




Custom Search