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

Pages: [1]
1
Graphics / Is there a way to combine (add) sprites?
« on: November 15, 2015, 02:56:30 am »
Say, I have this sprite from a robot texture, BUT THE ROBOT IS ON FIRE!!!

And I want to draw a robot on fire.

Luckily I have a semi-transparent fire texture that I want to draw over the robot. I know I can just draw the robot sprite, and then draw the fire sprite over it. But that would require using two sprites.

To keep things simple, I made my robot class give out its own sprite (so it can handle its own movement animations and stuff), but it can only return a single sprite. And I would prefer that the robot class itself detected the robot is on fire and gave out a sprite with the robot on fire to be drawn.

Any way to achieve this (other than duplicating all my sprite sheets and adding a fire on the copies)?

2
General / Re: Strange behaviour with thor animations
« on: November 09, 2015, 04:43:15 am »
I think I figured it out. I was passing the whole sf::Clock object, and calling restart on every Robot object. Logically, the .restart() call was messing up with the numbers. I'll try calling .restart only once and sending the return value of that to the Robot objects.

3
General / Strange behaviour with thor animations
« on: November 09, 2015, 03:49:34 am »
So, I made my Robot objects hold their own thor::Animator objects, and made member functions to play the animations included in the thor::Animator object.

I keep pointers to my Robot objects inside a vector, which I pass as argument to my Game_Logic class, by copy if I'm not mistaken.

The thing is, for the first element of the robot vector, the animations play fine. For the second and subsequent robot objects, the animations only display the first frame, and get stuck there. The Robot objects are all exactly the same, so I have no clue what might be making this wrong.

It's hard to put some minimal code, because the sprites are generated by the Robot objects, which are then put together on a vector along with other sprites by Game_Logic, and given to Game_Screen to be drawn. I'll try to paste some relevant code

Oh, and the sf::Clock object I use is passed by reference to all objects. I dunno if it matters, though.

This is the innards of the Robot class

Robot::Robot()
{
        thor::FrameAnimation attack;
        attack.addFrame(1, sf::IntRect(60, 0, 60, 60));
        attack.addFrame(1, sf::IntRect(60, 60, 60, 60));
        attack.addFrame(1, sf::IntRect(60, 0, 60, 60));
        m_animator.addAnimation("attack", attack, sf::seconds(1));
}

sf::Sprite Robot::r_sprite(sf::Clock& clock)
{
        sf::Sprite sprite(m_texture, sf::IntRect(0, 0, 60, 60));       

        m_animator.update(clock.restart());    
        m_animator.animate(sprite);    
        sprite.setPosition(m_pos.x * 60, m_pos.y * 60);
        return sprite;
}

void Robot::play_anim(std::string anim)
{
        m_animator.playAnimation(anim);
}
 
This is the part of Game_Logic that gets the sprites:

std::vector<sf::Sprite> Game_Logic::r_drawables(sf::Clock& clock)
{
        std::vector<sf::Sprite> drawables;
        Entity* pl_entity;

        for (unsigned int i = 0; i < m_player_entities.size(); i++)
        {
                pl_entity = m_player_entities[i];
                drawables.push_back(pl_entity->r_sprite(clock));
        }
        for (unsigned int i = 0; i < m_AI_entities.size(); i++)
        {
                drawables.push_back(m_AI_entities[i]->r_sprite(clock));
        }
        return drawables;
}

And this is the part of Game_Screen that gets the sprites and draws stuff:

        m_drawables = m_game_logic->r_drawables(clock);
        for (unsigned int i = 0; i < m_drawables.size(); i++)
        {
                window->draw(m_drawables[i]);
        }
        window->display();

4
General / Re: How to make edge scrolling work with windowed mode?
« on: October 26, 2015, 11:36:07 am »
It's the real code, and guess what, if I copy that code to other project, it works. In the current project it works only on two directions (right and down). To the left and up I have to find the exact 0 pixel for it to work. I don't know what can be wrong, I'm going mad searching for it.

Well, if it works on other projects, then it's other part of your code what is causing the problem. What you can do is "minimize" your project (deleting or commenting code) until the problem dissappears, that way you'll discover the root of the problem, fix it, and then put the rest of the code back. This will be tedious as hell if your project is too big, though.

Found the problem. I was comparing an int with an unsigned int. Jesus. Hahaha.

