Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - xj76

Pages: [1]
1
General / finding item in vector help please
« on: September 04, 2011, 12:11:38 am »
Hi, I'm having trouble accessing an item within a vector. what I wanted is to somehow get the id (perhaps) of the correct sprite that's been inserted into a vector. The second code is an attempt to this but produces the errors below.

The tiling procedures are within the first code box.

      
Code: [Select]

std::vector<std::vector<int> > mapTiles; // contains the id of the tiles
std::vector<sf::Sprite> map; // contains the tiles itself (3072)

sf::Image mapImage;
mapImage.LoadFromFile("map.bmp");
// Create tiles (3072 sprites)
sf::Image tileset;
tileset.LoadFromFile("land.jpg");
tileset.SetSmooth(false);

sf::Image tileset2;
tileset2.LoadFromFile("post.png");
tileset2.SetSmooth(false);

sf::Image tileset3;
tileset3.LoadFromFile("tree.png");
tileset3.SetSmooth(false);

sf::Image tileset4;
tileset4.LoadFromFile("dirt.jpg");
tileset4.SetSmooth(false);

sf::Image tileset5;
tileset5.LoadFromFile("boat.png");
tileset5.SetSmooth(false);

for (int y=0; y<41; y++)
{
for (int x=0; x<72; x++)
{
sf::Color Color = mapImage.GetPixel(x,y);
if(Color == sf::Color::Black)
{
sf::Sprite spriteLand;
spriteLand.SetImage(tileset);
spriteLand.SetPosition(x*10, y*10);
map.push_back(spriteLand);
}

if(Color == sf::Color(255,0,0))
{
sf::Sprite sprite;
sprite.SetImage(tileset2);
sprite.SetPosition(x*10, y*10);
map.push_back(sprite);
}

if(Color == sf::Color(0,0,255))
{
sf::Sprite sprite;
sprite.SetImage(tileset3);
sprite.SetPosition(x*10, y*10);
map.push_back(sprite);
}

if(Color == sf::Color(0,255,0))
{
sf::Sprite sprite;
sprite.SetImage(tileset4);
sprite.SetPosition(x*10, y*10);
map.push_back(sprite);
}
if(Color == sf::Color(0,255,255))
{
sf::Sprite sprite;
sprite.SetImage(tileset5);
sprite.SetPosition(x*10, y*10);
map.push_back(sprite);
}
}
}

   This is what's causing the error.
   Sprite is related to this code:

     sf::Image Image;
     if (!Image.LoadFromFile("player.png"))
         return EXIT_FAILURE;
     sf::Sprite Sprite(Image);
     Sprite.SetPosition(320.0f,240.0f);
     Image.SetSmooth(false);

   
Code: [Select]

std::vector<sf::Sprite>::iterator p;
p = find(map.begin(),map.end(),(Sprite.GetPosition().x*10)*(Sprite.GetPosition().y*10));





error
Code: [Select]


g++ -Wall -c "untitled.cpp" (in directory: /home/casper/Desktop/SFML)
untitled.cpp: In function ‘int main()’:
untitled.cpp:195: warning: comparison between signed and unsigned integer expressions
untitled.cpp:217: error: no matching function for call to ‘Collision::BoundingBoxTest(__gnu_cxx::__normal_iterator<sf::Sprite*, std::vector<sf::Sprite, std::allocator<sf::Sprite> > >&, sf::Sprite&)’
Collision.cpp:153: note: candidates are: static bool Collision::BoundingBoxTest(const sf::Sprite&, const sf::Sprite&)
In file included from /usr/include/c++/4.4/algorithm:62,
                 from /usr/local/include/SFML/Graphics/Rect.hpp:31,
                 from /usr/local/include/SFML/Graphics/Glyph.hpp:32,
                 from /usr/local/include/SFML/Graphics/Font.hpp:34,
                 from /usr/local/include/SFML/Graphics.hpp:34,
                 from untitled.cpp:2:
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘_RandomAccessIterator std::__find(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<sf::Sprite*, std::vector<sf::Sprite, std::allocator<sf::Sprite> > >, _Tp = float]’:
/usr/include/c++/4.4/bits/stl_algo.h:4224:   instantiated from ‘_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator<sf::Sprite*, std::vector<sf::Sprite, std::allocator<sf::Sprite> > >, _Tp = float]’
untitled.cpp:215:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:174: error: no match for ‘operator==’ in ‘__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = sf::Sprite*, _Container = std::vector<sf::Sprite, std::allocator<sf::Sprite> >]() == __val’
/usr/include/c++/4.4/bits/stl_algo.h:4224:   instantiated from ‘_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator<sf::Sprite*, std::vector<sf::Sprite, std::allocator<sf::Sprite> > >, _Tp = float]’
untitled.cpp:215:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:178: error: no match for ‘operator==’ in ‘__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = sf::Sprite*, _Container = std::vector<sf::Sprite, std::allocator<sf::Sprite> >]() == __val’
/usr/include/c++/4.4/bits/stl_algo.h:182: error: no match for ‘operator==’ in ‘__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = sf::Sprite*, _Container = std::vector<sf::Sprite, std::allocator<sf::Sprite> >]() == __val’
/usr/include/c++/4.4/bits/stl_algo.h:186: error: no match for ‘operator==’ in ‘__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = sf::Sprite*, _Container = std::vector<sf::Sprite, std::allocator<sf::Sprite> >]() == __val’
/usr/include/c++/4.4/bits/stl_algo.h:194: error: no match for ‘operator==’ in ‘__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = sf::Sprite*, _Container = std::vector<sf::Sprite, std::allocator<sf::Sprite> >]() == __val’
/usr/include/c++/4.4/bits/stl_algo.h:198: error: no match for ‘operator==’ in ‘__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = sf::Sprite*, _Container = std::vector<sf::Sprite, std::allocator<sf::Sprite> >]() == __val’
/usr/include/c++/4.4/bits/stl_algo.h:202: error: no match for ‘operator==’ in ‘__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = sf::Sprite*, _Container = std::vector<sf::Sprite, std::allocator<sf::Sprite> >]() == __val’
Compilation failed.

Pages: [1]