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

Pages: [1] 2
1
Graphics / Question about sprite moving
« on: August 10, 2013, 10:27:07 am »
I can keep the sprite on the screen, but my problem is when it reaches the end of screen, it cant go back left, And if I continue pressing key it lefts the screen.
Quote
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow Window(sf::VideoMode(320,320),"");
    sf::Texture tex;
    tex.loadFromFile("bullet.png");
    sf::Sprite sprite(tex);
    float movespeed = 0.1f;
    float velocityX = 0;
    while(Window.isOpen())
    {
        Window.clear();
        Window.draw(sprite);
        Window.display();
        sf::Event Event;
        while(Window.pollEvent(Event))
        {
            switch(Event.type)
            {
            case sf::Event::Closed:
                Window.close();
            }
        }
        if(sprite.getPosition().x + 9 > 320 || sprite.getPosition().x < 0)
            velocityX = 0;
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        {
            velocityX = movespeed;
            sprite.move(velocityX,0);
        }
        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
            velocityX = -movespeed;
            sprite.move(velocityX,0);
        }
    }
}

2
C / Question about Codeblocks and sfml 2.0
« on: March 22, 2013, 06:21:34 am »
Why codeblocks intellisense cant the variables ive made?

3
Graphics / Re: Question about bouncing
« on: December 06, 2012, 04:58:46 pm »
Yes thats what I want but what will I use to make ballx negate when it reaches the end of X of screen?

Im trying this code but its wrong..
Quote
#include <SFML/Graphics.hpp>

int main()
{
    int screen_w = 640;
    int screen_h = 480;
    sf::RenderWindow window(sf::VideoMode(screen_w,screen_h), "SAMPLE");
    sf::Image image;
    image.loadFromFile("ball.png");
    image.createMaskFromColor(sf::Color(255,0,255));
    sf::Texture texture;
    texture.loadFromImage(image);
    sf::Sprite sprite(texture);
    float ballx = 0.1;
    float bally = 0.0;
    while(window.isOpen())
    {
        sprite.move(ballx,bally);
        window.clear();
        window.draw(sprite);
        window.display();

        sf::Event event;
        while(window.pollEvent(event))
        {
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
            window.close();
        }
        if(sprite.getPosition().x <= screen_w-20)
        ballx = -0.1;
    }
}

4
Graphics / Question about bouncing
« on: December 06, 2012, 04:35:56 pm »
How can I make the ball bounce back if it reaches the end of the screen?

#include <SFML/Graphics.hpp>
int main()
{
    int screen_w = 640;
    int screen_h = 480;
    sf::RenderWindow window(sf::VideoMode(screen_w,screen_h), "SAMPLE");
    sf::Image image;
    image.loadFromFile("ball.png");
    image.createMaskFromColor(sf::Color(255,0,255));
    sf::Texture texture;
    texture.loadFromImage(image);
    sf::Sprite sprite(texture);
    float ballx = 0.1;
    float bally = 0.0;
    while(window.isOpen())
    {
        sprite.move(ballx,bally);
        window.clear();
        window.draw(sprite);
        window.display();
               
        sf::Event event;
        while(window.pollEvent(event))
        {
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
            window.close();
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
            {
            ballx = -0.1;
            bally = 0.0;
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
            {
            ballx = 0.1;
            bally = 0.0;
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
            {
            bally = 0.1;
            ballx = 0.0;
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
            {
            bally = -0.1;
            ballx = 0.0;
            }

        }    
    }
}
 

5
Graphics / Help in moving sprite
« on: November 28, 2012, 06:35:32 am »
How can I make a simple sprite move on the screen like a ball?

6
Graphics / Re: how to draw like this?
« on: November 20, 2012, 04:13:34 am »
thankyou so much for your replies..
Im just trying to translate the code in game programming all in one book by james harbour and I've got trouble in here.. maybe I will just skip this step..

7
Graphics / how to draw like this?
« on: November 19, 2012, 07:38:48 pm »
How can I draw like the picture?
#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>
#include <ctime>

static inline std::string int2Str(int x);

int main()
{

    int x,y;
    int red,green,blue;
    std::srand(time(NULL));
    int SCREEN_W = 640;
    int SCREEN_H = 480;
    std::string width = int2Str(SCREEN_W);
    std::string height = int2Str(SCREEN_H);
    std::string printonscr = "Pixels Program - " + width + " x " + height + " - " + "Press ESC to Quit";
    sf::RenderWindow window(sf::VideoMode(SCREEN_W,SCREEN_H), "Test");


    sf::Font font;
    if(!font.loadFromFile("arial.ttf"))
        return EXIT_FAILURE;

    sf::Text text(printonscr, font, 15);
    text.setStyle(sf::Text::Bold);
    while(window.isOpen())
    {
    x = 10 + rand() % (SCREEN_W);
    y = 10 + rand() % (SCREEN_H);
    red =  rand() % 255;
    blue = rand() % 255;
    green = rand() % 255;
    sf::Image dot;
    dot.create(10,10,sf::Color(red,blue,green));
    sf::Texture texture;
    texture.loadFromImage(dot);
    sf::Texture background;
    sf::Sprite sprite(texture);
    sprite.setPosition(x,y);

        sf::Event event;
        while(window.pollEvent(event))
        {

            if(event.type == sf::Event::Closed)
            window.close();
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
            window.close();

        }
        window.clear(sf::Color::Black);
        window.draw(sprite);
        window.draw(text);
        window.display();
    }
    return EXIT_SUCCESS;
}
static inline std::string int2Str(int x)
        {
                std::stringstream type;
                type << x;
                return type.str();
        }
 

[attachment deleted by admin]

8
Graphics / Re: Help in sf::text
« on: November 19, 2012, 12:02:54 pm »
Thank you so much, I didnt know that I have to link sfml-system because sf::Text is part of sfml graphics module.

9
Graphics / Re: Help in sf::text
« on: November 19, 2012, 11:48:02 am »
Im using code::blocks 10.05 with minggw
and sfml 2.0



[attachment deleted by admin]

10
Graphics / Help in sf::text
« on: November 19, 2012, 09:00:24 am »
This is my code and I got the error
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(640,480), "Test");
    sf::Font font;
    if(!font.loadFromFile("arial.ttf"))
        return EXIT_FAILURE;

    sf::Text text;
    text.setString("Hello");
    text.setFont(font);
    text.setCharacterSize(30);
    text.setStyle(sf::Text::Bold);
    text.setColor(sf::Color::Red);

    while(window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
            window.close();
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
            window.close();
        }
        window.clear(sf::Color::Black);
        window.draw(text);
        window.display();
    }

}
 

