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

Pages: [1]
1
General / Keeping RenderWindow in a class?
« on: May 10, 2013, 03:58:53 am »
How can I keep render window in a class? I have this

//simController.h
class simController {
private:
        sf::RenderWindow game;
public:
    void execute();
    void init();
    void event();
    void exit();
};

and this

//simController.cpp
void simController::init(){
    game = sf::RenderWindow(sf::VideoMode(1280, 920), "Sim");
    game.setFramerateLimit(0);
};

However, RenderWindows are uncopyable, so I cannot do this. I also cannot declare the window directly inside the class. So how can I store a RenderWindow in a class? it seems impossible.

Thanks

2
Note the API change of sf::Rect:

Rect (T rectLeft, T rectTop, T rectWidth, T rectHeight)

It's no-longer Left, Top, Right, Bottom, but Left, Top, Width, Height. ;)

Thanks! But that still doesn't fix the issue that the bullets are extremely off centre. I did some logging, and their X is indeed in the same place. It was on centre in 1.6.

3
Hello everybody! I'm in the process of making a game. I was using SFML 1.6, and was recently informed to upgrade to SFML 2.0. I did, and fixed everything I had to, hoping that it would fix the texture. But it did not. My texture now looks like this: http://videobam.com/vdtJR

It's horrible. Normally it would looks like the lights were normally blinking. This is my actual texture: http://i.imgur.com/oKl4VBO.png

and this is the code I'm using to set the sub rect
playerSprite.setTextureRect(sf::IntRect(imageLoop % 4 * 32, floor(imageLoop / 4) * 32, imageLoop % 4 * 32 + 32, floor(imageLoop / 4) * 32 + 32));

It was working perfectly before I upgraded from SFML 1.6 to 2.0. Please help! This is really annoying.


Also, it made the sprite extremely off center. Normally, these bullets are centered: http://i.imgur.com/jYDaOqY.jpg

4
1) Oh. Time to update SFML!
2) Huh that's interesting. My real name is Thor :P
3) Oh of course! I had that confused with that constructers can't return anything. Über fail.
4) Oh, ok, thanks.
5) Well, they're not thaat huge. I have them pretty well split up (IMO). It's just that it would take time.
6) I've been learning it with cplusplus.com
7) Oh! Awesome! Time to make an image management class I guess :P

Thanks so much for your help!

5
Cool story, but code.show(); would be much better... ;D

No seriously the description isn't bad, but it doesn't really help that much. If you want a good answer you need to provide a minimal and complete example that reproduces the problem.

I can now only give you some points:
.SetImage
I strongly advice you against the use of SFML 1.6, it's around 2.5 years old, thus outdated, has a lot of bugs and misses quite a few nice features.

I have a class, within that class contains a Sprite and an Image
Usually it's not such a good idea to pair Sprites and Images, because Images are heavy resource objects that shouldn't be copied around but could also get used multiple times.

Anyway, I have an init function. This function is called to initiate all the good stuffs including setting the image for the sprite.
Classes have constructors for a reason. The job of a constructor is to fully initialize the object and it's member variables, having a (public) init function often shows already a bad design.

The function takes a pointer to the Render Window and then uses it to draw the sprite (held within the class).
The overall design is not exactly clear here, but I'd say a pointer is unnecessary and a reference would do the trick too.

Although, when I draw like this, it shows as a white box. In order to draw correctly, before I draw I must set the image once again.
This sounds like the Image gets moved in memory between setting the Image to the Sprite and drawing the Sprite, thus the reference the Sprite holds is invalid. But without code it's impossible to tell.

I have done lots of problem testing and found out its not an obvious fault in my code (as in it is indeed being called and indeed being drawn correctly).
Well C++ is quite complex and one has to learn a lot, even after years of programming with it. But I guess the problem here, is just a not so nice code design plus a small lack of knowledge in C++ basics.

P.P.S. if it helps, the classes that do this are stored within a std::vector<--class-->.
Go on... (= show code). :D

1) That's interesting. When I went on SFML I clicked download current version. Does that happen to be 1.6? I shall update!

2) So shall I create an imageHolder (or something) class (or struct, which would be better?) that contains instances of all images?

3) Yes, but the init function takes arguments. I don't think constructors can take arguments. Is it a better idea to just use a ton of getter and setter functions?

4) Elaborate?

5) Ok, I shall provide code. I was avoiding doing that because i'd have to strip down a ton of unrelated stuff from the main.cpp and the enemy.h and enemy.cpp and stage.h and stage.cpp, which would take some time since they're all huge, and I wanted to avoid taking this much time if by any chance it wasn't necessary.

6) I meant, I'm logging when things happen, to make sure they happen, and it is indeed happening, therefore the function of drawing and setting image is being called at the very least. Also, forgive me, I'm a nooblet at C++, but I have quite a bit of Python experience which is much easier :P

7) Code below

http://pastebin.com/712QvpdA

If you need to see any other file please specify. Files are: enemy.h, enemy.cpp, bullethandler.h, bullethandler.cpp, bullet.h, bullet.cpp, stagestats.h, stagestats.cpp, stage.h, stage.cpp, player.h, player.cpp, main.cpp, inputhandler.h, inputhandler.cpp

If you need to know about the design please ask. I would greatly appreciate if you give tips on how I could improve this, and the design of the whole thing. Thanks!

6
Hi! I have a class, within that class contains a Sprite and an Image and a ton of other irrelevant stuff. Anyway, I have an init function. This function is called to initiate all the good stuffs including setting the image for the sprite. I also have a function that is called to draw this sprite. The function takes a pointer to the Render Window and then uses it to draw the sprite (held within the class). Although, when I draw like this, it shows as a white box. In order to draw correctly, before I draw I must set the image once again. This is very very odd as I have yet another class that doesn't do this (I only have to set the image once) and another class that does ALSO do this. I have done lots of problem testing and found out its not an obvious fault in my code (as in it is indeed being called and indeed being drawn correctly).

Anyway, please help me with this, bros.

P.S. the classes dynamically change coordinates. But the class that doesn't do the resetting thing also changes coords. So that's also odd.

P.P.S. if it helps, the classes that do this are stored within a std::vector<--class-->.

7
Hi. I'm making a game that involves pixels. When I display a sprite, it becomes antialiased (all fuzzy). How can I make it aliased (sharp) like the actual .png is? Thanks!

Pages: [1]