The window::getSize() returns a sf::Vector2u. And the mouse position sf::Mouse::getPosition() returns a sf::Vector2i.

Just lovely :)

5
General / Re: How to make edge scrolling work with windowed mode?
« on: October 25, 2015, 06:16:57 pm »
I also move the camera the same way as you, using sf::Mouse::getPosition(), sf::View::getCenter() and sf::View::move(), and I have no problems with scrolling in windowed mode if the mouse is outside the window (on Windows 7 at least). In fact, I had to limit the scrolling to only happen if the cursor is inside the window because it's annoying to me when it scrolls when I move the mouse outside to do something else. Keep this in mind for your game, you could add an option to toggle "outside-of-window-scrolling" on and off, some people (like me) may appreciate it :P

I can't see anything wrong with your code (asumming that's the real one), so I can't really help you. Maybe it's something silly like both "if" statements happening at once for some strange reason, moving the view both left and right at the same time so they cancel each other out. You said that using std::cout shows the positions as negative, which is good, so maybe is the second part of the condition the problem (view_position.x >= view.getSize().x/2 +15, etc.).

It's the real code, and guess what, if I copy that code to other project, it works. In the current project it works only on two directions (right and down). To the left and up I have to find the exact 0 pixel for it to work. I don't know what can be wrong, I'm going mad searching for it.

6
General / Re: How to make edge scrolling work with windowed mode?
« on: October 23, 2015, 02:23:20 pm »
I'm using View.Center property instead of MoveTo and camera moving across the map just perfectly with no any issues. It works in windowed and fullscreen mode and even with switch between these modes.

It works even if you go beyond the border of the window? Care to share that piece of code? :)

7
General / How to make edge scrolling work with windowed mode?
« on: October 23, 2015, 03:13:47 am »
Hey.

Right now, my the game detects the edge of the screen (pixel 0 and pixel window_width), but once you go past it, it stops the scrolling.

I checked with std::cout, and it keeps registering the positions as negative, when out of screen, and that's the expected behaviour, but for some reason, it doesn't keep scrolling.

It works fine in fullscreen mode, but that's horrible for debugging, and I'm sure many players will want to play the game windowed.

How to solve this?

Here's the code:

Quote
      sf::Vector2i localPosition = sf::Mouse::getPosition(*window);
      sf::Vector2f view_position = view.getCenter();

      //Scrolling the map
      if (localPosition.x <= 0 && view_position.x >= view.getSize().x/2 +15) view.move(-15, 0);
      if (localPosition.x >= WINDOW_SIZE.x-1 && view_position.x <= map_size_pixels.x - view.getSize().x/2 -15) view.move(15, 0);      
      if (localPosition.y <= 0 && view_position.y >= view.getSize().y/2 +15) view.move(0, -15);
      if (localPosition.y >= WINDOW_SIZE.y-1 && view_position.y <= map_size_pixels.y - view.getSize().y/2 -15) view.move(0, 15);

8
Uh, I usually search before posting, but I think I didn't this time. My bad.

Thanks for your answer, tho, I'll check out the other threads.

9
This is more of a design decision than a technical issue.

So, I'm wondering about this. I have this design decision, where I can store the sprites of several objects inside them, and request them when I want to draw them (every frame), or I can store all the sprites in a container (vector, or a map, a map would be ideal, I guess) inside the class responsible for drawing the stuff.

The thing is, the position is of each object is saved inside the object itself, so it's much easier to just ask "gimme your sprite" and receive a ready sprite at the right location and draw them, then to keep track of which sprite belongs to each object, and have to ask the object for his position, then set the sprite coordinates.

 I'll have objects die (it's a game after all, stuff dies), if I keep the sprites inside the class, I'll have to keep track of which objects died and remove their sprites too. If I keep on the objects, once they die, they will be removed and it won't be on the list of things to draw anymore.

The only drawbacks I can see to keeping the sprites inside the objects they belong to is that the objects will have to know the size of the map squares to calculate their position properly AND it can be slow if copying sprites is slow. Alternatively, I can just make a member function to return a pointer to the sprite and draw the sprite from inside the object directly, but maybe that hurts encapsulation?

:)

Loads of options, loads of ways to shoot yourself in the foot in the future.

