Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Sprite Help  (Read 3279 times)

0 Members and 1 Guest are viewing this topic.

David

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Sprite Help
« 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:

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6276
  • Thor Developer
    • View Profile
    • Bromeon
Sprite Help
« Reply #1 on: April 27, 2011, 03:55:34 pm »
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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

David

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Events
« Reply #2 on: April 27, 2011, 04:33:54 pm »
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

Fred_FS

  • Newbie
  • *
  • Posts: 48
    • View Profile
Sprite Help
« Reply #3 on: April 27, 2011, 05:26:36 pm »
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.

Dimple

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Events
« Reply #4 on: April 27, 2011, 05:38:45 pm »
Quote from: "David"
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):
Code: [Select]

if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::LShift)) {
    // Do here what you want to happen when the user presses shift
}

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6276
  • Thor Developer
    • View Profile
    • Bromeon
Re: Events
« Reply #5 on: April 27, 2011, 06:08:34 pm »
Quote from: "Dimple"
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 ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Dimple

  • Newbie
  • *
  • Posts: 30
    • View Profile
Sprite Help
« Reply #6 on: April 27, 2011, 06:35:32 pm »
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

David

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Events
« Reply #7 on: April 27, 2011, 07:05:04 pm »
Quote from: "Dimple"
Quote from: "David"
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):
Code: [Select]

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? :?

Code: [Select]

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:
Code: [Select]

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
}

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6276
  • Thor Developer
    • View Profile
    • Bromeon
Sprite Help
« Reply #8 on: April 27, 2011, 07:09:50 pm »
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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Fred_FS

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: Events
« Reply #9 on: April 27, 2011, 11:37:05 pm »
Quote from: "David"

Can you do this? :?
Code: [Select]

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 has special variables to check, wether shift, control or alt was pressed or not.

Code: [Select]

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.

David

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Events
« Reply #10 on: April 27, 2011, 11:50:44 pm »
Quote from: "Fred_FS"
Quote from: "David"

Can you do this? :?
Code: [Select]

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 has special variables to check, wether shift, control or alt was pressed or not.

Code: [Select]

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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sprite Help
« Reply #11 on: April 28, 2011, 07:48:01 am »
Code: [Select]
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.
Laurent Gomila - SFML developer

Fred_FS

  • Newbie
  • *
  • Posts: 48
    • View Profile
Sprite Help
« Reply #12 on: April 28, 2011, 11:31:16 am »
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 ;).