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 - codeed

Pages: [1]
1
Graphics / Visual C++ 2008: sf::Image as static attribute
« on: December 12, 2010, 02:45:01 am »
Now I get it. Also I've linked the wrong graphics lib :oops:.

Thanks for your help !

2
Graphics / Visual C++ 2008: sf::Image as static attribute
« on: December 11, 2010, 09:15:15 pm »
Hi Nexus,

thanks for your fast reply. But I don't know how moving the static variable outside of the class definition should solve the problem. I want it to be an attribute of the class.

Anyway I tried your suggestion and put the Image variable above the class.

Now if I start the programme it spits out random letters and numbers and crashes after a few seconds.  


PS: I mixed up the file names in my first post the .h file is in fact the .cpp file

3
Graphics / Visual C++ 2008: sf::Image as static attribute
« on: December 11, 2010, 07:31:52 pm »
Hi all,

I have problems using sf::Image as static attributes. I've created an empty cmd console Project with Visual C++ 2008 and added the Missile Class from this Tutorial:

http://www.sfml-dev.org/tutorials/1.6/graphics-sprite.php

If I add now a new missile object i get error LNK2020 and error LNK2001.
When i remove the keyword static it works fine.

I've linked all required libs in the project settings and included the Graphics.hpp in the standard header file (stdafx.h).

Main.cpp

Code: [Select]

// Main.cpp: Hauptprojektdatei.

#include "stdafx.h"
#include "Missile.h"

using namespace System;

int main(array<System::String ^> ^args)
{
     Missile missile;

    return 0;
}



Missile.h

Code: [Select]

#pragma once
#include <SFML/Graphics.hpp>

class Missile
{
public :

    static bool Init(const std::string& ImageFile)
    {
        return Image.LoadFromFile(ImageFile);
    }

    Missile()
    {
        Sprite.SetImage(Image); // every sprite uses the same unique image
    }

private :

    static sf::Image Image; // shared by every instance

    sf::Sprite Sprite; // one per instance
};



Missile.cpp

Code: [Select]

#include "StdAfx.h"
#include "Missile.h"


I hope you can help me.

Regards Paul

Pages: [1]