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.


Topics - dove96

Pages: [1]
1
General / Sprites inside a Class
« on: April 11, 2016, 03:48:55 pm »
hi, i have created a class called "Player"

in its header
"Player.h"
#ifndef PLAYER_H
#define PLAYER_H
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>

using namespace std;

class Player
{
public:
 sf::Sprite sprite(){
         sf::Texture texture;
            texture.loadFromFile("gunship.png");
            texture.setSmooth(true);
        sf::Sprite playersprite;
        playersprite.setTexture(texture);
        return playersprite;        
}
 

its cpp file

Player.cpp
#include "Player.h"
Player::Player()
{

}
 

what i am trying to do is to create an object from this class from another cpp file called

newMap.cpp
#include "NewMap.h"
#include "Player.h"
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
int mapPlayers()
{
    sf::RenderWindow map1(sf::VideoMode(1180, 600), "GUNSHIP", sf::Style::None);
            sf::Font font;
            if (!font.loadFromFile("emulogic.ttf"))
            return EXIT_FAILURE;

    sf::Text gametitle("GUNSHIP", font, 54);
            gametitle.setPosition(300,50);

 Player p1;                //created an object p1 from the class player

while(map1.isOpen())
            {
                map1.draw(gametitle);
                while(map1.pollEvent(event))
                {

                }
            map1.draw(p1.sprite());     //i want to draw the sprite of the object P1 from the class Player
            map1.display();
            }
    return 0;
}
 

in the main.cpp
#include "NewMap.h"
 main()
{
mapPlayers();
return 0;
}
 

my code does not have throw an error but it crashes everytime i execute it.
the first result that i had was a blank white rectangle. please help

2
General / How to make a bullet curve
« on: April 03, 2016, 10:06:38 pm »
Hello c++&sfml gurus, i was just wondering if how would i make the bullet(artillery) of my tank curve?? i've been looking for clear explanations and tutorials for this but i haven't found any..
any suggestions please??

sorry if the question is too broad..

3
General / sf::Time and sf::Clock
« on: March 28, 2016, 08:10:27 am »
Hello everyone, i am trying to display a window for 3 seconds,after that it closes. yet why does the window displays on random amount of time. it does not display the way i wanted to. Can anyone please enlighten me of my rather stup!D error.  it does display the window but not exactly 3 seconds. sometimes it jumps to 3.xx to greater than 3 seconds. can somebody enlighten me with this please?

sf::Clock clock;
            sf::Time limit = sf::milliseconds(3000);
            sf:: Time elapsed;

...loop...
elapsed=clock.getElapsedTime();
             while(window5.pollEvent(event))
                {
                    //std::cout<<elapsed.asMilliseconds()<<std::endl;
                    if(elapsed.asMilliseconds()>limit.asMilliseconds())
                            {
                                window5.close();
                            }
                }
window5.display();
...end loop...

4
I've been reading about this for 4 hours both docs and threads here but I was not able to make this work properly . i am posting this as new topic again because the threads i went to i guess are dead. I just simply want to ask max of 8 character input and delete characters when backspace is pressed. somehow i got it working but:

  • it deletes the last character, but it replaces it with the backspace character value " ".
question is: what should i do so that the backspace character value is not inserted on the string?

here is my code:

 if (event.type == sf::Event::TextEntered)
                            {
                                if((event.text.unicode < 128)&& playerInput.getSize()< 8 )
                                    {  playerInput.insert(playerInput.getSize(), event.text.unicode);
                                       playerText.setString(playerInput);
                                    }
                            }
                    if(event.type == sf::Event::KeyPressed)
                                    {
                                        if(event.key.code == sf::Keyboard::BackSpace)
                                            {playerInput.erase(playerInput.getSize()-1,2);
                                            playerText.setString(playerInput);}
                                    }

5
Window / how to create "input fields/ text fields"
« on: March 13, 2016, 08:00:41 am »
Hello everyone, i am an absolute beginner with c++ and sfml, i was tasked to create an Artillery Game, 2 player.
i really need help on how to create a Text field area where a player will enter their name, ive seen tutorials read docs, and forums, but still i am not able to do this. i really need some help.

how should i display the TextEntered on the window?
for example: Player presses 'J', that 'J' is immediately drawn on screen..

any help??if this is even possible??

Pages: [1]
anything