Dynamically update a mini map
Posted: Fri Feb 09, 2007 16:59
I am trying to create a map in the top right corner of the screen. I have one large image of the map. I want to zoom into specific areas of this image as the camera moves along the terrain. To do this, I replaced the old larger image with the desired piece of the new image.
I used the following code from the CreateSubimage wiki,
My question is, in order to have the image change dynamically (can this be done?), where do I need to call the createSubImage function in a typical game state setup?
I used the following code from the CreateSubimage wiki,
Code: Select all
//this function is just called to show the imageloading from a file, and selecting a subpart of the image
void GUIHud::createMMap()
{
//load in a file, replace with your own file
CEGUI::Texture* texture = mGUIRenderer->createTexture("Ground1.bmp");
//create a new imageset with an image that spans the entire texture
CEGUI::Imageset* set = CEGUI::ImagesetManager::getSingleton().createImageset((CEGUI::utf8*)"ExampleImageSet",texture);
set->defineImage("Base",CEGUI::Point(0.0f,0.0f),CEGUI::Size(texture->getWidth(),texture->getHeight()),CEGUI::Point(0.0f,0.0f));
//create a new window for this stuff and link the created image to it
CEGUI::StaticImage* renderTarget = (CEGUI::StaticImage*)CEGUI::WindowManager::getSingleton().createWindow((CEGUI::utf8*)"SEM/StaticImage", (CEGUI::utf8*)"BaseWindow");
renderTarget->setSize(CEGUI::Size(0.3f, 0.4f));
CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)topElement)->addChildWindow(renderTarget);
renderTarget->setPosition(CEGUI::Point(0.6, 0.6));
renderTarget->setImage(&set->getImage((CEGUI::utf8*)"Base"));
/*this function replaces the image with the new coordinates passed with it, which selects a subimage,
and replaces the given image with the newly created one */
createSubImage("ExampleImageSet","Base",CEGUI::Point(0.0f,0.0f),CEGUI::Size(texture->getWidth()-512,texture->getHeight()-512),CEGUI::Point(0.0f,0.0f));
//should not be necessary, if anything weird appears try redrawing the image
//renderTarget->requestRedraw();
}
//this function replaces the image in the given imageset with the new coordinates that are passed with this function
void GUIHud::createSubImage(CEGUI::String imageSetName,CEGUI::String imageName, CEGUI::Point start, CEGUI::Size size,CEGUI::Point offset)
{
CEGUI::Imageset* curr_imageset = CEGUI::ImagesetManager::getSingleton().getImageset(imageSetName);
CEGUI::Texture* texture = curr_imageset->getTexture();
curr_imageset->undefineImage(imageName);
curr_imageset->defineImage(imageName,start,size,offset);
}
My question is, in order to have the image change dynamically (can this be done?), where do I need to call the createSubImage function in a typical game state setup?