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

Pages: 1 ... 3 4 [5]
61
Network / Re: socket.bind() Always Fails
« on: March 03, 2014, 06:34:03 pm »
My bad, I was using a 1.6 tutorial with 2.0. I knew I was doing it, but I was just adjust accordingly because I didn't see there was a 2.0 tutorial for this.
socket.bind(RECEIVE_PORT) != sf::Socket::Done

62
Network / socket.bind() Always Fails [SOLVED]
« on: March 03, 2014, 03:48:25 am »
This says the error message EVERY time, even when it is successful.
            cout << "\nEnter Receiving Port";
            cin >> RECEIVE_PORT;
            socket.unbind();
            if (!socket.bind(RECEIVE_PORT))
            {
                cout << "\nThere was an error binding to [" << RECEIVE_PORT << "]";
            }

For instance, if I say tell it to bind to 5000, it will say it has failed, but I call socket.getLocalPort(), and it says 5000, AND I can call socket.receive(rPacket, sizeof(rPacket), sizet, RECEIVE_IP, RECEIVE_PORT) and it returns success.
So everything works, except that it claims it doesn't. What's going on?

63
General / Re: Not rendering position and rotation accurately
« on: January 07, 2014, 11:24:50 pm »
While I was editing my post you replied, sorry about that.
Anyway, wouldn't it be really messy to put 100+ sprites in a single png file?
Or, is there some way I can load the textures into SFML, and combine them there?

64
General / Re: Not rendering position and rotation accurately
« on: January 07, 2014, 11:06:46 pm »
Using a the TileMap class actually solves the original problem of this post, as well as being faster, so I will definitely use them if possible
And when I said Quad pointer, I meant 4 vertex pointers (for each vertex of a quad), so the object can change the textureCoordinates to change what is being displayed (animation).

This is what I have as an example to loop over pieces of an animation, all part of a .png (4 states):
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::X))
        {
            textureTileX++;

            if(textureTileX == 4)
                textureTileX = 0;

            quad[0].texCoords = sf::Vector2f(textureTileX * tileSize.x, textureTileY * tileSize.y);
            quad[1].texCoords = sf::Vector2f((textureTileX + 1) * tileSize.x, textureTileY * tileSize.y);
            quad[2].texCoords = sf::Vector2f((textureTileX + 1) * tileSize.x, (textureTileY + 1) * tileSize.y);
            quad[3].texCoords = sf::Vector2f(textureTileX * tileSize.x, (textureTileY + 1) * tileSize.y);
        }

Sorry if I didn't understand, but how do I get data from multiple files, for example:

The file "Gun_Type1.png" would ideally only hold the sprite sheet for that specific entity, while "Armor_Type2.png" would hold its own sprite sheet for a different entity. TileMap only lets me load one texture. How do I get around this?

Would I need multiple sf::VertexArrays and a corresponding sf::Textures in the TileMap, so that each call to         
states.texture = loop over textures;
target.draw(loop over vertices, states);
would result in the correct texture being used, for the correct vertices? That doesn't seem like a good solution but it's the only one I have come up with.

65
General / Re: Not rendering position and rotation accurately
« on: January 07, 2014, 02:35:43 am »
If I should post this in a new thread let me know, but it's related to this.

If you look at the first images I posted, the main object is comprised of many sprites (9x19).
Nexus told me to look at Vertex Arrays, which i'm trying to learn to use now: http://www.sfml-dev.org/tutorials/2.0/graphics-vertex-array.php

In the examples, it shows a custom made "TileMap" class that does some of what I need, except for a few things, which I don't really understand.

1. My object will potentially contain 30-40 different images, each of which could have 2-3 states for each sub-block of the object seen in the picture (I just colored it with a gradient to show the different cubes). I can't just have a sprite sheet with 40*3=120, 64x64 images on it.

2. Each block of the object will want to control the state of its image. Before I had each Block object hold its own sprite. Now, they are all grouped together in a tilemap. Should each block object hold a quad pointer now?