Quote
obj\Debug\Main.o||In function `main':|
C:\Documents and Settings\TAE\My Documents\SFML\SAMPLE\Main.cpp|11|undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'|
||=== Build finished: 1 errors, 0 warnings ===|

11
Graphics / sf::clear doesnt fill my window
« on: November 08, 2012, 06:38:13 am »
Im using palit videocard, sf::clear doesnt seem to work.. what will i have to do..

12
Graphics / Help in Animation.
« on: December 13, 2011, 08:45:18 am »
Thank you very much!
It solves my problem!
More power to SFML!

I think your Blog teaches many things about game programming
Ill visit it if I had much time!

13
Graphics / Help in Animation.
« on: December 13, 2011, 04:21:11 am »
I got a problem when I try to press the keyboard key A.
My animation stops when I hold down the Keyboard key A.

Code: [Select]
#include "SFML/Graphics.hpp"
#include "SFML/System.hpp"
#include "AniSprite.h"

int main()
{
    sf::RenderWindow App(sf::VideoMode(640, 420,32), "Test");

sf::Image Image;

if (!Image.LoadFromFile("untitled1.bmp"))
return 1;
Image.CreateMaskFromColor(sf::Color::Black);

sf::Texture Texture;
Texture.LoadFromImage(Image);

AniSprite Sprite(Texture,93,96);
Sprite.SetLoopSpeed(0.007); //60 fps




while(App.IsOpened())
{
    sf::Event Event;

    while (App.PollEvent(Event))
    {
        if (Event.Type == sf::Event::Closed)
                App.Close();
        if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::A))
                Sprite.Play();
        else if ((Event.Type == sf::Event::KeyReleased) && (Event.Key.Code == sf::Keyboard::A))
                Sprite.Stop();

    }

    App.Clear();
    Sprite.Update();
    App.Draw(Sprite);
    App.Display();
}
}

14
Graphics / AniSprite Error
« on: December 11, 2011, 04:46:08 pm »
Thankyou for your reply sir, It somehow push me to analyze the code.
And I made it work..
Im sorry because Im new to SFML and libraries. I Studied C++ 2weeks ago
so im new to the environment..
By the way..Again Thankyou!

15
Graphics / AniSprite Error
« on: December 11, 2011, 02:03:58 pm »
Yeah I know sir, Thats why im asking if this is fully implemented in sfml 2.
Because I know that sf::Image will pass to sf::Texture first before passing to sf::Sprite..

Pages: [1] 2
anything