SFML community forums
Help => Graphics => Topic started by: David on April 27, 2011, 03:48:43 pm
-
I just started SFML a few days ago, and I need an explaination on the sprites tutorial :?
Is it saying that you take small sections of a sprite sheet and displaying them accordingly or is it saying that you have to upload all of the images and then displaying them :?:
Can someone also help explain the Event function? I'm kinda confused
I'm using Code::Blocks if that helps, which I doubt :wink:
-
sf::Sprite is just a class that references a sf::Image (or parts of it). So the real image data, i.e. the pixels, are stored inside sf::Image. You normally initialize images once, afterwards you work with sprites. Sprites can be colorized, moved, rotated, scaled, flipped and drawn on the screen.
I don't know whether this answers your question, but your formulation is really unprecise and hard to understand. Same with events, please tell us in a concrete way what you don't understand. By the way, there is nowhere a "Event" function.
-
Your explaination helped
And for the Events part, I just want to know how can you program a key listener so the user can press the SHIFT key and make it do something
-
Have a look at this: http://www.sfml-dev.org/tutorials/1.6/window-events.php
There is everything explained what you want to know.
-
Your explaination helped
And for the Events part, I just want to know how can you program a key listener so the user can press the SHIFT key and make it do something
There is no need for a key listener (Java programmer?). If you want something to happen when the user presses shift, you can do this (inside the event-loop):
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::LShift)) {
// Do here what you want to happen when the user presses shift
}
-
There is no need for a key listener
Sometimes there is, for example when you want to add/remove functions associated with events at runtime. That's also why I have implemented event listeners in my library ;)
-
You are right, I never thought about that. I assumed that he just wanted to execute some code when shift-key is pressed, not to do anything as fancy as that. :D
-
Your explaination helped
And for the Events part, I just want to know how can you program a key listener so the user can press the SHIFT key and make it do something
There is no need for a key listener (Java programmer?). If you want something to happen when the user presses shift, you can do this (inside the event-loop):
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::LShift)) {
// Do here what you want to happen when the user presses shift
}
Can you only do it on one of the shift keys? :?:
Can you do this? :?
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Shift)) {
// Do here what you want to happen when the user presses shift
}
Or this?
:idea:
if ((Event.Type == sf::Event::KeyPressed) && ((Event.Key.Code == sf::Key::LShift) || (Event.Key.Code == sf::Key::RShift)) {
// Do here what you want to happen when the user presses shift
}
-
The second code works, the first doesn't. You could also find this out on your own.
And lookup the documentation, there you see which identifiers are valid keys. "Shift" is none of them.
-
Can you do this? :?
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Shift)) {
// Do here what you want to happen when the user presses shift
}
You can do it in a very similar way. Key Event (http://www.sfml-dev.org/documentation/2.0/structsf_1_1Event_1_1KeyEvent.htm#a024b19f70f7a0c04f358b6fb5b818984) has special variables to check, wether shift, control or alt was pressed or not.
if ((Event.Type == sf::Event::KeyPressed) && Event.Key.Shift )
{
// Do here what you want to happen when the user presses shift
}
So this should work.
-
Can you do this? :?
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Shift)) {
// Do here what you want to happen when the user presses shift
}
You can do it in a very similar way. Key Event (http://www.sfml-dev.org/documentation/2.0/structsf_1_1Event_1_1KeyEvent.htm#a024b19f70f7a0c04f358b6fb5b818984) has special variables to check, wether shift, control or alt was pressed or not.
if ((Event.Type == sf::Event::KeyPressed) && Event.Key.Shift )
{
// Do here what you want to happen when the user presses shift
}
So this should work.
That fills the missing gaps. Thanks for everyone's contribution to this :D
-
if ((Event.Type == sf::Event::KeyPressed) && Event.Key.Shift )
{
// Do here what you want to happen when the user presses shift
}
This code is not equivalent. It's not triggered when shift is pressed, but when any key is pressed while holding shift.
-
That was my fault. I am sorry. I just saw this code and thought it would be possible to use it in this way. But actually it is logical, because KeyEvent::Shift is not a key code. At least I now know, what it is good for ;).