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 - nisse pisse

Pages: [1]
1
Well im gonna take a c++ course this fall, but i have written games in java and know of classes, inheritance, polymorphism etc :P

2
Right it works, but only with the sf::Image&

may is ask what the & does?As i know it gives the adress to an object, and therefore should work as a pointer, but obviously not...

3
Well,what exactly do you mean by return a reference directly.  I interpreted it as to remove the pointer, but that seem to be wrong :/


i added  image[position] = new Image(); aswell
 

}

4
Well then the sprite gets 100% white

5
I want to have a class where i stora all my images like this

Code: [Select]
#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




Code: [Select]
#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];
}


I want to be able to load it like this
sf::Sprite bg1(hej->GetGamestate()->GetImage(0));

But its not possible -> D:\Program\Projects\test\Game.cpp|48|error: no matching function for call to 'sf::Sprite::Sprite(sf::Image*)'|

It doesnt take pointers... So its not possible to store my images in another class and get them from another?


[/code]

6
General / Quick question
« on: June 24, 2010, 12:44:36 pm »
thank you :)

7
General / Quick question
« on: June 24, 2010, 12:37:06 pm »
Hello, when i call my drawgame function in the following code it just paints a white square where the picture are supposed to be. the square have the right proportions and such its just white...





Code: [Select]
#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);


}




Also it works fine if I load the picture in the drawgame function


Code: [Select]
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);


}

8
Graphics / Help with scrolling background
« on: June 24, 2010, 10:11:18 am »
Yes it was that "set smooth" was set to true... one might wonder why that is the defualt setup when it works so bad O_o

9
Graphics / Help with scrolling background
« on: June 01, 2010, 09:29:32 pm »
Hello.
So i want a scrolling background. I get the background to scroll fine there is just one problem, there is a pixel gap.

http://data.fuskbugg.se/skalman01/-help.png



   
Code: [Select]
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;
 }


The picture is 1904 pixels in the y axis

I dont see where my thinking fails...

Pages: [1]