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

Pages: [1] 2
1
General / Re: Sprites inside a Class
« on: April 11, 2016, 05:35:29 pm »
lets cut the discussion short.

when you say "You need to keep track of your texture untill the destruction (or the use) of your sprite."

how should i implement that in my code??????

2
General / Re: Sprites inside a Class
« on: April 11, 2016, 05:32:14 pm »
yeah my mistake on the term..i admit. but if you say that this is a syntactic error, then my program shouldnt have  executed.. the window i created should not have displayed..

nicox11. you are not really providing answers. what you are pointing here is if i have enough skills on c++ and sfml, well i admit i dont, THAT IS WHY I ASK QUESTIONS..

3
General / Re: Sprites inside a Class
« on: April 11, 2016, 04:39:03 pm »
Quote
you should maybe go back to the basics.

what i was asking is how to make the sprite() function work properly. i am sorry if i lack basic coding competencies like you said, but you see i am a newb. i only use what i see on tutorials and those that i tried and worked as long as it worked.

4
General / Re: Sprites inside a Class
« on: April 11, 2016, 04:35:51 pm »
i saw the link that you said. but i do not really know how to keep the texture "alive".

im sorry im still a beginner that is why.

5
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

6
General / Re: How to make a bullet curve
« on: April 05, 2016, 01:03:42 pm »
yes that is what i exactly mean..shadowmouse, i am really new to this, can you help me out to do this especially the coding? on what should be the attributes of the objects like for example the bullets and tanks. :),..

thank you for the valuable tip..

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

8
General / Re: sf::Time and sf::Clock
« on: March 28, 2016, 05:29:35 pm »
oww. there. got it. thanks both.

9
General / Re: sf::Time and sf::Clock
« on: March 28, 2016, 03:25:54 pm »
hi exploiter, i get a little bit confused when you say:

"you get the elapsed time once","all you do is compare two fixed values" and " you call getElapsedTime before the loop"

are you telling me what i should do, or what my mistake are??

10
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...

11
Graphics / Re: Text Input - Handling press of backspace.
« on: March 24, 2016, 07:07:31 pm »
Posting code already posted = helpful
Trying to explain = useless
You see i'm really new to programming, sorry that i forgot to thank you, you explained it well but i didnt know how to implement it...now im getting it.  ;D ;D ;D


12
Graphics / Re: Text Input - Handling press of backspace.
« on: March 24, 2016, 08:31:00 am »
Thank you bitano.. got it working.. Thank you for helping beginners like me, i really learn very slow. Thank you for your help.

if (event.text.unicode == '\b') // handle backspace explicitly
                                {
                                    playerInput.erase(playerInput.getSize()- 1, 1);
                                    playerText.setString(playerInput);
                                }
                            else // all other keypresses
                                {
                                    playerInput += static_cast<char>(event.text.unicode);
                                    if((event.text.unicode < 128)&& (playerInput.getSize()< 8 ) )
                                            playerText.setString(playerInput);
                                }

13
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);}
                                    }

14
Graphics / Re: Text Input - Handling press of backspace.
« on: March 24, 2016, 03:23:42 am »
i dont really get what "handle explicitly", how do i do it? im just knew in SFML, thats why, i read the documentation on .erase(position, count o char to erase), could you please give me a clearer hint that i could understand.
:)

 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,1);
                            }

this one works it does delete the last character but the backspace value remains.

if "HELLU" -press backspace "HELL" -press O "HELL 0".

deletes only once.

15
Graphics / Re: Text Input - Handling press of backspace.
« on: March 24, 2016, 02:48:07 am »
Hi, everyone i hope this thread is not dead yet, i just want to ask why is my code(below) only delete the last character when it reaches the total size of character input.

if (event.type == sf::Event::TextEntered)
                            {   //handle user input     !!works properly
                                if((event.text.unicode < 128)&& playerInput.getSize()< 8 )
                                    {   
                                       playerInput.insert(playerInput.getSize(), event.text.unicode);
                                       playerText.setString(playerInput);
                                    }
                                //erase on backspace press     !!does not work properly?what is wrong with it??
                                if(event.text.unicode == '\b')
                                    {
                                        playerInput.erase(playerInput.getSize() -1,1);
                                    }
                            }
what i want to do is ask for input(max of 8 characters), and delete when backspace is entered.

Pages: [1] 2