Jump to content

  • Log In with Google      Sign In   
  • Create Account

Cdrandin

Member Since 01 Dec 2012
Offline Last Active Nov 26 2013 12:42 PM

Topics I've Started

SFML fail to load image as texture

26 June 2013 - 02:05 PM

Hello everyone,

I have come to a problem with the code below ...

Using SFML 2.0

#include <SFML/Graphics.hpp>

#include <iostream>
#include <list>

int main()
{
	float speed = 5.0f;

    // create the window
    sf::RenderWindow window(sf::VideoMode(sf::VideoMode::getDesktopMode().height - 300, 800), "Breaking Bricks");

	// Set game window position on the screen
	window.setPosition( sf::Vector2i(sf::VideoMode::getDesktopMode().width/4 + sf::VideoMode::getDesktopMode().width/16 , 0) );

	// Allow library to accept repeatitive key presses (i.e. holding key)
	window.setKeyRepeatEnabled(true);

	// Hide mouse cursor
	//window.setMouseCursorVisible(false);

	// Limit 30 frames per sec; the minimum for all games
	window.setFramerateLimit(30);
	
	sf::Texture texture;
	if (!texture.loadFromFile("tile.png", sf::IntRect(0, 0, 125, 32)))
	{
		std::cout<<"Could not load image\n";
		return -1;
	}

	// Empty list of sprites
	std::list<sf::Sprite> spriteContainer;
	bool gameFocus = true;

    // run the program as long as the window is open
    while (window.isOpen())
    {
		sf::Vector2i mousePos = sf::Mouse::getPosition(window);

        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
			float offsetX = 0.0f, offsetY = 0.0f;

			if(event.type == sf::Event::GainedFocus)
				gameFocus = !gameFocus;
			else if(event.type == sf::Event::LostFocus)
				gameFocus = !gameFocus;

			if(event.type == sf::Event::KeyPressed)
			{
				if (event.key.code == sf::Keyboard::Space)
				{
					if(gameFocus)
					{
						// Create sprite and add features before putting it into container
						sf::Sprite sprite(texture);
						sprite.scale(.9f,.7f);
						sf::Vector2u textSize = texture.getSize();

						sprite.setPosition(sf::Vector2f(mousePos.x-textSize.x/2.0f, mousePos.y - textSize.y/2.0f));

						spriteContainer.push_front(sprite);
					}
				}

				if(event.key.code == sf::Keyboard::P)
					std::cout << spriteContainer.size() << std::endl;

				if( event.key.code == sf::Keyboard::W )
					offsetY -= speed;

				if( event.key.code == sf::Keyboard::A )
					offsetX -= speed;

				if( event.key.code == sf::Keyboard::S )
					offsetY += speed;

				if( event.key.code == sf::Keyboard::D )
					offsetX += speed;
			}

            // "close requested" event: we close the window
			if (event.type == sf::Event::Closed || event.key.code == sf::Keyboard::Escape)
                window.close();

			// Move all sprites synchronously
			for (std::list<sf::Sprite>::iterator sprite = spriteContainer.begin(); sprite != spriteContainer.end(); ++sprite)
				sprite->move(offsetX, offsetY);

			//sprite.move(offsetX,offsetY);
        }

        // clear the window with black color
        window.clear(sf::Color::Black);

        // draw everything here...
        // window.draw(...);
		// Draw all sprites in the container
		for (std::list<sf::Sprite>::iterator sprite = spriteContainer.begin(); sprite != spriteContainer.end(); ++sprite)
				window.draw(*sprite);

        // end the current frame
        window.display();
    }

    return 0;
}

A couple weeks ago it worked flawlessly to my expectation, but now that I come back to it and I am having problems importing the image as a texture "tile.png". I don't understand why this is evening happening and the only message I get via the terminal is "Cannot load image ..." then a bunch of random characters. My libraries are for sure working, but now I am not sure why the image is not loading. My image is in the same directory as with my .h and .cpp files.

 

This is an irritating problem that keep coming up for some reason and is always a problem to fix it.

 

I import my libraries via my own directory "locals" which contain many APIs, but I specifically get SFML, and done appropriately as I am able to open a window and many other stuff.


What are some libraries and techniques that game dev's should know?

03 February 2013 - 10:28 PM

What are some C++/C libraries and some techniques that game developers should know when working with C++?

Like I can do some stuff if I put my mind to it, but it will never be optimized.  How can I think  in a fashion which I try to get the most power and speed out of C++.

Like I have heard to avoid using STL because of there restricting and "slow" when taking to a advance level.

 

I am not beginner, but I am also no professional software engineer.  I am in school learning, but not many courses seem to talk about advance techniques in C++, like some stuff people don't first noticed until a lot of research.


Low level design of a tiled based movement game

31 January 2013 - 11:56 AM

So, I want to make a 3D tiled turned based strategy game like Fire Emblem.  My only problem thus far is coming up with a solution on how to implement a tile based environment and the possible movement each unit can move.  For the movement my though was using something as A*, but modify, but just not sure how to mimic the tiled logic.  I will be using Unity to build this game on.  If anyone knows any good articles or ideas on how to achieve it would be appreciated.


Is it worth investing time to learn 3D modeling.

17 January 2013 - 10:02 PM

I have never done art before, but I am trying to make my game visual appealing. So, far I am using a model I got online as the player and working on the gameplay with the model for now.  Just wondering if I should bother making my own character player and animations, but I have no idea on how to do any of that.  I know how to do all the programming stuff and I do prefer programming.  Just wondering what can I do to get some models with animations, or something very basic to use in my game.

 

I just want to simple archer, to be idle, run, shoot, jump.  I have a model that is an archer, but has no animations.  The other problem is I don't know if I can even make an animation for it because there are no children nodes on this character model.  It is just one big model with no rigging or anything.

 

Just looking for some wisdom and how to approach this.  I am currently focus on getting my game play down, but eventually I will need to get my animations down.


Need help on how to instantiate a class in Boo in Unity

11 January 2013 - 01:26 AM

Here is the post, Kinda long and was neatly prepared here.  The class itself isn't really important, just the initial setup.

http://answers.unity3d.com/questions/378485/how-can-i-instantiate-my-variables-in-boo-having-p.html

 

I got it to work in Unityscript, but I prefer to use Boo.  Also, if someone could explain why this is happening.

 

I also got Unity to stop complaining with the following:

class CombatController (MonoBehaviour): 
	public Robo as PlayerAttributes
	
	def Start ():
		Robo = GetComponent(PlayerAttributes)
		Robo.SetInitialStats('Robo', 20, 21, 19, 20, 18, 22, 22, 57000)

 

But my Robo variable which is of class PlayerAttributes is't affected at all according to the inspector. 

 


PARTNERS