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

Pages: [1] 2 3
Graphics / How incorporate more tiles instead of just one?
« on: June 29, 2014, 09:37:10 am »
How would I add more than one tile to this vertex map? Haven't been able to find a solution, and my ideas that I have tried are very slim on working.

I want to be able to use more than on tile (like look at an array and replace the numbers with a tile???)

Any clues/help to get me started?
class MapLoader : public TileLoader
        m_mapdata.MapX = 100;
        m_mapdata.MapY = 100;
        m_mapdata.TextureName = "0.gif";
    virtual void AppendTile(int gx, int gy, sf::VertexArray& garr)
        sf::Vertex ver;
        ver.position = sf::Vector2f(gx*16.f, gy*16.f);
        ver.texCoords = sf::Vector2f(0.f, 0.f);

        ver.position = sf::Vector2f(gx*16.f + 16.f, gy*16.f);
        ver.texCoords = sf::Vector2f(16.f, 0.f);

        ver.position = sf::Vector2f(gx*16.f + 16.f, gy*16.f + 16.f);
        ver.texCoords = sf::Vector2f(16.f, 16.f);

        ver.position = sf::Vector2f(gx*16.f, gy*16.f + 16.f);
        ver.texCoords = sf::Vector2f(0.f, 16.f);

but the tile number your on
What does "you're on" mean? Who is "you"? The mouse cursor? A game object? Please express yourself clearly.

If you have the coordinates, you can divide them by the tile size to learn the tile index. If the vertex array doesn't start at (0,0), you have to offset accordingly.

Sorry, the "you" is the gameobject, I haven't gotten the coordinates as of yet.

showing what tile your on
What does that mean? Do you want to get the tile coordinates? Or something else?

Coordinates would be good, but the tile number your on; 1, 12, 4 etc. Where the level is loaded, that number array, finding out which number your sitting on.

How would you go about showing what tile your on with a VertexArray Tilemap that is based mostly on the example?

Really simple answer, but I'm just lost at where to start with it.



Graphics / Re: Changing Sprite Texture on key press not working?
« on: June 13, 2014, 01:45:21 pm »

Had a line that was continuously replacing the texture back to the normal. Was in a function being looped and moved that out and works well.

Move this out of PlayerSetup and into Init()
p_sprite.setTexture(tp_sprite);//Set Texture

Graphics / Re: Changing Sprite Texture on key press not working?
« on: June 13, 2014, 10:21:10 am »
No, I don't do everything on the one line, the issue I have is that when I hit another key, it doesn't change the sprites texture.  This is the part of the script that controls the player and movement

#include <SFML/Graphics.hpp>
#include <iostream>
#include "Lester.h"

sf::Texture tp_sprite_l, tp_sprite_r, tp_sprite_d, tp_sprite;
sf::Sprite p_sprite, p_sprite_l, p_sprite_r, p_sprite_d;

void Lester::PlayerSetup()



    p_sprite.setTexture(tp_sprite);//Set Texture

void Lester::KeyInput()

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape) || sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Q)){ window->close(); }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A))  p_sprite.move(-4, 0); m_view->move(-4, 0); std::cout << "LEFT" << std::endl;
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)){ p_sprite.move(4, 0); m_view->move(4, 0); std::cout << "RIGHT" << std::endl; }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S)){ p_sprite.move(0, 4); m_view->move(0, 4); std::cout << "DOWN" << std::endl; }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W)){ p_sprite.move(0, -4); m_view->move(0, -4); std::cout << "UP" << std::endl; }
void Lester::Screen()

    window->setView(*m_view);//Set Game View
    Map();//Call Map
void Lester::GameScreen()
void Lester::GameLoop()
    window = new sf::RenderWindow(sf::VideoMode(960, 550, 32), "Lester V:0.1");
    m_view = new sf::View(sf::FloatRect(200, 200, 300, 200));//View Port
    m_view->zoom(0.7f);//Set Zoom

    window->setFramerateLimit(60);//Set FrameRate

    p_sprite.setPosition(300, 250);

    while (window->isOpen())

        sf::Event event;
        while (window->pollEvent(event))
            if (event.type == sf::Event::Closed)
        running = true;

        while (splash_set == false){window->display();splash_set = true;}        
        if (splash_set == true){ window->clear(); KeyInput();PlayerSetup(); GameScreen(); window->display(); }
void Lester::Init(){ GameLoop(); }



I've been stuck on this for a few hours now, and I'm lost. I have a if statement that lets me move my sprite, but for it to control the player, I need it to change the sprite texture according to what key is pressed,

