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

Pages: [1]
1
Graphics / Help with Sprites and Vectors [Newbie]
« on: February 03, 2011, 05:40:55 pm »
Quote from: "Groogy"
Also you want to avoid pointers, especially pointers to heap memory(memory gained through the new operator.)

Where do you do the call to the method of Tile that crashes? That pointer to the object used in the call where do you assign a value to it?

i wasnt using pointers at first , all i did was create a new Tile object , and in Tile.cpp in my constructor i initialize a vector<sf::Sprite> and i have a sprite object called sprit , i would iterate through my spritesheet cutting it into 16x16 tiles and storing each tile sprite into the vector .

Then in settype(should be called DrawTiles()) i tried to fill the screen with the tile in vector[60].

also i read somwhere that you had to push pointers to the sprites onto the vector , or it might remove everything in previous vector positions.

2
Graphics / Help with Sprites and Vectors [Newbie]
« on: February 02, 2011, 10:00:39 pm »
Quote from: "Laurent"
You have something like this in your code:
Code: [Select]
Tile* tile = 0;
tile->SetType(window);


yeah , should it be something like

Code: [Select]

Tile * tile = new Tile();
tile->SetType(window);


im not used to working with pointers and vectors , so in tile.cpp should sprit also be a pointer , and the vector should accept a pointer of sf::Sprite?

3
Graphics / Help with Sprites and Vectors [Newbie]
« on: February 02, 2011, 08:31:32 pm »
Im not great at c++ and have only had an intro to c++ class that barely touched on classes . everything else i know is what i learn from books or browsing programming forums. So even with your advice i dont know what you mean by your title object is null , a more in-depth explanation would be amazing . but anyway thanks for your help so far.

4
Graphics / Help with Sprites and Vectors [Newbie]
« on: February 02, 2011, 08:58:14 am »
whoops , messed with code , not the same as what i had in the first post. anyway now the debugger breaks in the setType function , when i try and set the position of the sprite in clipped[60]. Im guessing that the sprites are getting messed up when being pushed onto the vect, how would i fix?
 

5
Graphics / Help with Sprites and Vectors [Newbie]
« on: February 02, 2011, 08:15:07 am »
its an error at runtime .
Code: [Select]
Unhandled exception at 0x75569617 in Game.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0028f164..

the debugger breaks at the return of this function in the vector class.

Code: [Select]
reference at(size_type _Pos)
{ // subscript mutable sequence with checking
if (size() <= _Pos)
_Xran();
here-> return (*(begin() + _Pos));
}

6
Graphics / Help with Sprites and Vectors [Newbie]
« on: February 02, 2011, 06:59:44 am »
Ive been having alot of trouble getting sprites into a vector , this is the code ive been using ,and i keep getting an error as i try and access clipped[60] to set the position of that sprite, and also when trying to draw it.
Code: [Select]
#include "tile.h"

Tile::Tile()
{
sf::Image tileset;
        sf::Sprite sprit;
        vector<sf::Sprite> clipped;

tileset.LoadFromFile("C:/Users/stubbs/Desktop/tilesheet.png");
tileset.SetSmooth(false);
sprit.SetImage(tileset);

for(int x = 0; x <= 7; x++)
{
for(int y = 0; y <= 20; y++)
{
sprit.SetSubRect(sf::IntRect(x,y*16,x+16,y+16));
clipped.push_back(sprit);
}
}


}
void Tile::SetType(sf::RenderWindow &App)
{
for(int x = 0; x <= 30; x++)
{
for(int y = 0; y <= 30; y++)
{
clipped[60].SetPosition((x*16),(y*16));
App.Draw(clipped[60]);
}
}
}


so what im trying to do is cut my sprite sheet into 16x16 squares and load each into a vector. so i will be able to assign what type of tile goes where.

any help would be great.

Pages: [1]