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

Pages: [1] 2 3
1
Graphics / Insert images after App.Display();
« on: January 02, 2012, 01:09:56 pm »
Code: [Select]

bool show;

App.Clear();

if(sf::Keyboard::IsKeyPressed(sf::Keyboard::A))
{
    show = true;
}

if(show)
{
    App.Draw(sprite);
}

App.Display();



EDIT: If you want the object only to show up while the key is still down, get rid of the boolean and the second if statement then put "App.Draw(sprite);" in the first if statement.

2
General / SFML Window not showing!!!
« on: December 29, 2011, 09:37:37 pm »
For a walking animation, this is helpful: http://www.manningkrull.com/pixel_art/tutorials/walking.asp. Don't copy it exactly, though, make your own character and follow the general idea. If you copy the legs pixel for pixel with different colors, you won't learn much.

3
General / SFML Window not showing!!!
« on: December 29, 2011, 02:33:11 pm »
Good job; that's what I was trying to tell you :).

4
General / SFML Window not showing!!!
« on: December 28, 2011, 12:00:10 am »
"frame2 %= 5" should set frame2 to 0 when it reaches 5. I said to use '==' because it's more readable, not because it should fix anything. Make sure the image width and height are both 640 pixels.

5
General / SFML Window not showing!!!
« on: December 27, 2011, 10:52:43 pm »
No, keep the "* 68", unless you changed the image size? Anyways, change "if(frame2 > 4){ frame2 = 0; }" to "frame2 %= 5;". You can check if frame is equal to 5 instead of if it's greater than 4; it's more readable.

6
General / SFML Window not showing!!!
« on: December 27, 2011, 09:30:49 pm »
Quote
And yes, the problem is with the parameters to SetSubRect(). You're checking if "frame" is greater than 5, which is true when it's 6 or higher. This means you're setting the top left corner to 408, 408.


Did you fix this?

7
General / SFML Window not showing!!!
« on: December 27, 2011, 09:17:09 pm »
You're moving the subrect down one pixel when frame is greater than 5; you need to move it down 68 pixels. In place of "frame2" if you write "frame2 * 68" it should be fine. Instead of the following:

Code: [Select]

if(frame2 > 5)
{
    frame2 = 0;
}



You can write "frame2 %= 5;". And yes, the problem is with the parameters to SetSubRect(). You're checking if "frame" is greater than 5, which is true when it's 6 or higher. This means you're setting the top left corner to 408, 408.

8
General / SFML Window not showing!!!
« on: December 27, 2011, 08:52:39 pm »
Try drawing the image without SetSubRect(). If it's okay, the problem is probably with the parameters of SetSubRect(), and if you can't find the problem, show me the code and I'll try to find it.

9
General / SFML Window not showing!!!
« on: December 27, 2011, 01:04:06 pm »
Huh, I thought I saw sf::Sprite::SetImage() somewhere.... Maybe you've got the parameters of SetSubRect() wrong somehow and you're setting a subrect which doesn't exist completely in the image you loaded? When I do that I get a sort of cyan color, but it might be different from machine to machine. Also, in SFML 2.0, you use sf::Texture and sf::Sprite::SetTexture().

10
General / SFML Window not showing!!!
« on: December 26, 2011, 12:31:43 am »
You're using SFML 1.6.

11
General / SFML Window not showing!!!
« on: December 25, 2011, 09:13:02 pm »
Code: [Select]

sf::Sprite::SetSmooth(false);



You could have checked the documentation to see what Anata meant, or searched the forums (at the top of the page under "SFML forums"). It should take less time to do that than wait for an answer. By the way, in SFML 2.0 smooth is false by default.

12
General / SFML Window not showing!!!
« on: December 25, 2011, 11:04:41 am »
You just wrote "frame2", so the animation will move down one pixel when you increment it. Also, it might be easier to write "frame %= totalFrames" and have each animation in the image take up just one row.

Use this to help you get started: http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition.aspx. Don't just copy and paste, though; I'd recommend making a different game and once the tutorials get more specific to the game he's creating, continue on your own.

13
General / SFML Window not showing!!!
« on: December 24, 2011, 11:11:56 pm »
Code: [Select]

if(clock.GetElapsedTime() >= 1)
{
    sprite.SetSubRect(sf::Intrect(frame * width, animation * height, width, height));
    ++frame;

    clock.Reset();
}



This would change the frame every second, but try to problem solve on your own sometimes; it's very important in programming. "animation" is for if you have multiple animations in one spritesheet. The first frame would be 0 and the first animation would also be 0.

14
General / SFML Window not showing!!!
« on: December 24, 2011, 09:35:43 pm »
Well, first, you don't time the frames. A frame is one run through the game loop. sf::Clock::GetElaspsedTime() gets the time between when you last reset (or created) the clock and when you call the function. GetElapsedTime() in SFML 1.6 is seconds (float), but in SFML 2.0 it's in milliseconds (UINT32).

EDIT: I mixed up SFML 1.6 and SFML 2.0; changed it.

15
General / SFML Window not showing!!!
« on: December 24, 2011, 09:14:49 pm »
Oops, I forgot about sf::IntRect. Anyways, say you have a 100x100 square. You want to crop the image to a 10x10 sprite in the middle. You would do this:

Code: [Select]

sf::Image image;

if(!image.LoadFromFile("100x100.png")
{
    return 0;
}

sf::Sprite sprite(image);
sprite.SetSubRect(sf::IntRect(45, 45, 10, 10));



The sprite is a rectangle with a height and width of 10, and whose leftmost pixel is at column 45 of the image from the left and whose topmost pixel is at row 45 of the image from the top.

Pages: [1] 2 3