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

Pages: [1]
1
Graphics / Extending the Sprite class?
« on: May 20, 2010, 05:35:26 pm »
Thank you!  That's exactly what was wrong!

I know about reference... but, like I said, my C++ is really rusty, and when you don't have to worry about that stuff (Python!) it sorta gets lost.

Thanks again!

2
Graphics / Extending the Sprite class?
« on: May 20, 2010, 05:51:10 am »
Hello!

I'm working on a basic platformer, trying to get used to using C++ instead of Python, and I was going to make a tile-based system.

I had no problem creating a two-dimensional array of Sprites and drawing those onto the screen.  It's when I started to try and create a "Tile" class to have a bit more functionality that I started running into problems.

My C++ is pretty rusty, but I think that I'm doing everything right in terms of C++ syntax.  I want to create my "Tile" class and make it extend Sprite.  I assumed that I should be able to simply call renderwindow.Draw(someTile) and that it would correctly draw things.  

Here is my tile class:

Code: [Select]
#ifndef TILE_H_INCLUDED
#define TILE_H_INCLUDED

#include <SFML/Graphics.hpp>

class Tile : public sf::Sprite{
    public:
        Tile() : sf::Sprite(), solid(false){};

        Tile(sf::Image img, sf::Vector2f pos, bool sol) : sf::Sprite(img, pos), solid(sol){};

        bool solid;

};
#endif // TILE_H_INCLUDED


However, every time I try to draw a tile, it draws the correct size (in this case the image is 32x32) but all of the pixels are always white!  

I'm creating my tile object like this:
Code: [Select]
Tile test(tileset[1], sf::Vector2f(0,0), true);
And drawing it like this:
Code: [Select]
window.Draw(test);

tileset is an array of Images, this seems to be working correctly, because if I just create a Sprite from tileset[1] it displays correctly.

Am I doing something wrong?  Should I just include a Sprite in my Tile class, instead of extending the Sprite class?  

Thanks!

-Sam

Pages: [1]
anything