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

Pages: [1] 2
1
Graphics / std::map and sf::Texture
« on: August 20, 2011, 11:32:35 pm »
Hi, why this code throw

Code: [Select]
Failed to create texture, invalid size (0x0)

???

Code: [Select]
#include <SFML/Graphics.hpp>
#include <map>

int main()
{
    std::map<int,sf::Texture>   myTexture;

    myTexture[0].LoadFromFile("image.jpg");

    return 0;
}


If I make a sprite, set the texture to it, and draw the sprite, works, but why throw "failed to create texture"?

Thanks.

2
Graphics / Masking in SFML 2
« on: August 02, 2011, 05:54:52 am »
sf::Image myImage(myRenderImage.GetImage());

or

myRenderImage.Create(100,50);
const sf::Uint8* ptr = myRenderImage.GetImage().GetPixelsPtr();
sf::Image myImage;
myImage.LoadFromPixels(100,50,ptr);

I did't test this.

3
Graphics / Masking in SFML 2
« on: August 01, 2011, 09:04:50 pm »
sf::Image Class

void    CreateMaskFromColor (const Color &color, Uint8 alpha=0)
    Create a transparency mask from a specified colorkey.

4
Graphics / Spell Effects
« on: August 01, 2011, 04:43:06 am »
Hi,take a screenshot of the sprite in youtube. If you have gimp, load the image   and look at Threshold, in the menu Color. Its very similar the way the color change, when you change the parameters. Maybe tinting the result of a threshold B/N shader its a start.

Or, in gimp, make every sprite , and just make an animation.
In gimp make a mask layer with the threshold effect, and tint yellow the next layer.....something like that.
Bye.

5
Graphics / Shader SetParameter
« on: July 31, 2011, 12:30:59 am »
Hi,  
Code: [Select]
for ( t_it=myTile.begin() ; t_it < myTile.end(); t_it++ )
{
    if(viewRect.Intersects((*t_it)->GetTileRect()))
    {
         value=calculate_value();
         myShader.SetParameter("param",value); //dynamic param
         myWindow.Draw(*(*t_it)->mySprites[0],myShader);
    }
}


Im drawing almost 7000 sprites(16x16), 1680x1050.
If i only draw the sprites, without shader, I have 200/250 FPS (with SFML2).

If I use shader , with SetPArameter outside the loop, a precalculated value for every sprite, I get 140/160 FPS.

IfIi use shader, just like the code, I get 90/100 FPS.

So, I want to know if it is a better way to use dynamic shader(thats the name???).....calling the shader with a dynamic var, using setparameter.

Hope you understand my problem......and my English.

Thanks.
God bless Laurent and his child.

6
Graphics / When I load an image, My moving sprite freezes.
« on: June 26, 2011, 06:39:06 am »
Hi, show some code.

7
Graphics / Making a sprite move randomly accross screen
« on: June 26, 2011, 05:53:24 am »
Quote from: "JAssange"
Yeah the pacman ghosts have a set pattern, from what I remember, its:
Red chases player directly
Orange camps the bottom left corner
Pink heads to the square a few in front of pacman in his current direction.
Blue.... eh I think he follows red but with an offset but I forget.


WOW!!!  I never realized this, and I played pacman "unsigned long" times.

8
Graphics / Anchor a pixel to a sprite?
« on: June 26, 2011, 05:26:55 am »
Hi, i dont know if I had understood the question.

This way, you can know where is a pixel in a sprite, even if it is rotated.
I draw a Sprite, and a Circle Shape. The center of the circle follow the pixel assigned in barrelPos(vector2f).

Not my Sprite


Code: [Select]
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::RenderWindow App(sf::VideoMode(800,600, 32), "SFML Graphics");

    sf::Image image;
    image.LoadFromFile("player.png");
    image.SetSmooth(false);

    sf::Sprite sprite;
    sprite.SetImage(image);
    sprite.SetPosition(400,300);

    sf::Vector2f barrelPos;
    sf::Vector2f GlobalBarrelPos;

    barrelPos.x=30; //The pixel(x,y) in the sprite you want to follow
    barrelPos.y=15;

    sf::Shape Circle = sf::Shape::Circle(0,0, 6, sf::Color(255, 0, 0),1,sf::Color(255, 0, 0));
    Circle.EnableFill(false);

    App.UseVerticalSync(true);
    App.SetFramerateLimit(60);

    while (App.IsOpened())
    {
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                App.Close();
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();
        }

        sprite.Rotate(2);
        sprite.Move(-1,0.5);

        GlobalBarrelPos=sprite.TransformToGlobal(barrelPos);
        Circle.SetPosition(GlobalBarrelPos.x,GlobalBarrelPos.y);
        std::cout << "(" << GlobalBarrelPos.x << "," << GlobalBarrelPos.y << ")" << std::endl;

        App.Clear(sf::Color(255,255,255));
        App.Draw(sprite);
        App.Draw(Circle);

        App.Display();
    }

    return EXIT_SUCCESS;
}

9
Graphics / game engine question 2
« on: June 26, 2011, 01:15:28 am »
i have to load not only the sprites near, and delete the far ones ?? the tiles data too ????

Code: [Select]
#include <SFML/Graphics.hpp>

const int MAXLAYERS=3;
const int MAPSIZE=128;

struct sTileLayer
{
   // sf::Sprite *sprite;
};