66
General / Re: Not rendering position and rotation accurately
« on: January 07, 2014, 12:30:07 am »
Thank you all very much, I would imagine this info is what I needed. Haven't tried the stuff out yet though.

67
General / Re: Not rendering position and rotation accurately
« on: January 06, 2014, 09:00:29 pm »
Well I do updateAllPhysics, then, drawAllSprites and I loop over that. And each cube does need to be its own image.

68
General / Not rendering position and rotation accurately
« on: January 06, 2014, 07:11:06 pm »
I am using Box2D and SFML to make a game.
Everything works great and perfectly except for this.
The problem is that when an object is spinning quickly in Box2D, the sprites start to not render in the correct rotation/position.

I know the problem is probably with Box2D, but I posted there   (http://www.box2d.org/forum/viewtopic.php?f=3&t=9614)   and I haven't gotten any replies, so I figured I would post here, and hopefully get some input on what I could try and do to fix it, if there is anything I can do.

Spinning slowly, 5 rpm maybe:


Spinning at about 40 rpm:


Here is the code that draws the sprite. Drawing happens after the Box2D timeStep().
Each Fixture of the Body has its own sprite, called m_sprite.

    m_sprite.setPosition(scale*(m_pFixture->GetAABB(0).GetCenter().x), scale*(m_pFixture->GetAABB(0).GetCenter().y));//scale is 64
    m_sprite.setRotation(180.0*m_pBody->GetAngle()/PI);//PI is defined as 3.1415926
    m_rWindow.draw(m_sprite);

69
General / Fog of War
« on: September 29, 2013, 05:41:48 pm »
I am making a multiplayer 2D game.
The world is made out of tiles(squares) which have a fixture, a sprite, and other data. My original plan was to have tiles color default to black if the players line of sight wasnt able to see the tile.(calculated using ray traces)
But that doesn't work for a multiplayer game, because if two people are on opposite sides of a wall, they will be able to see what the other can see.

One solution I came up with was that since each player will have his own window, if an object is raytraced by a certain player. Each tile has a true false value for each player that could or couldn't see it. So if player one sees it, the true false value for that player is set to true, while the others is false(since he can't see it) Later on, when each players window comes by to draw the tile, one players will draw it, and the others wont.

I posted because I wan't to know if there is a better solution.

70
General / Re: Custom GUI
« on: August 26, 2013, 11:43:34 pm »
Nice, and one final thing, I asked how the buttons should interact with other things, but didn't really get a response. So, I made the button a template that can store a pointer to some object that it wants to affect. Should I do this in a different way?

///In Button.h
template <typename T>
class Button
{
public:

    //Construct and Destruct
    Button();
    Button(string text);
    Button(T& link);
    Button(T& link, string text);
    Button(T& link, string text, int overHangX, int overHangY);
    Button(T& link, string text, string texture, string font, sf::Vector2f position, int overHangX, int overHangY, int charSize, sf::Color color);
    ~Button();

    //Set
    void setText(string text);//text displayed
    void setFont(string fontFile);//font type
    void setCharSize(int charSize);
    void setTexture(string textureFile);//texture used for sprite
    void setColor(sf::Color color);//color modifyer for sprite
    void setOverHangX(int overHangX);//overHang is how much larger the sprite is than the text
    void setOverHangY(int overHangY);//overHang is how much larger the sprite is than the text
    void setPosition(sf::Vector2f position);//position of button by center

    T setLink(T link);///this allows button to hold a pointer to something!

    //Get
    const string getText();
    const string getFontFile();//returns what type of font is being used
    const string getTextureFile();//returns texture files used for sprite
    const sf::Color getColor();
    const int getOverHangX();//overHang is how much larger the sprite is than the text
    const int getOverHangY();//overHang is how much larger the sprite is than the text
    const int getCharSize();
    const sf::Vector2f getPosition();//returns center of button

    const T getLink();