10
General / Help me with this doubt.
« on: October 14, 2015, 12:07:45 am »
I wrote a class to draw my game screen. When it initializes, it draws some stuff to a window pointer. The funny thing is, if I call window.display() from the same member function that draws the stuff to the window, I get everything working correctly. But if I wait to call window.display() after the member function returns, the stuff is drawn, but I get flickering. Why does this happen?

Lemme post some code so you can understand, if I was not clear enough:

This works:

   
Quote
tgui::Gui *p_gui = &gui;
   sf::RenderWindow *p_window = &window;
   Game_State *game_screen = new Game_Screen();
   game_screen->start(p_gui, p_window);

void Game_Screen::start(tgui::Gui *gui, sf::RenderWindow *window)
{   
   sf::Texture map_texture;
   if (!map_texture.loadFromFile("test_map.png"))
   {
      std::cout << "Failed to load map file" << std::endl;
   }

   sf::Sprite map_sprite;
   map_sprite.setTexture(map_texture);

   sf::View view(sf::FloatRect(0, 0, 600, 600));
   view.setViewport(sf::FloatRect(0, 0, 0.75, 1));

   window->clear();
   window->setView(view);
   window->draw(map_sprite);
   window->display();   
}
//----------MEMBER FUNCTION ENDS HERE, WINDOW LOOP STARTS

   while (window.isOpen())
   {
      sf::Event event;
      while (window.pollEvent(event))
      {
         if (event.type == sf::Event::Closed)
            window.close();
      }
      window.display();
   }

This doesn't.

   
Quote
tgui::Gui *p_gui = &gui;
   sf::RenderWindow *p_window = &window;
   Game_State *game_screen = new Game_Screen();
   game_screen->start(p_gui, p_window);

void Game_Screen::start(tgui::Gui *gui, sf::RenderWindow *window)
{   
   sf::Texture map_texture;
   if (!map_texture.loadFromFile("test_map.png"))
   {
      std::cout << "Failed to load map file" << std::endl;
   }

   sf::Sprite map_sprite;
   map_sprite.setTexture(map_texture);

   sf::View view(sf::FloatRect(0, 0, 600, 600));
   view.setViewport(sf::FloatRect(0, 0, 0.75, 1));

   window->clear();
   window->setView(view);
   window->draw(map_sprite);
}
//----------MEMBER FUNCTION ENDS HERE, WINDOW LOOP STARTS

   while (window.isOpen())
   {
      sf::Event event;
      while (window.pollEvent(event))
      {
         if (event.type == sf::Event::Closed)
            window.close();
      }
      window.display();
   }



11
General / Re: First-chance exception on running the tutorial code
« on: October 09, 2015, 07:52:59 pm »
Setup was correct.

I have no clue what a call stack is, or where I can find it. :D

I "solved" it by downloading visual studio 2015 and getting the library for it. It's running properly now.

If you wanna link something about call stacks so I can educate myself I would be thankful. :)

12
General / Re: First-chance exception on running the tutorial code
« on: October 08, 2015, 11:17:38 pm »
As far as I know, I didn't mix them.

I downloaded the "Visual C++ 12 (2013) - 32-bit" package, and I'm pretty sure I set the libraries called sfml-xxxx-d.lib to the debug, and the regular ones to the release. Again, I'm on win7 64 bit, and using Visual Studio 2013.

What else could it be?

13
General / First-chance exception on running the tutorial code
« on: October 08, 2015, 09:23:46 pm »
Hey. I'm trying to set up SFML on Visual Studio 2013, I'm using win7 64 bits.

I'm having troubles, the green circle from the tutorial shows up, but when I click the close button, I get a dialog window with:
"bluerobots.exe has triggered a breakpoint."

or it doesn't give me a dialog window but writes:

"First-chance exception at 0x776A332F (ntdll.dll) in bluerobots.exe: 0xC0000005: Access violation reading location 0x00000004."

or sometimes gives yet another strange error. But these two are the most commom.

Here's the whole code:

Quote
#pragma once
#include <iostream>
#include <SFML\Graphics.hpp>

int main()
{
   sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
   sf::CircleShape shape(100.f);
   shape.setFillColor(sf::Color::Green);
   
   while (window.isOpen())
   {
      sf::Event event;
      while (window.pollEvent(event))
      {
         if (event.type == sf::Event::Closed)
            window.close();
      }

      window.clear();
      window.draw(shape);
      window.display();
   }
   return 0;
}

Pages: [1]
anything