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

Pages: [1]
1
Graphics / Re: Can't see my vertex array.
« on: January 02, 2018, 02:56:03 pm »
I want to display a whole row of hearts, not just one. Also, could you point out some of the serious mistakes, I know a few of them that I'm going to fix but it'll be good to know the rest. Thanks.

2
Graphics / Can't see my vertex array.
« on: January 02, 2018, 02:32:33 pm »
Based on the tileset from the vertex array tutorial, I have tried to make my own variant for hearts, since i know the tile size and that it will only be one row, I can eliminate some variables.

class health: public sf::Drawable, public sf::Transformable {
public:
        int hp;
        sf::Texture heartTexture;
       
        sf::VertexArray m_vertices;
        void init(void) {
                heartTexture.loadFromFile("Heart.png");
                hp = 12;
        }
        void load(void) {
                int x = 0;
                m_vertices.setPrimitiveType(sf::Quads);
                m_vertices.resize(ceil(hp / 4));
                //Looping throughout each heart.
                for (x = 0; x <= m_vertices.getVertexCount(); x++) {
                       
                        if (x == m_vertices.getVertexCount()) {
                                sf::Vertex* quad = &m_vertices[x];
                                quad[0].position = sf::Vector2f(10 + x * 32, 50);
                                quad[1].position = sf::Vector2f(10 + ((x + 1) * 32), 50);
                                quad[2].position = sf::Vector2f(10 + ((x + 1) * 32), 82);
                                quad[3].position = sf::Vector2f(10 + x * 32, 82);

                                quad[0].texCoords = sf::Vector2f((4-(hp % 4)) * 32, 0);
                                quad[1].texCoords = sf::Vector2f(4-((hp % 4)) * 32 + 32, 0);
                                quad[2].texCoords = sf::Vector2f((4-(hp % 4)) * 32 + 32, 32);
                                quad[3].texCoords = sf::Vector2f((4-(hp % 4)) * 32, 32);
                        }
                        else {
                                sf::Vertex* quad = &m_vertices[x];
                                quad[0].position = sf::Vector2f(10 + x * 32,50);
                                quad[1].position = sf::Vector2f(10 + ((x + 1) * 32), 50);
                                quad[2].position = sf::Vector2f(10 + ((x + 1) * 32), 82);
                                quad[3].position = sf::Vector2f(10 + x * 32, 82);

                                quad[0].texCoords = sf::Vector2f(0, 0);
                                quad[1].texCoords = sf::Vector2f(0 + 32, 0);
                                quad[2].texCoords = sf::Vector2f(0 + 32, 32);
                                quad[3].texCoords = sf::Vector2f(0, 32);

                        }// End If else
                }
        }// end of function
private:
        virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
        {
                // apply the transform
                states.transform *= getTransform();
                states.texture = &heartTexture;

                // draw the vertex array
                target.draw(m_vertices, states);
        }
};

and a simplified version of the main that uses it.
int main() {
       
       
       
        sf::RenderWindow windows(sf::VideoMode(800,600), "Game");
        windows.setFramerateLimit(60);
health p1Health;
        p1Health.init();
        p1Health.load();
while (windows.isOpen()) {
       
                        // check all the window's events that were triggered since the last iteration of the loop
                        sf::Event event;
                        while (windows.pollEvent(event))
                        {
                                // "close requested" event: we close the window
                                if (event.type == sf::Event::Closed)
                                        windows.close();
                        }
        windows.clear();
                        windows.draw(p1.charSprite);
                        windows.draw(box.hurtbox);
                        windows.draw(p1Health);
                        windows.display();

        }
       
        return 0;
}
however when I load up the program I see no heart, but there are no errors. Each heart image is 32*32, and there are four of them in one texture. The image is attached.

3
General / Using Partial filenames
« on: November 19, 2017, 08:52:44 am »
just a simple question, how would I program opening an image from a folder which is in the directory folder? Or for a file somewhere else?"

4
Graphics / Re: Can move up but not down.
« on: August 22, 2017, 10:29:59 am »
Thanks a lot.

The yReset function was to see if the position of the sprite was above or below a certain yPos, and if it was, to bring it back below the threshold. I had removed what it contained because it didn't affect the result. However, it was converting a float to an int, rounding it and not moving down.

Can you please elaborate on what you mean by "Key repeat delay"? It's responsive as far as I can tell.

And if I shouldn't use decimals, how should I move my character at a non-supersonic rate?