    //Get but not Set
    const sf::Vector2i getDimensions();//returns size of the sprite, not text size!

    //Take Action
    void leftClicked();//these will do something
    void rightClicked();
    void middleClicked();
    void sideOneClicked();
    void sideTwoClicked();
    void mouseOver();
    void draw(sf::RenderWindow& renderWindow);

private:

    sf::Texture* myTexture;//I need to keep textures until the object is destroyed right?
    sf::Font* myFont;//do i need to keep fonts though?
    sf::Text* myText;
    sf::Sprite* mySprite;
    T* myLink;                      ///==========here it is
};




///In Button.cpp
template <typename T> Button<T>::Button(T& link)
{
    myFont = new sf::Font();
    myText = new sf::Text();
    myTexture = new sf::Texture();
    mySprite = new sf::Sprite();
    myLink = &link;
}

71
General / Re: Custom GUI
« on: August 26, 2013, 04:09:00 pm »
Thanks for your response, and sorry for not being more clear with the question.
My main question is if this:

if (event.type == sf::Event::MouseButtonPressed)
{
    if (event.mouseButton.button == sf::Mouse::Left)
        for(all buttons in the list)
        {
            if (button.getSprite()->getGlobalBounds().contains(window.mapPixelToCoords(mouseCoordinates)))
                button.leftClicked();
//or as you have now suggested button.leftClicked(window.mapPixelToCoords(mouseCoordinates));
        }
}

for(all buttons in the list)
    button.draw(window);

is the correct way to check buttons and draw.

72
General / Custom GUI
« on: August 26, 2013, 05:03:47 am »
I wanted to make my own GUI for learning purposes and for a project i'm doing. I am looking for advice on what I should be doing differently (both in terms of how I used SFML and generic programming practices). I also would like to know the best way to make these buttons interact (in general) with other objects in the world. Here is my code for a Button class that I have made, I didn't write all the functions just to save reading and space. On top of this Button class, I might make a Menu class, to hold and position buttons.

P.S. I looked a lot of my questions up, but it really just came down to a matter of whether I understood it or not, but I can't be certain I did. This code works, (except for the obvious English substitutions) but it's probably not the best method.

class Button
{
public:

    //Construct and Destruct
    Button();
    Button(string text);
    ~Button();

    //Set
    void setText(string text);//text displayed
    void setTexture(string textureFile);//texture used for sprite
    void setFont(string fontFile);//font type
    void setPosition(sf::Vector2f position);//position of button by center
    void setColor(sf::Color color);//color modifyer for sprite
    void setOverHang(int overHang);//overHang is how much larger the sprite is than the text
    void setCharSize(int charSize);

    //Get
    const string getText();
    const sf::Texture getTexture();
    const sf::Font getFont();//returns what type of font is being used
    const sf::Vector2f getPosition();//returns center of button
    const sf::Vector2i getDimensions();//returns size of the sprite, not text size!
    const sf::Color getColor();
    const int getOverHang();
    const int getCharSize();
    const sf::Sprite getSprite();

    //Take Action
    void leftClicked();//these will do something
    void rightClicked();
    void middleClicked();
    void mouseOver();
    void draw(sf::RenderWindow& renderWindow);

private:

    sf::Texture* myTexture;//I need to keep textures until the object is destroyed right?
    sf::Font* myFont;//do i need to keep fonts though?
    sf::Text* myText;
    sf::Sprite* mySprite;
};




