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

Pages: [1]
1
Graphics / Re: texture problem
« on: March 04, 2014, 11:41:32 am »
Thanks, I will give that a go :)

2
Graphics / Re: texture problem
« on: March 04, 2014, 11:20:04 am »
Thanks, forgot about using
this->x=s;
I was messing around with the Npc constructor hoping it might change something but thanks for pointing it out.
And I believe I found out the problem (correct me if I am wrong please). Since I am using a vector and copying the temporary Npc, the vector's sprite is storing a pointer to the temporary Npc's texture instead of its own(the vector's texture). Therefore when the loop finishes, the temporary Npc is out of scope and the vector is no longer pointing to any valid texture. My temporary solution is to set the texture outside the loop or in another function which is working fine for now.

3
Graphics / Re: texture problem
« on: March 03, 2014, 11:33:20 pm »
Sorry for not being clear but I was actually storing the parameter to an attribute.
Npc.cpp
Npc::Npc(int x, int y,int gid, std::string location)
{
        Npc::x = x;
        Npc::y = y;
        Npc::location = location;
        Npc::gid = gid;
        Npc::texture1.loadFromFile(Npc::location);
        Npc::sprite1.setTexture(texture1);
}
TileMap.cpp
 while(count >= 0)
                                                        {
                                                                if(atoi(attr->value()) >= locations[count].gid)
                                                                {
                                                                        Npc temp(j,i,atoi(attr->value()) -
                                                                                locations[count].gid, locations[count].location);
                                                                        Npcs.push_back(temp);
                                                                        break;
                                                                }
                                                                count--;
                                                        }
//I omitted alot of code but basically its just loops that take data from file. Then creating and storing each npc's position, image path etc inside the vector.
Main.cpp
int main()
{
        TileMap t;
        Player p;
        //inside the game loop draws the tiles
        for(int q = 0; q < t.Npcs.size(); q++)
                                {
                                       //t.Npcs[q].sprite1.setTexture(t.Npcs[q].texture1);
                                        t.Npcs[q].sprite1.setPosition(t.Npcs[q].getX()*32,t.Npcs[q].getY()*32);
                                        t.Npcs[q].sprite1.setTextureRect(IntRect(0,0,32,48));
                                        window.draw(t.Npcs[q].sprite1);
                                }
         p.sprite.setTextureRect(IntRect(p.source.x%4*p.width,p.source.y*p.height,p.width,p.height));
         window.draw(p.sprite);
         window.display();
//above cove: draws the npc to screen and then draw the character.
 
*EDIT: Although it works if I add that commented out line t.Npcs[q].sprite1.setTexture(t.Npcs[q].texture1). I am not sure if that is a good way to do this because it will need to set the texture for every iteration in the loop.

4
Graphics / texture problem
« on: March 03, 2014, 03:59:38 pm »
Hi everyone I am new and I have a problem where one of the sprites(npc) being drawn is a different texture than I set it to. It is the same texture as another sprite. I am loading the texture and setting it in the constructor of the class. The texture shouldn't be destroyed since it is not local and I don't have the white square problem.
int main()
{
        TileMap t;   //contains each tile in a map and other info like coordinates.
        Player p;
        .....
}
Npc.class
#include "Npc.h"


Npc::Npc(int x, int y,int gid, std::string location)
{
        ......
        Npc::texture1.loadFromFile(Npc::location);
        Npc::sprite1.setTexture(texture1);
}
 
The tilemap gets its data from a file and has a vector of Npcs. Also, If I switch the tilemap and player lines around, the sprite being drawn becomes the one being declared last.

Pages: [1]
anything