void GridPoint::render(sf::RenderTarget &tgt) { // We don't want the circle to scale with the image, so we have to break out of // the current View and compute the position manually. const sf::View &view = tgt.GetView(); sf::FloatRect rect = view.GetRect(); float xtrans = rect.Left + (x * tgt.GetWidth() / rect.GetWidth()); float ytrans = rect.Top + (y * tgt.GetHeight() / rect.GetHeight()); tgt.SetView( tgt.GetDefaultView() ); sf::Shape circle = sf::Shape::Circle(xtrans, ytrans, 5, sf::Color(0, 0, 0, 0), 1, sf::Color(255, 0, 0)); tgt.Draw(circle); tgt.SetView(view); }
void fff::bg::Run(sf::RenderTarget &rendertarget, sf::Uint32 time, float height){ float ftime = time/1000.f; height = fmod(height*ratioy, 480.f); this->setPositionY(-height); sf::Vector2f pos = sprites[0].GetPosition(); //std::cout << "pos.x: " << pos.x << std::endl; if (velx > 0.f && pos.x > 0.f){ this->setPositionX(-640.f); }else if (velx < 0.f && pos.x < -640.f){ this->setPositionX(0.f); } rendertarget.SetView( rendertarget.GetDefaultView() ); for(int i = 0; i < 4; i += 1){ sprites[i].Move(ftime * velx, 0.f); rendertarget.Draw(sprites[i]); } }
void Camera::draw(sf::RenderTarget &target) { target.SetView(view); }
void bange::layerimagetilemap::Process(sf::Uint32 time, sf::RenderTarget &rendertarget, std::map<const void *, int> &views, lua_State *vm){ std::map<const void *, int>::iterator aview; bange::proxy *proxy = NULL; bange::tile *tile = NULL; bange::sprite *sprite = NULL; for (int i = 0; i < processtiles.size(); i += 1){ lua_rawgeti(vm, LUA_REGISTRYINDEX, processtiles[i]); proxy = static_cast<bange::proxy *>( lua_touserdata(vm, -1) ); proxy->behavior->Process(lua_gettop(vm), time, vm); lua_pop(vm, 1); tile = static_cast<bange::tile *>(proxy->object); tile->Process(time, vm); } //Process the autoscroll float ctime = (float)time / 1000.f; if ( (flags & bange::layerimagetilemap::autoscrollx) == bange::layerimagetilemap::autoscrollx ){ xautoscrollx += velautoscrollx * ctime; if ( fabs(xautoscrollx) > widthtilemap ){ xautoscrollx = 0.f; } } if ( (flags & bange::layerimagetilemap::autoscrolly) == bange::layerimagetilemap::autoscrolly ){ yautoscrolly += velautoscrolly * ctime; if ( fabs(yautoscrolly) > heighttilemap ){ yautoscrolly = 0.f; } } //--- //Draw all the tiles in rendertexture std::vector< std::vector<int> >::iterator arow; std::vector<int>::iterator acol; rendertexture.Clear(); for (arow = tiles.begin(); arow != tiles.end(); arow++){ for(acol = (*arow).begin(); acol != (*arow).end(); acol++){ if ( (*acol) == LUA_REFNIL){ continue;} lua_rawgeti(vm, LUA_REGISTRYINDEX, (*acol)); proxy = static_cast<bange::proxy *>( lua_touserdata(vm, -1) ); tile = static_cast<bange::tile *>(proxy->object); lua_pop(vm, 1);//proxy if (tile->sprite == LUA_REFNIL){ continue;} lua_rawgeti(vm, LUA_REGISTRYINDEX, tile->sprite); proxy = static_cast<bange::proxy *>( lua_touserdata(vm, -1) );//Reuse proxy is safe lua_pop(vm, 1);//proxy sprite sprite = static_cast<bange::sprite *>(proxy->object); rendertexture.Draw(*sprite); } } rendertexture.Display(); //Now draw the tilemap's sprite with each view sf::Vector2f opos = this->sprite.GetPosition(); rendertarget.SetView( rendertarget.GetDefaultView() ); for (aview = views.begin(); aview != views.end(); aview++){ const bange::view *view = static_cast<const bange::view *>(aview->first); sf::Vector2f center = view->GetCenter(); sf::Vector2f size = view->GetSize(); float startxview = center.x-size.x/2.f; float startyview = center.y-size.y/2.f; rendertarget.SetView(*view); //Draw the sprite with the tilemap rendered. this->sprite.SetTexture(rendertexture.GetTexture()); //What... if (flags == 0){ rendertarget.Draw(this->sprite); } else if ((flags & bange::layerimagetilemap::repeatx) == bange::layerimagetilemap::repeatx \ && (flags & bange::layerimagetilemap::repeaty) != bange::layerimagetilemap::repeaty){ float x = -(int(center.x * velx + xautoscrollx) % (int)widthtilemap) + startxview - widthtilemap; float posrepeatx = vely * center.y; this->sprite.SetY(posrepeatx + opos.y); for (; x < startxview+size.x; x += widthtilemap){ this->sprite.SetX(x); rendertarget.Draw(this->sprite); } } else if ((flags & bange::layerimagetilemap::repeaty) == bange::layerimagetilemap::repeaty \ && (flags & bange::layerimagetilemap::repeatx) != bange::layerimagetilemap::repeatx){ float y = -(int(center.y * vely + yautoscrolly) % (int)heighttilemap) + startyview - heighttilemap; float posrepeaty = velx * center.x; this->sprite.SetX(posrepeaty + opos.x); for (; y < startyview+size.y; y += heighttilemap){ this->sprite.SetY(y); rendertarget.Draw(this->sprite); } } else if ((flags & bange::layerimagetilemap::repeatx) == bange::layerimagetilemap::repeatx \ && (flags & bange::layerimagetilemap::repeaty) == bange::layerimagetilemap::repeaty){ float y = -(int(center.y * vely + yautoscrolly) % (int)heighttilemap) + startyview - heighttilemap; for(; y < startyview+size.y; y += heighttilemap){ this->sprite.SetY(y); for (float x = -(int(center.x * velx + xautoscrollx) % (int)widthtilemap) + startxview - widthtilemap; x < startxview+size.x; x += widthtilemap){ this->sprite.SetX(x); rendertarget.Draw(this->sprite); } } } this->sprite.SetPosition(opos); } }