当前位置: 首页>>代码示例>>C++>>正文


C++ Tileset::getImage方法代码示例

本文整理汇总了C++中Tileset::getImage方法的典型用法代码示例。如果您正苦于以下问题:C++ Tileset::getImage方法的具体用法?C++ Tileset::getImage怎么用?C++ Tileset::getImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tileset的用法示例。


在下文中一共展示了Tileset::getImage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: drawTile

void Map::drawTile(int id,int x, int y)
{
	for(int k=0; k < tilesets.getSize(); k++)
	{
		Tileset* tileset = tilesets.get(k);
		if(id <= tileset->getLasttId() && id >= tileset->getFirstId())
		{
			id -= tileset->getFirstId();
			int tw = tileset->getTileWidth();
			int th = tileset->getTileHeight();
			int imw = al_get_bitmap_width(tileset->getImage());

			//tile
			int sx = id*tw % imw;
			int sy = id/(imw/tw)*th;

			al_draw_bitmap_region(tileset->getImage(),sx,sy,tileWidth,tileHeight,(x*tileWidth) - (xOffs%tileWidth),(y*tileHeight) - (yOffs%tileHeight),0);
		}
	}
}
开发者ID:hudovisk,项目名称:Allegro,代码行数:20,代码来源:Map.cpp

示例2: draw

void MapperTilesetBox::draw(gcn::Graphics* graphics){
    // draw components
    InfraellyWindow::draw(graphics);

    //draw selection overlay
    if( !tilesetList->empty() ){
        Tileset *selectedTs = tilesetList->at( tilesetDropDown->getSelected() );
        if( selectedTs != NULL ){
            if( selectedTs->getImage() != NULL ){
                //tile width and height
                int tileWidth = selectedTs->getTileWidth();
                int tileHeight = selectedTs->getTileHeight();

                //calculate amount of px off the screen
                int offsetX = tilesetImage->getX();
                int offsetY = tilesetImage->getY();

                // convert pixel values to row, width
                int offCol = offsetX/tileWidth;
                int offRow = offsetY/tileHeight;



                //get the row and col of the selected tile
                int trueCol = selectedTile.getCol();
                int trueRow = selectedTile.getRow();


                //to find out the reletive row/col to draw to
                //  we must minus the offscreen tiles from the true tiles co-ords
                int drawCol = trueCol + offCol;
                int drawRow = trueRow + offRow;


                //calculate where to draw in pxs
                int drawX = (drawCol * tileWidth) + (tilesetImageScroller->getX() + getFrameSize());
                int drawY = (drawRow * tileHeight) + (tilesetImageScroller->getY() + getTitleBarHeight());


                //add offsets according to scroller
                drawX += offsetX%tileWidth;
                drawY += offsetY%tileHeight;


                //dimensions of the frame
                gcn::Rectangle d( drawX+selectedTs->getXOffset(),
                                  drawY+selectedTs->getYOffset(),
                                  tileWidth, tileHeight );

                //only draw if within region
                if(  ( d.x < tilesetImageScroller->getX()+tilesetImageScroller->getWidth() ) &&
                     ( d.x+d.width > tilesetImageScroller->getX() ) &&
                     ( d.y < tilesetImageScroller->getY()+tilesetImageScroller->getHeight()+getTitleBarHeight() ) &&
                     ( d.y+d.height > tilesetImageScroller->getY()+getTitleBarHeight() )
                ){
                    //setcolour to blue
                    graphics->setColor( gcn::Color( 0, 0, 255) );
                    //draw a frame
                    graphics->drawRectangle( d );
                    //decrease the dimensions by one pixel
                    ++d.x;
                    ++d.y;
                    d.width -= 2;
                    d.height -= 2;
                    //draw another frame (inside prev one)
                    graphics->drawRectangle( d );
                } else {
                    //not in region, draw a bob
                    //off the left
                    if( (d.x+d.width) < tilesetImageScroller->getX() ){
                        d.x = tilesetImageScroller->getX();
                        d.y += (tileHeight/2)-5;
                    };
                    //off the right
                    if( d.x > (tilesetImageScroller->getWidth()+tilesetImageScroller->getX()) ){
                        d.x = tilesetImageScroller->getWidth()-10;
                        d.y += (tileHeight/2)-5;

                    };
                    //off the top
                    if( (d.y+d.height) < tilesetImageScroller->getY() ){
                        d.y = tilesetImageScroller->getY()+getTitleBarHeight();
                        d.x += (tileWidth/2)-5;
                    };
                    //off the bottom
                    if( d.y > (tilesetImageScroller->getHeight()+tilesetImageScroller->getY()+getTitleBarHeight())  ){
                        d.y = tilesetImageScroller->getY()+tilesetImageScroller->getHeight()+getTitleBarHeight() - 10;
                        d.x += (tileWidth/2)-5;
                    };
                    //draw the bob (5x5px box)
                    d.width = 10;
                    d.height = 10;
                    //setcolour to red
                    graphics->setColor( gcn::Color( 255, 0, 0) );
                    graphics->fillRectangle( d );
                }
            }
        }
    }
}
开发者ID:hoodwolf,项目名称:Infraelly,代码行数:100,代码来源:MapperTilesetBox.cpp


注:本文中的Tileset::getImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。