I have this for my if statement to change the texture :

if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)){ p_sprite.move(4,0); p_sprite.setTexture(tp_left);}

I have the textures setup in the header file as
sf::Texture tp_left;tp_left.loadFromFile('left.jpg');

Im drawing the sprite, the player loads fine and I can move correctly, just the changing of textures of the player on certain keys is confusing me.

Thanks :)

Graphics / Re: No Errors, but Sprite wont draw?
« on: May 15, 2014, 01:01:48 pm »
You should not be drawing the sprite in your player's constructor/init method.  draw() calls should only happen in between the clear() and display() calls of your main loop.  If PlayerSetup() is being called every frame, then only draw() should be in there.

This is being called after a statement returns true
If you feel the need to describe more of your code, that implies you haven't shown us enough of the code to begin with.  If you need more help be sure to post a *complete* and minimal example.

This the entire cpp file for drawing onto screen. http://pastebin.com/8j59jtvF

I've added the draw() and display() calls in the main loop, and set it so its just draw() in PlayerSetup(), but it still isn't showing?

Graphics / No Errors, but Sprite wont draw?
« on: May 15, 2014, 02:36:42 am »
Hi, I've been having troubles drawing my sprite, in my Player class where I'm loading the images, I get no errors when loading the images for the texture, but when I goto run the application, the sprite isn't showing, I have other objects being drawn as well, I have the player being drawn last after everything else, but still down do anything?

Any Ideas?

Drawing the Characters Sprite (This is being called after a statement returns true)
void Lester::PlayerSetup()
    Player player = *new Player();
    sf::Sprite p_sprite(player.p_sprite);
    p_sprite.setPosition(200, 200);

Player Declarations for sprite image loading
void Player::texture()

    if (!tp_sprite.loadFromFile("data/assets/player/up_char.png")){ std::cout << "Unable to load Player Sprites! Please report this Error!"; }
    else{ std::cout << "Player Sprite was Loaded Correctly"; }


Network / Re: Load Sprite texture from Website
« on: April 20, 2014, 02:20:50 am »
Don't you want to try by yourself first? ;)

It's really easy, and the doc + tutorials are more than enough to guide you.

Can't find any good tutorials with a search :s

Network / Re: Load Sprite texture from Website
« on: April 18, 2014, 08:54:07 am »
Two simple options:

1. Get the image from the website to a memory buffer, then use sf::Texture::loadFromMemory.
2. Save the image from the website to a file, then use sf::Texture::loadFromFile.

Can you justify how one could do this?

Network / Load Sprite texture from Website
« on: April 18, 2014, 08:39:11 am »

What would be the easiest way to convert what I have here, to display my sprites textures instead of using .loadFromFile?

    sf::Http::Request request("image.png", sf::Http::Request::Post);

    sf::Http http("http://mysite.com/");
    sf::Http::Response response = http.sendRequest(request);

    // check the status
    if (response.getStatus() == sf::Http::Response::Ok)
        // check the contents of the response
        std::cout << response.getBody() << std::endl;
        std::cout << "request failed" << std::endl;

This just shows the image.png contents in the console, I want to be able to draw a sprite from fetching the image from the website, is it possible to do this?


Window / Re: Unresolved External on changing Window Size
« on: April 14, 2014, 01:55:06 am »
The code seems fine to me. That error is definitely a linker error. See here:
Linker Tools Error LNK2019

Maybe you are using Visual Studio 2013 and downloaded the libraries from the website? Then you would need to compile SFML yourself.

compiled SFML for my VS Studio 2013, added the .dll files to the project and it still does it.

Window / Re: Unresolved External on changing Window Size
« on: April 14, 2014, 12:37:56 am »
That's a linker error, so you're not linking against the SFML libs correctly.  Reread the SFML build tutorial very carefully and double check all of the IDE settings it mentions.

I've re-read the build tutorial, the IDE settings are the exact same as everything else, before I added that function into my project, it was all working fine.


Window / [Solved] Unresolved External on changing Window Size
« on: April 13, 2014, 01:54:47 pm »
Hello, I have just ran into an error when trying to resize my screen via a function,

error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::setSize(class sf::Vector2<unsigned int> const &)" (__imp_?setSize@Window@sf@@QAEXABV?$Vector2@I@2@@Z) referenced in function "public: void __thiscall Lester::GameScreen(void)" (?GameScreen@Lester@@QAEXXZ)

This is the function resizing:

void Lester::GameScreen()
   window.setTitle("Lester V0.1");
   window.setSize(sf::Vector2u(960, 550));

Any ideas?


Pages: [1] 2 3