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

Pages: 1 [2] 3
16
Graphics / Re: A better scrolling background technique
« on: August 06, 2013, 02:39:18 am »
I didn't post it here, it got moved here, but I see your point.

17
Graphics / A better scrolling background technique
« on: August 05, 2013, 08:49:31 pm »
Today I was playing around with a background I wanted to scroll, and was using the old 2 sf::Sprite technique, but I personally found that distasteful and got to thinking: sf::Texture has setRepeated, and sf::Sprite has setTextureRect, could I use these to my advantage?

And absolutely yes, what I got was a scrolling background with one sf::Sprite which gives me absolute control, I can move it, i can scale it, i can rotate it, i can do anything i want with it. without having to use any external variables either.

The code itself is really simple:
First here is the image


And here is the code
int main()
{
    sf::RenderWindow app(sf::VideoMode(640, 480), "Platform Physics");

    // x = wind, y = gravity
    sf::Vector2f gravity(0.f, .5f);

    sf::RectangleShape playerShape;


    playerShape.setSize(sf::Vector2f(16, 64));
    playerShape.setPosition(32, 0);
    playerShape.setFillColor(sf::Color(140, 36, 58));
   
    sf::RectangleShape floor;
    floor.setPosition(0, 324);
    floor.setSize(sf::Vector2f(640, 16));
 
   sf::Vector2f velocity;

    sf::Time jumpTime;
    sf::Time jumpMaxTime = sf::seconds(0.1f);
    sf::Clock clock;
    sf::Time lastTime;

    sf::Texture texture;
    sf::Sprite background;
    if (texture.loadFromFile("brinstar_bg1.png"))
    {
        texture.setRepeated(true);
        background.setTexture(texture);
    }

    const float MAX_VELOCITY = .2f;

    while(app.isOpen())
    {
        sf::Time currentTime = clock.restart();
        lastTime = currentTime;

        sf::Event event;
        while(app.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                app.close();
        }


        velocity.y += gravity.y*lastTime.asSeconds();

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
            // Immediate stop
            if (velocity.x > 0)
                velocity.x = 0;
            velocity.x -= .2f*lastTime.asSeconds();
        }
        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        {
            // Immediate stop
            if (velocity.x < 0)
                velocity.x = 0;
            velocity.x += .2f*lastTime.asSeconds();
        }
        else
            velocity.x *= .75f;

        if (velocity.x < -MAX_VELOCITY)
            velocity.x = -MAX_VELOCITY;
        else if (velocity.x > MAX_VELOCITY)
            velocity.x = MAX_VELOCITY;
        if (velocity.y < -MAX_VELOCITY)
            velocity.y = -MAX_VELOCITY;
        else if (velocity.y > MAX_VELOCITY)
            velocity.y = MAX_VELOCITY;


        playerShape.move(velocity);

        if (playerShape.getPosition().x < 0)
            playerShape.setPosition(0, playerShape.getPosition().y);
        if (playerShape.getPosition().x + playerShape.getSize().x > app.getSize().x)
            playerShape.setPosition(app.getSize().x - playerShape.getSize().x, playerShape.getPosition().y);

        background.setOrigin(background.getLocalBounds().width/2, background.getLocalBounds().height/2);
        background.setPosition(background.getLocalBounds().width/2,  background.getLocalBounds().height/2);
        background.setTextureRect(sf::IntRect(-((playerShape.getPosition().x*.125f)), -(playerShape.getPosition().y*.25f), 640, 256));
       
        // Test rotation;
        background.rotate(16.f*lastTime.asSeconds());

        app.clear(sf::Color::Magenta);
        app.draw(background);
        app.draw(floor);
        app.draw(playerShape);
        app.display();
    }

    return 0;
}
 

18
Graphics / SFML 2.0: RenderWindow::GetFrameTime() missing?
« on: February 07, 2012, 09:22:54 pm »
Thanks, I don't know why I didn't use the search function xD sorry about that

This topic can be locked/deleted then

19
Graphics / SFML 2.0: RenderWindow::GetFrameTime() missing?
« on: February 07, 2012, 09:01:41 pm »
When attempting to get the frame time I discovered that the function is entirely missing. Is this intentional?, if so why?

20
Graphics / Maximum size of sf::Image and sf::Sprite
« on: July 25, 2010, 12:55:47 am »
Isn't there a way to query the drivers and get the max texture size that way?

21
Graphics / sf::RenderWindow vs sfml/qt
« on: July 25, 2010, 12:48:06 am »
It could be the OGL backend for SFML or your drivers ;P

22
Graphics / Image bpp
« on: May 24, 2010, 03:32:27 am »
Then that should be pretty easy considering the data is stored 32x32 by default, and read as an 8x8 tile (contradictory I know)

And the de/compression is already taken care of.

23
Graphics / Loading PNG?
« on: May 24, 2010, 03:24:36 am »
Actually the error message is kinda cryptic if you look at it.

Does it mean that only 8-bit png files are supported? Or is the image 8-bit only?

See what I'm getting at?

24
Graphics / Huge problem with SFML
« on: May 24, 2010, 03:18:47 am »
Check the task manager and see what the memory usage is when this happens. It may be a memory leak if so some debugging is in order.

Laurent, maybe you should check the Mouse event functions in the SDK and make sure you have no stray loops.

25
DotNet / Image.Copy copying nothing
« on: May 24, 2010, 02:42:33 am »
An unrelated note, but unless you plan to have a variable change it's type using var will only lead to unneeded overhead due to the way m$ wrote it.

Don't get me wrong, var is great when using LINQ but in a game it's not necessary.

26
Graphics / Image bpp
« on: May 09, 2010, 07:12:09 pm »
Actually i know for a fact that Zelda in particular uses 4bpp ;D the bit planes are 4bpp.

27
Graphics / Image bpp
« on: May 09, 2010, 05:42:36 am »
I am working on an editor for an snes game I'm sure you are all familiar with: Zelda A Link To The Past, and it uses 4bpp graphics.

Now is it possible to use this mode? Or does it have to converted to 24bpp?

If it can that removes that headache if not, well myself and my programming partner can make do.

28
General discussions / [Windows-x64] Building SFML?
« on: March 21, 2010, 05:05:20 am »
From what I've seen of the source, some of the libraries included aren't thread safe, that would make getting an x64 bit version compiling difficult though it is possible.

29
Graphics / GDI primitives vs SFML primitives
« on: March 08, 2010, 03:10:40 am »
Friendly, in this case, is a relative term and should not be used. Sure GDI/GDI+ is "friendly" however the performance hit is rather "unfriendly" not to mention the lack of real support on Vista/7, GDI is dying, let it die in peace.

EDIT:
Forgot to mention "Lock-In".

GDI, while supported fairly well by Wine, is designed for and around windows, therefore limiting your target audience.

30
Feature requests / Add support for custom refresh rates
« on: November 18, 2009, 05:40:12 pm »
Three tips: Be open, Be skeptical, Wiki isn't the holy grail of knowledge


EDIT:
I also apologize for my attitude, I was just having a bad day and i have no real excuse. dunce, you are correct in your above post, and despite English not being your native language, you are concise and understandable good job. I also got one of my facts incorrect, Refresh rate is how many times per second the guns fire Across the screen, in an Up, Down Left Right fashion.

Pages: 1 [2] 3
anything