//============================================================================= // Initialize the Image. // Post: returns true if successful, false if failed // pointer to Graphics // width of Image in pixels (0 = use full texture width) // height of Image in pixels (0 = use full texture height) // number of columns in texture (1 to n) (0 same as 1) // pointer to TextureManager //============================================================================= bool Image::initialize(Graphics *g, int width, int height, int ncols, TextureManager *textureM) { try{ graphics = g; // the graphics object textureManager = textureM; // pointer to texture object spriteData.texture = textureManager->getTexture(); if(width == 0) width = textureManager->getWidth(); // use full width of texture spriteData.width = width; if(height == 0) height = textureManager->getHeight(); // use full height of texture spriteData.height = height; cols = ncols; if (cols == 0) cols = 1; // if 0 cols use 1 // configure spriteData.rect to draw currentFrame spriteData.rect.left = (currentFrame % cols) * spriteData.width; // right edge + 1 spriteData.rect.right = spriteData.rect.left + spriteData.width; spriteData.rect.top = (currentFrame / cols) * spriteData.height; // bottom edge + 1 spriteData.rect.bottom = spriteData.rect.top + spriteData.height; this->layer = LAYERMANAGER->getLayer(enLayerList::LAYER_DEFAULT); } catch(...) {return false;} initialized = true; // successfully initialized return true; } //============================================================================= // Initialize the Image. // Post: returns true if successful, false if failed // pointer to Graphics // width of Image in pixels (0 = use full texture width) // height of Image in pixels (0 = use full texture height) // number of columns in texture (1 to n) (0 same as 1) // pointer to TextureManager // pointer to this->layer //============================================================================= bool Image::initialize(Graphics * g, int width, int height, int ncols, TextureManager * textureM, Layer * pLayer) { try { graphics = g; // the graphics object textureManager = textureM; // pointer to texture object spriteData.texture = textureManager->getTexture(); if (width == 0) width = textureManager->getWidth(); // use full width of texture spriteData.width = width; if (height == 0) height = textureManager->getHeight(); // use full height of texture spriteData.height = height; cols = ncols; if (cols == 0) cols = 1; // if 0 cols use 1 // configure spriteData.rect to draw currentFrame spriteData.rect.left = (currentFrame % cols) * spriteData.width; // right edge + 1 spriteData.rect.right = spriteData.rect.left + spriteData.width; spriteData.rect.top = (currentFrame / cols) * spriteData.height; // bottom edge + 1 spriteData.rect.bottom = spriteData.rect.top + spriteData.height; this->layer = pLayer; } catch (...) { return false; } initialized = true; // successfully initialized return true; }