///In Button.cpp
Button::Button()
{
    myFont = new sf::Font();
    myText = new sf::Text();
    myTexture = new sf::Texture();
    mySprite = new sf::Sprite();
}
Button::Button(string text)
{
    myFont = new sf::Font();
    myText = new sf::Text();
    myTexture = new sf::Texture();
    mySprite = new sf::Sprite();

    ///inputs
    myText->setString(text);

    ///defaults
    int posX = 100;
    int posY = 100;
    int charSize = 20;
    int overHang = 2;
    myFont->loadFromFile("Georgia.ttf");
    myTexture->loadFromFile("button_grey.png");


    myText->setFont(*myFont);
    myText->setCharacterSize(charSize);
    myText->setStyle(sf::Text::Bold);
    myText->setColor(sf::Color::Black);
    sf::FloatRect textRect = myText->getGlobalBounds();
    myText->setOrigin(textRect.left + (textRect.width/2), textRect.top + (textRect.height/2));
    myText->setPosition(posX, posY);


    sf::IntRect spriteRect(0, 0, textRect.width+2*overHang, textRect.height+2*overHang);
    mySprite->setTexture(*myTexture);
    mySprite->setTextureRect(spriteRect);
    mySprite->setOrigin(spriteRect.width/2, spriteRect.height/2);
    mySprite->setPosition(posX, posY);
    //mySprite->setColor(sf::Color(255, 255, 255, 255));
    mySprite->setPosition(myText->getPosition());
}
Button::~Button()
{
    delete mySprite;
    delete myTexture;
    delete myText;
    delete myFont;
}
void Button::setPosition(sf::Vector2f position)
{
    mySprite->setPosition(position);
    myText->setPosition(position);
}
void Button::setTexture(string textureFile)
{
    myTexture->loadFromFile(textureFile);
}
void Button::setFont(string fontFile)
{
    myFont->loadFromFile(fontFile);
}
void Button::leftClicked()
{
    ///We got left clicked on! do something
}
//same for mouse over, and all other clicked actions
void Button::draw(sf::RenderWindow& renderWindow)
{
    renderWindow.draw(*mySprite);
    renderWindow.draw(*myText);
}


///EXAMPLE CODE
//similar for Mouse Moved ect.
//If i had a menu class, rather than checking against all buttons on screen, i could check whether the
//mouse was over a given menu, one at a time. If yes, go into that menu, do that button, and exit out
//of the loop. Thus not having to check every button on screen.
if (event.type == sf::Event::MouseButtonPressed)
{
    if (event.mouseButton.button == sf::Mouse::Left)
        for(all buttons in the list)
        {
            if (button.getSprite()->getGlobalBounds().contains(window.mapPixelToCoords(mouseCoordinates)))
                button.leftClicked();
        }
}

for(all buttons in the list)
    button.draw(window);

73
Graphics / Re: Optimization while using SFML
« on: March 25, 2013, 04:21:00 am »
Thanks for the replies! :)

Ok, so i'm going to have all the potential states of the thing on a single texture, and when I change what the object looks like, i'm actually just changing what part of the texture is being displayed?
^^ Is that correct? ^^

Also, did the rest of my game design seem good?

74
Graphics / Optimization while using SFML
« on: March 21, 2013, 12:15:58 am »
Hello.

I have been using SFML while developing a game I have been designing for a long time. I'm still "relatively" new to programming (C++ for about 2 years) so I have several questions with my plans. I should give a bit of background before going straight to the graphics part, because maybe the graphics idea is good but the design concept isn't. More likely, they're both bad.

Here is the design concept:
Have a vector of GameEntities.
Each GameEntity has a draw function.
Every frame, go through the vector and draw them on screen at some location.

A player has "control" over one of those entities in the form of a pointer that points at one of the objects, so when he presses a key, it iterates the GameEntities position by a certain amount (movement). Similar things for the rest of things this GameEntity will be able to do.

HERE IS THE GRAPHICS PART:
The class GameEntity has a myTexture pointer variable that dictates what the GameEntity looks like in game. I was originally going to have a different texture for each animation sequence loaded into an array inside the GameEntity when the game loads. So when an event caused it to change its animation, a function would change  what the myTexture pointer is pointing to in the array. But I don't want to go coding anything that is going to be garbage and inefficient. How should I go about this? This game isn't going to be super CPU intensive so I don't need the ABSOLUTE best method, but will this work well enough?

Thanks.

Pages: 1 ... 3 4 [5]