1
Graphics / Why cant sprite take a pointer to the location of the image?
« on: June 30, 2010, 07:33:05 pm »
Well im gonna take a c++ course this fall, but i have written games in java and know of classes, inheritance, polymorphism etc
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.
#ifndef GAMESTATE_H_INCLUDED
#define GAMESTATE_H_INCLUDED
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <string>
using namespace std;
class Model;
class Gamestate{
private :
Model* model;
sf::Image *image[255];
sf::Music bgm[1];
sf::SoundBuffer sfx[255];
public :
Gamestate(Model* model);
void DrawGamestate(sf::RenderWindow* App,int layer);
void UpdateGamestate();
void HandleEvent( sf::Event* event);
void LoadImage(string address, int position);
void LoadSfx(string address,int position);
void LoadMusic(string address,int position);
sf::Image *GetImage(int position);
};
#endif // GAMESTATE_H_INCLUDED
#include "Gamestate.h"
#include "Model.h"
Gamestate::Gamestate(Model* model){
this->model = model;
this->LoadImage("testbg.png",0);
}
void Gamestate::DrawGamestate(sf::RenderWindow* App, int layer){
}
void Gamestate::UpdateGamestate(){
}
void Gamestate::HandleEvent(sf::Event *event){
}
void Gamestate::LoadImage(string address, int position){
image[position]->LoadFromFile(address);
}
void Gamestate::LoadSfx(string address,int position){
sfx[position].LoadFromFile(address);
}
void Gamestate::LoadMusic(string address,int position){
bgm[position].OpenFromFile(address);
}
sf::Image *Gamestate::GetImage(int position){
return image[position];
}
#include "Gamestate.cpp"
#include "Player.cpp"
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
using namespace std;
class Model {
private :
int hej;
Gamestate* gamestate;
Player* player;
sf::Sprite Sprite1;
public :
Model();
void updategame();
void drawgame(sf::RenderWindow *App);
};
Model::Model(){
sf::Image Image1;
Image1.SetSmooth(false);
Image1.LoadFromFile("trans.png");
Sprite1.SetImage(Image1);
Sprite1.SetPosition(500,-1);
}
void Model::drawgame(sf::RenderWindow *App){
Sprite1.SetPosition(500,-1);
App->Draw(Sprite1);
}
void Model::drawgame(sf::RenderWindow *App){
sf::Image Image1;
Image1.SetSmooth(false);
Image1.LoadFromFile("trans.png");
sf::Sprite Sprite1(Image1);
Sprite1.SetPosition(500,-1);
App->Draw(Sprite1);
}
sf::Sprite bg1(background);
sf::Sprite bg2(background);
int bgheight;
bgheight = 1904;
bool bgActive1;
bool bgActive2;
int bgPosition1;
int bgPosition2;
bgPosition1 = 799;
bg1.SetPosition(0,(bgPosition1-bgheight));
bgActive1 = true;
bgActive2 = false;
// Start the game loop
while (App.IsOpened())
{
if(App.GetFrameTime() < 0.0167){
Sleep((0.0167-App.GetFrameTime())*1000);
}
// Process events
if(bgActive1 == true){
bgPosition1 = bgPosition1 + 1;
bg1.SetPosition(0,(-bgheight+ bgPosition1));
}
if(bgActive2 == true ){
bgPosition2 = bgPosition2 + 1;
bg2.SetPosition(0,(-bgheight+ bgPosition2));
}
if((-bgheight+ bgPosition1) == 0 && bgActive1 == true){
bgActive2 = true;
bgPosition2 = 0;
bg2.SetPosition(0,-bgheight+ bgPosition1);
}
// if((-bgheight)+ bgPosition1 == 800 && bgActive1 == true){
// bgActive1 = false;
// }
if((-bgheight+ bgPosition2) == 0 && bgActive2 == true){
bgActive1 = true;
bgPosition1 = 0;
bg1.SetPosition(0,-bgheight+ bgPosition2);
}
// if((-bgheight)+ bgPosition2 == 800 && bgActive2 == true){
// bgActive2 = false;
// }
/ Clear screen
App.Clear();
if(bgActive1 == true){
App.Draw(bg1);
}
if(bgActive2 == true){
App.Draw(bg2);
}
if(bgActive2 == true && bgActive1 == true){
m++;
if(m == 5){
cout << endl << bgPosition1 << endl;
cout << bgPosition2 << endl;
}
}
// Draw the string
// App.Draw(Text);
// Update the window
App.Display();
}
return EXIT_SUCCESS;
}