tango2009
asked on
Error help
I am creatinga game and I am stuck with this particular error
1>c:\users\scott\desktop\p roject\myc ++\csci260 5cwk\mains croller.cp p(155) : error C2664: 'powerupScroller::powerupS croller(fl oat,float, std::vecto r<_Ty>,flo at,unsigne d int,float)' : cannot convert parameter 3 from 'std::vector<_Ty>' to 'std::vector<_Ty>'
1> with
1> [
1> _Ty=ScrollSprite *
1> ]
1> and
1> [
1> _Ty=Scrollpower *
1> ]
1> and
1> [
1> _Ty=ScrollSprite *
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
This is my class below
1>c:\users\scott\desktop\p
1> with
1> [
1> _Ty=ScrollSprite *
1> ]
1> and
1> [
1> _Ty=Scrollpower *
1> ]
1> and
1> [
1> _Ty=ScrollSprite *
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
This is my class below
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include <sstream>
#include "ScrollSprite.h"
#include "Scroller.h"
#include "AnimatedSprite.h"
#include "powerupScroller.h"
using std::endl;
int main()
{
//initialisation - lots of this code could be put into functions for
//neatness and separation of concerns. You need to declare objects here to draw them
//but the set up for those objects could be done in a function or a class
//window dimensions
unsigned int width=600;
unsigned int height=480;
//we need a timer to update things - get a clock
sf::Clock clock;
static float timeAccumulator=0.0;
//load resources for the scroller - images and sounds (if you have any)
sf::Image backGround;
if(!backGround.LoadFromFile("images/backGrnd2.jpg")) std::cout<<"File not found background.jpg"<<std::endl;
sf::Image title;
if(!title.LoadFromFile("images/title.png")) std::cout<<"File not found title.jpg"<<std::endl;
sf::Image aScroll;
if(!aScroll.LoadFromFile("images/rock.png")) std::cout<<"File not found rock.png"<<std::endl;
sf::Image bScroll;
if(!bScroll.LoadFromFile("images/navalmine.png")) std::cout<<"File not found navalmine.png"<<std::endl;
sf::Image cScroll;
if(!cScroll.LoadFromFile("images/barrel.png")) std::cout<<"File not found barrel.png"<<std::endl;
sf::Image dScroll;
if(!dScroll.LoadFromFile("images/ship.png")) std::cout<<"File not found ship.png"<<std::endl;
sf::Image aNimat;
if(!aNimat.LoadFromFile("images/sub.png")) std::cout<<"File not found sub.png"<<std::endl;
//resouces loaded
int level = 0;
int lives = 3;
AnimatedSprite anim(aNimat,Vector2f(0,-20),Vector2f(1,1),0,Color(255,255,255,255),10,10);
//resouces loaded
anim.Scale(3,3);
anim.setInterval(1.05);
anim.Move(200,200);
sf::Sprite backGndSprite(backGround);
backGndSprite.Scale(0.75f,0.8f);
sf::Sprite screen(title);
screen.Scale(0.75f,0.8f);
//set up the scroller data
ScrollSprite scrollingSprite(dScroll);
scrollingSprite.setScrollPos(10);
scrollingSprite.setVertPos(300);
Scrollpower scrollingSprite0(cScroll);
scrollingSprite0.setScrollPos(10);
scrollingSprite0.setVertPos(300);
ScrollSprite scrollingSprite1(aScroll);
scrollingSprite1.setScrollPos(30);
scrollingSprite1.setVertPos(320);
ScrollSprite scrollingSprite2(aScroll);
scrollingSprite2.setScrollPos(30);
scrollingSprite2.setVertPos(380);
scrollingSprite2.SetScale(3,3);
ScrollSprite scrollingSprite3(cScroll);
scrollingSprite3.setScrollPos(500);
scrollingSprite3.setVertPos(400);
scrollingSprite3.SetScale(1,1);
ScrollSprite scrollingSprite4(aScroll);
scrollingSprite4.setScrollPos(710);
scrollingSprite4.setVertPos(300);
ScrollSprite scrollingSprite5(bScroll);
scrollingSprite5.setScrollPos(930);
scrollingSprite5.setVertPos(20);
ScrollSprite scrollingSprite6(aScroll);
scrollingSprite6.setScrollPos(1100);
scrollingSprite6.setVertPos(380);
scrollingSprite6.SetScale(3,3);
ScrollSprite scrollingSprite7(aScroll);
scrollingSprite7.setScrollPos(1300);
scrollingSprite7.setVertPos(4000);
scrollingSprite7.SetScale(3,3);
ScrollSprite scrollingSprite8(bScroll);
scrollingSprite8.setScrollPos(1300);
scrollingSprite8.setVertPos(4000);
scrollingSprite8.SetScale(3,3);
ScrollSprite scrollingSprite9(bScroll);
scrollingSprite9.setScrollPos(1300);
scrollingSprite9.setVertPos(4000);
scrollingSprite9.SetScale(3,3);
ScrollSprite scrollingSprite10(bScroll);
scrollingSprite10.setScrollPos(1300);
scrollingSprite10.setVertPos(35);
scrollingSprite10.SetScale(1,1);
std::vector<ScrollSprite*> pSprite;
pSprite.push_back(&scrollingSprite);
pSprite.push_back(&scrollingSprite1);
pSprite.push_back(&scrollingSprite2);
pSprite.push_back(&scrollingSprite3);
pSprite.push_back(&scrollingSprite4);
pSprite.push_back(&scrollingSprite5);
pSprite.push_back(&scrollingSprite6);
pSprite.push_back(&scrollingSprite7);
pSprite.push_back(&scrollingSprite8);
pSprite.push_back(&scrollingSprite9);
pSprite.push_back(&scrollingSprite10);
std::vector<Scrollpower*> sSprite;
sSprite.push_back(&scrollingSprite0);
//nb - scroller window width needs to match window size
Scroller scr(2000,width,pSprite,400);
powerupScroller sc(2000,width,sSprite,400);
// Create main window
sf::RenderWindow App(sf::VideoMode(width, height), "Scroller Window");
// Start the display loop
while (App.IsOpened())
{
sf::Event Event;
//check inputs in the event queue
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
// Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
//up arrow key : does nothing
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Up))
{
anim.Move(0,-20);
//to do something on up key write here
}
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Down))
{
anim.Move(0,20);
//to do something on up key write here
}
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::S))
{
screen.Rotate(100.00);
}
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::W))
{
anim.Rotate(30.00);
}
//other events are ignored
}
//update the things that need updating in the game loop
float f=clock.GetElapsedTime();
clock.Reset();
timeAccumulator+=f;
scr.update(f);
sc.update(f);
anim.update(f);
//draw the things you have to draw
App.Draw(backGndSprite);
App.Draw(anim);
App.Draw(scr);
App.Draw(sc);
App.Draw(screen);
//Monitoring the display function
std::stringstream str;
str<<"The display rate is ";
str<<1/f;
//str<<" the accumulated time is "<<timeAccumulator;
str<<1/f;
std::string s;
std::getline(str,s);
str.clear();
sf::String TextScore(s.c_str(),sf::Font::GetDefaultFont(),15);
TextScore.SetPosition(0,0);
TextScore.SetColor(sf::Color(255, 0, 0));
App.Draw(TextScore);
std::stringstream stv;
stv<<"The level is "<<level;
//stv<<1/f;
std::string sv;
std::getline(stv,sv);
stv.clear();
sf::String Text(sv.c_str(),sf::Font::GetDefaultFont(),15);
Text.SetPosition(10,20);
Text.SetColor(sf::Color(255,0,0));
App.Draw(Text);
std::stringstream stvt;
stvt<<"The distance travelled "<<timeAccumulator<<"Mps";
stv<<1/f;
std::string sx;
std::getline(stvt,sx);
stvt.clear();
sf::String Dist(sx.c_str(),sf::Font::GetDefaultFont(),15);
Dist.SetPosition(20,30);
Dist.SetColor(sf::Color(255,0,0));
App.Draw(Dist);
std::stringstream stvs;
stvs<<"LIVES "<<lives;
//stvs<<1/f;
std::string sm;
std::getline(stvs,sm);
stvt.clear();
sf::String life(sm.c_str(),sf::Font::GetDefaultFont(),15);
life.SetPosition(20,40);
life.SetColor(sf::Color(255,0,0));
App.Draw(life);
if (timeAccumulator > 10)
{
level = 1;
}
if (timeAccumulator > 50)
{
level = 2;
}
if (timeAccumulator > 100)
{
level = 3;
}
if (level > 1)
{
}
// Finally, display the rendered frame on screen
App.Display();
}
return EXIT_SUCCESS;
}
Line 144 in the example code...
std::vector sSprite;
sSprite.push_back(&scrolli ngSprite0) ;
Shouldn't this be...
std::vector sSprite;
sSprite.push_back(&scrolli ngSprite0) ;
??
std::vector sSprite;
sSprite.push_back(&scrolli
Shouldn't this be...
std::vector sSprite;
sSprite.push_back(&scrolli
??
ASKER
Zoppo
this is my powerupScroller header file ill also attach my cpp below
this is my powerupScroller header file ill also attach my cpp below
#ifndef POWERUPSCROLLER_H
#define POWERUPSCROLLER_H
#include <vector>
#include <SFML/Graphics.hpp>
#include "Scrollpower.h"
using namespace sf;
class powerupScroller : public Scrollpower
{
public:
powerupScroller();
powerupScroller(float D,float W,std::vector<Scrollpower*> reps, float scrollV=0, unsigned int currentStartIndex=0,float left=0);
void update(float dt);//moves lhs to correct position in the scroll pattern
float getLHS();//returns the LHS value
void setVelocity(float f);
float getVelocity();
protected:
float D;//the length in pixels of the scroll pattern
float W;//the width in pixels of the scrolling window
std::vector<Scrollpower*> repeaters;//the repeating images that have to be drawn as we we move to the right - should point to scroll sprites
float scrollVelocity;//how fast do we scoll;
unsigned int currentStartIndex;
float lhs;//the position in the scroll pattern of the window LHS 0<=lhs<D
void Render (const RenderWindow &Window) const ;
void prepareToRender();
private:
void setHeights();
};
#endif
ASKER
This is my cpp
#include "powerupScroller.h"
powerupScroller::powerupScroller()
{
}
powerupScroller::powerupScroller(float D,float W,std::vector<Scrollpower*> reps, float scrollV, unsigned int currentStartIndex,float left)
{
this->D=D;
this->W=W;
this->repeaters=reps;
this->scrollVelocity=scrollV;
this->currentStartIndex=currentStartIndex;
this->lhs=left;
setHeights();
}
float powerupScroller::getLHS(void)
{
return lhs;
}
void powerupScroller::update(float dt)
{
lhs=lhs+dt*scrollVelocity;
if(lhs>D)
{
lhs=lhs-D;
currentStartIndex=0;
}
prepareToRender();
}
void powerupScroller::setVelocity(float v)
{
scrollVelocity=v;
}
void powerupScroller::Render (const RenderWindow &Window) const
{
if(currentStartIndex<repeaters.size())
//draw everything we can see starting from the current index
//update index for the next run
{
//set the iterator to the current index
std::vector<Scrollpower*>::const_iterator iter=repeaters.begin();
iter+=currentStartIndex;
//draw the things between current index and the end which are in view
while(iter!=repeaters.end()&&((*iter)->getScrollPos()<=lhs+W))
{
Window.Draw(**iter);
++iter;
}
}
//need to check for wraparounds
if(lhs+W>D)
{
std::vector<Scrollpower*>::const_iterator iterStart=repeaters.begin();
//draw everything that starts within W-(D-lhs) of the start
while(iterStart!=repeaters.end()&&((*iterStart)->getScrollPos()<W-(D-lhs)))
{
Window.Draw(**iterStart);
++iterStart;
}
}
}
void powerupScroller::prepareToRender()
{
if(currentStartIndex<repeaters.size())
//setup everything we can see starting from the current index
//update index for the next run
{
//set the iterator to the current index
std::vector<Scrollpower*>::iterator iter=repeaters.begin();
iter+=currentStartIndex;
//move over anything which is too far left and update currentIndex for next run
while(iter!=repeaters.end()&&((*iter)->getScrollPos()<lhs)&&((*iter)->getScrollPos()+(*iter)->GetSize().x<lhs))
{
++currentStartIndex;
++iter;
}
//FYI currentIndex may be == repeaters.size()
//setup the things between current index and the end which are in view
while(iter!=repeaters.end()&&((*iter)->getScrollPos()<lhs+W))
{
//need to set some sprite data before drawing
float scrolPos=(*iter)->getScrollPos();
(*iter)->SetX(scrolPos-lhs);
++iter;
}
}
//need to check for wraparounds
if(lhs+W>D)
{
std::vector<Scrollpower*>::iterator iterStart=repeaters.begin();
//draw everything that starts within W-(D-lhs) of the start
while(iterStart!=repeaters.end()&&((*iterStart)->getScrollPos()<W-(D-lhs)))
{
//need to set some sprite data before drawing
float scrolPos=(*iterStart)->getScrollPos();
(*iterStart)->SetX(D-lhs+scrolPos);
++iterStart;
}
}
}
void powerupScroller::setHeights()
{
std::vector<Scrollpower*>::iterator iter;
for(iter=repeaters.begin();iter<repeaters.end();iter++)
{
(*iter)->SetY((*iter)->getVertPos());
}
}
float powerupScroller::getVelocity()
{
return scrollVelocity;
}
Did you see http:#30504337 ???
Actually, maybe not -- I've just looked through the code again and I see this is probably correct.
ASKER
Evilrix
I dont think so, I am trying to create two scrollers that are nearly identical to one another one for obstacles in my game and the other for powerups. If you check out line 76 this is the sprite on my other scroller.
I dont think so, I am trying to create two scrollers that are nearly identical to one another one for obstacles in my game and the other for powerups. If you check out line 76 this is the sprite on my other scroller.
What line in the example code corresponds to line 155 that the error occurs?
ASKER
This line is the one that gets flagged up
powerupScroller sc(2000,width,sSprite,400) ;
powerupScroller sc(2000,width,sSprite,400)
Hmmm. Think we might need to have a go at building this. Can you post all the code required to build this?
ASKER
I have zipped all my code up and posted this hope you can use this to see the error
code.zip
code.zip
Ok, thanks :)
At work right now but I'll look at this when I get home (assuming no one else has done so in the mean time).
At work right now but I'll look at this when I get home (assuming no one else has done so in the mean time).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Nice one I8.
tango2009, sorry I couldn't look at this in detail earlier... I was up to my neck in it at work :)
tango2009, sorry I couldn't look at this in detail earlier... I was up to my neck in it at work :)
how is the used 'powerupScroller'-construc
ZOPPO