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

Pages: 1 2 3 [4] 5
46
Window / How do you make the keyboard just click one time? (SFML 2.0)
« on: November 04, 2012, 12:03:43 pm »
Hello  ;D

I have a problem with the keyboard input thing... i just want it to click 1 single time instead of 2 or 3 times when i click a key.

Heres my code... just so you can see what i mean. Also... Does key A count as "left mouse click"?... it looks like it does. (u can copy and paste if you wanna test)

#include <SFML/Graphics.hpp>
#include <sstream>
#include <string>

sf::RenderWindow mywindow(sf::VideoMode(800,600,32),"dsda");
sf::Event ev;

int x = 0;

template <typename T>
std::string toString(T arg)
{
        std::stringstream ss;
        ss << arg;
        return ss.str();
}

int main()
{
        sf::Text mytext;
        mywindow.setVerticalSyncEnabled(true);

        while(mywindow.isOpen())
        {
                mytext.setString(toString(x));
                while(mywindow.pollEvent(ev))
                {
                        if(ev.key.code == sf::Keyboard::A)
                        {
                                x++;
                        }
                }
                mywindow.clear(sf::Color(0,200,0));
                mywindow.draw(mytext);
                mywindow.display();

        }
}
 

47
General / Re: BASIC NEWB QUESTION about preprocessor
« on: October 31, 2012, 01:09:59 am »
argh!! okay  :(

48
General / Question about preprocessor
« on: October 31, 2012, 12:17:48 am »
Hey folks :)
i just want to show a small example about scope when dealing with preprocessor and functions that i have a little problem with

So.... i have the main functions and another function in a header... heres my code.

//MAIN.CPP

#include <SFML\Graphics.hpp>
#include "world1.h"

sf::RenderWindow mywindow(sf::VideoMode(800,600,32),"dsadsa");
sf::Event ev;

int main()
{
        while(mywindow.isOpen())
        {
                while(mywindow.pollEvent(ev))
                {
                        if(ev.type == sf::Event::Closed)
                                mywindow.close();
                }
                world1();
               
        }
}
 

//WORLD1.H

#include <SFML\Graphics.hpp>

void world1()
{
        mywindow.clear(sf::Color(0,200,0));
        mywindow.display();
}
 

So basically, the problem is that an error aqquires and says that mywindow is unidentified.

I actually tried to define my RenderWindow variable "before" i #included the world1.h.
And that worked.... but is that really how you should do it to make my renderwindow variable be accessed in all function in other headers?

49
General / Re: How do i write variables contents in text?
« on: October 27, 2012, 01:19:21 am »
i got it to work :D

#include <SFML\Graphics.hpp>
#include <sstream>
#include <string>

sf::RenderWindow mywindow(sf::VideoMode(800,600,32),"terdas");

template <typename T>
std::string toString(T arg)
{
        std::stringstream ss;
        ss << arg;
        return ss.str();
}

int main()
{
        mywindow.setVerticalSyncEnabled(true); // 60 fps
        int score = 200;
        std::string scoretext = "Score= ";

        sf::Text mytext;
       

        while(mywindow.isOpen())
        {
                mytext.setString(toString(scoretext) + toString(score));

                mywindow.clear(sf::Color(0,200,0));
                score++;
                mywindow.draw(mytext);
                mywindow.display();
        }
}
 

So is this how you make a score update properly?
I just want to make sure its not heavy for the computer  :D

50
General / Re: How do i write variables contents in text?
« on: October 25, 2012, 10:48:13 pm »
Woaw thanks alot!!!!
this community is so helpful and AWESOME  ;D ;D ;D

51
General / Re: How do i write variables contents in text?
« on: October 25, 2012, 01:31:31 am »
Erm.. This is not a SFML question?
Use stringstream(c++ approach) or sprintf(C approach) to convert and then use that as your text.
Also you don't set string to fonts. :)
You can easily write template function that takes any variable and returns it as string using stringstream.
template <typename T> std::string  EEVarToStr(T targ)
{
        std::stringstream ss;
        ss<<targ;
        return ss.str();
}

Im not really that advaned yet to use templates.
But yes... it is a sfml question.

Is there a more easy way to do this?
I just made an example to show what i wanted to make.
Siimply, just write my int variable on my screen to show fx the score

52
Ahh ok, ty :-)

But im not sure if im gonna buy the full version just yet though  ;D

53
General / How do i write variables contents in text?
« on: October 25, 2012, 01:22:05 am »
For example

int x = 10;

sf::text mytext;
mytext.setfont(myfont);
myfont.setstring("bla bla bla (x)") // i want to write "bla bla bla 10"

mywindow.draw(mytext);

So how do i write my variable x's contents if i had to track my score?

54
General discussions / When is SFML 2.0 gonna be compatible with VC 2012?
« on: October 25, 2012, 12:29:45 am »
Hey, sorry if its already been posted, but i couldn't seem to find it.

But when is SFML 2.0 gonna be compatible with VC 2012?

55
General / Re: How does the timers/clocks work?
« on: October 24, 2012, 01:57:43 am »
Thanks for help!!! that was easy  ;D

56
General / How does the timers/clocks work?
« on: October 24, 2012, 01:03:26 am »
Hi everybody :)

I dont really understand the timers/clocks. I just want my game to be on 60 fps on any computer.
In Allegro, it was very very easy.... just make a variable, start it and wupti... its 60 fps.

But in SFML it seems a little more confusing to me.

i looked at the tutorial here:
http://www.sfml-dev.org/tutorials/2.0/system-time.php

But i didn't really understand it :(

Hope someone helps
thanks!!!!  ;D

57
General / Re: How do i make my bitmap transparent? sfml2.0
« on: October 22, 2012, 12:06:38 am »
It still exists, see here. ;)

The thing is that texture.loadFromFile() actually is simply a shorthand for loading it into an image and then copying it to a texture.

So what you have to do is load it into a sf::Image set the wanted transparent color and retrieve the texture.

Another option would be to mask the background color in a image editor and set it to transparent. ;)


Ahh ok ty :)

58
General / How do i make my bitmap transparent? sfml2.0
« on: October 21, 2012, 02:18:21 pm »
In 2.0 theres no "CreateMaskFromColor" from my textures.
So how do i make my background transparent if my images aint png files?

59
General / Re: help!! Loading bitmap error in sfml 2.0 :(
« on: October 21, 2012, 01:08:53 am »
Ok... i figured out it was my linker-input i made wrong

60
General / help!! Loading bitmap error in sfml 2.0 :(
« on: October 21, 2012, 12:58:09 am »
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
        sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "Title");

        sf::Texture mytexture;
        sf::Sprite mysprite;

        mytexture.loadFromFile("theimage.bmp");

        mysprite.setTexture(mytexture, 0);

        while (Window.isOpen())
        {
                sf::Event Event;
                while(Window.pollEvent(Event))
                {
                        if(Event.type == sf::Event::Closed || Event.key.code == sf::Keyboard::Escape)
                                Window.close();
                }

                Window.clear();
                Window.draw(mysprite);
                Window.display();
                sf::sleep(sf::milliseconds(60));

        }

        return 0;
}

I cant really seem to figure it out when i look in the documentation  :(
When i run it, it gives me those "dot" sounds every 0.4 sec, and then there come a box where there stand i can break, continue or ignore.
In the console window there stand "failed to load image".

I have put the image in the folder where my .cpp is.

Pages: 1 2 3 [4] 5
anything