class cTile
{
    public:
        cTile(){layer=new sTileLayer[MAXLAYERS];};
        virtual ~cTile(){delete layer;};
    private:
       sTileLayer *layer;
};

class cMap
{
    public:
        cMap(){tile=new cTile[MAPSIZE*MAPSIZE];};
        virtual ~cMap(){delete tile;};
    private:
        cTile *tile;
};

class cWorld
{
    public:
        cWorld(){map=NULL;};
        virtual ~cWorld(){delete map;};
        void CreateMap(int w, int h){map=new cMap[w*h];};
    private:
        cMap *map;
};

int main()
{
    sf::RenderWindow App(sf::VideoMode(1024,768, 32), "SFML Graphics");

    cWorld world;
    world.CreateMap(40,40);

    App.UseVerticalSync(true);
    App.SetFramerateLimit(60);

    while (App.IsOpened())
    {
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                App.Close();
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();
        }
        App.Clear();
        App.Display();
    }

    return EXIT_SUCCESS;
}

10
Graphics / game engine question 2
« on: June 25, 2011, 08:30:01 pm »
Code: [Select]
#include <SFML/Graphics.hpp>

const int MAXLAYERS=3;
const int MAPSIZE=128;

struct sTileLayer
{
   // sf::Sprite *sprite;
};

class cTile
{
    public:
        cTile(){layer=new sTileLayer[MAXLAYERS];};
        virtual ~cTile(){delete layer;};
    private:
       sTileLayer *layer;
};

class cMap
{
    public:
        cMap(){tile=new cTile[MAPSIZE*MAPSIZE];};
        virtual ~cMap(){delete tile;};
    private:
        cTile *tile;
};

class cWorld
{
    public:
        cWorld(){map=NULL;};
        virtual ~cWorld(){delete map;};
        void CreateMap(int w, int h){map=new cMap[w*h];};
    private:
        cMap *map;
};

int main()
{
    sf::RenderWindow App(sf::VideoMode(1024,768, 32), "SFML Graphics");

    cWorld world;
    world.CreateMap(40,40);

    App.UseVerticalSync(true);
    App.SetFramerateLimit(60);

    while (App.IsOpened())
    {
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                App.Close();
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();
        }
        App.Clear();
        App.Display();
    }

    return EXIT_SUCCESS;
}


This is the minimal code. I have 1 world with 40x40 maps, each with 128x128 tiles.
Total = 40*40*128*128 = 26214400 tiles.

This gives me 629.280 K. Notice that sprite ptr in layers is //.

11
Graphics / game engine question 2
« on: June 25, 2011, 05:59:59 am »
Hi,

I want to make a tilemap, but with million of tiles. I know about split the map, and drawing only the part i see. The problem is not the fps, is the memory(RAM).

So doing something like sf::Sprite[10000000], is not a good choice.

So, i have classes TILE, MAP, WORLD. World contain maps, maps contain tiles.

The problem is that loading 10000000 tile Object,even without declaring each Sprite... just a few methods , vars.......etc, memory goes to hell.


Before i know this, i notice that with a lot of sprites memory die, so, i split the map in smaller maps, and i load only the Sprites that i need. But that dosent work. Because  memory die without loading any Sprite, "only" the tiles object(10000000 objects). When i say die, i say  1GB of memory running.

I dont know how to implement this. If i create and delete tile objects, every time i create the object i have to load every single var again, like sprite, pos of the sprite, layers, anim, all.

Hope you understand my question.

Thanks

12
Graphics / Anchor a pixel to a sprite?
« on: June 25, 2011, 05:39:17 am »
Hi, Im not programming right now, but i think.

I dont know if rotate works like this, im just mind-programming
When you rotate a sprite, you read each pixel in the sprite, like if it was not rotated i think. So, if you know the coords (x,y) in the sprite, where you want the bullet get out, after rotated, the coord(x,y) is the same. But when you convert this point to windowCoord, it will give you the correct (x,y).

I dont know if rotate works like that.


Sorry.....my English :(

Tell me/us if you solve this in any way.

Bye.

13
Graphics / move sprite in the opposite direction and bullet problem
« on: June 24, 2011, 06:21:34 pm »
Put "int dir=1" outside the game loop

Code: [Select]

   ...
   int dir=1;
   ...
   while (App.IsOpened())
   {
         ...
         if(X>=700)dir=-1;
         if(X<=0)dir=1;
         sprbox.Move(100 * dir * ElapsedTime, 0);
         ...
   }


14
Graphics / move sprite in the opposite direction and bullet problem
« on: June 24, 2011, 04:48:40 pm »
it works, post the full code again.

15
Graphics / move sprite in the opposite direction and bullet problem
« on: June 24, 2011, 05:34:07 am »
Hi
Code: [Select]

         if(X<=700)
            sprbox.Move(100* ElapsedTime, 0);
         else
            sprbox.Move(-200* ElapsedTime, 0);



Everytime sprbox goes LEFT 200, in the next loop, X < 700 , so.....RIGHT again.


You can do something like:

Code: [Select]
 
   ...
   int dir=1;
   ...
   while (App.IsOpened())
   {
         ...
         if(X>=700)dir=-1;
         if(X<=0)dir=1;
         sprbox.Move(100 * dir * ElapsedTime, 0);
         ...
   }


Pages: [1] 2
anything