5
Graphics / Can move up but not down.
« on: August 22, 2017, 07:59:13 am »
 
       
sf::Vector2f buttonCheck() {
        sf::Vector2f key = sf::Vector2f(0, 0);
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
                key.x -= 1;
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
                key.x += 1;
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
                key.y -= 1;
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
                key.y += 1;
        }

        return key;
}

int yReset(int yPos) {
       
//     Yup, literally nothing
        return yPos;
}



charSprite.move(0.25 * keyCheck.x , 0.25 * keyCheck.y);
charSprite.setPosition(charSprite.getPosition().x, yReset(charSprite.getPosition().y )
//Where keycheck is the return of the button check function.


);

However, if I remove the yReset, I can move down.

Why?
Any help is appreciated.

6
Graphics / Shape Functions not working in classes.
« on: June 10, 2017, 12:06:15 pm »
#include <SFML/Graphics.hpp>
#include <SFML\System.hpp>
#include <SFML\Window.hpp>




class player {
public:
        int the = 5; //Works
        sf::Font font; //Works
        sf::RectangleShape shape(sf::Vector2f(50, 50)); //Does not
        sf::CircleShape circle(50); //Does not
};
int main()
{
        sf::CircleShape circle2(50); //Does

 
It gives me the error "Function definition for ( shape name, not class) not found."
I don't think this is a sfml linking problem, but I could be wrong.
I am using VS 2015, If that matters.
Thanks in advance.

7
Graphics / Can you make a sprite move the way it's rotated?
« on: February 08, 2017, 07:13:33 am »
 :) :D  ;D

Can you make a sprite move the way it's rotated?

For example
sprite.setRotation(60);
sprite.move(60); //but in the way it's rotated;

Thanks in advance? 8) 8) 8) 8) 8) 8)

8
General / Returning sprites through functions.
« on: December 10, 2016, 06:23:26 am »
I have a header file that has a function. That loads my sprites since I have 35 of the same. However, I need to draw the sprites in my main file. Or, If there is a better way to do this?

How would I return my 35 sprites to my main file?

Code

Pathfind.h
#pragma once

#include<iostream>
#include<cmath>

//Sfml Includes
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>




void createMap(int) {

        int rowNumber = 1;
        sf::Texture mapSprites;
        int map[35] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
        int tileNumber = 1;

        if (!mapSprites.loadFromFile("LevelSprites.png")) {

                std::cout << "mapSprites not Loading" << std::endl;
        } //For loading the sprites.

        std::vector<sf::Sprite> sprites(35, sf::Sprite(mapSprites));


        for(tileNumber = 0; tileNumber < 35; tileNumber++) {
               
                if (map[tileNumber] == 0){
                       
                        for (int i = 0; i < sprites.size(); i++) {
                               
                               
                                sprites[i].setTextureRect(sf::IntRect(0, 0, 60, 60)); //First panel
                                sprites[i].setPosition( (tileNumber % 7 + 1) * 60, rowNumber * 60);
                                sprites[i].setScale(2, 2);
                        }
               
                }//end if statement
                if (tileNumber % 7 == 0)
                        rowNumber++;
        }//ends for statement

       
}

Main code
#include<iostream>
#include <cstdlib> //Random No
#include <ctime> //Time
//Sfml Includes
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>

#include"Pathfind.h"
int main() {


        std::cout << "Swords of Alleria Start" << std::endl;
        sf::RenderWindow window(sf::VideoMode(840, 600), "Swords of Alleria");
        sf::Event CloseCheck;  
        window.setFramerateLimit(60);

       
        sf::Font font;
        createMap(0);
        if (!font.loadFromFile("corbel.ttf")) {

                std::cout << "Error: Font not found." << std::endl;

        }
        else {

                std::cout << "Font corble Loaded" << std::endl;
        }

        //Random Seed
        srand(time(NULL));

        while (window.isOpen())
        {
               
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Return)) {

                }
                while (window.pollEvent(CloseCheck))
                {
                       
                        if (CloseCheck.type == sf::Event::Closed)
                                window.close();
                }
               
                window.clear(sf::Color::Black);
                //I need to draw them here

                window.display();
        }



        return 0;
}

thanks in advance.

9
SFML projects / Re: Simple Paddle - a simpleton's attempt at Pong!
« on: December 07, 2016, 07:35:21 am »
I'd Love an Ai for this :D :D

10
SFML projects / Re: Racod's lair - a coop dungeon crawler [Demo Release]
« on: December 07, 2016, 07:33:54 am »
I found a glitch I have not been able to replicate.

I switch my quickslot to no 1.
Pressed enter on a wooden chest(thought they opened)

Crash.

Pages: [1]