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

Author Topic: Using multiple sprite images for movement  (Read 1361 times)

0 Members and 1 Guest are viewing this topic.

wooshj

  • Newbie
  • *
  • Posts: 4
    • View Profile
Using multiple sprite images for movement
« on: June 22, 2017, 01:21:40 pm »
Using a spritesheet what is the best way to show a character moving? Is loading in each different image the best way to do it? For example if I click the W key it shows the image of character facing up, then if the I press S it clears the screen and draws the sprite of the character facing down. Is this the best way to do it? Reason I ask is because I saw a video of a guy who cropped the image using setTextureRect and just cropping the spriteSheet right in the game.
« Last Edit: June 22, 2017, 01:25:27 pm by wooshj »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Using multiple sprite images for movement
« Reply #1 on: June 22, 2017, 05:25:07 pm »
Use one texture and change the texture rect to get the correct animation frame.

And you need to clear, draw, display every frame. Don't try to just "update" the screen when needed.
« Last Edit: June 22, 2017, 05:28:05 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

wooshj

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Using multiple sprite images for movement
« Reply #2 on: June 22, 2017, 06:39:18 pm »
Alright thanks. For some reason the way i was thinking about it was you would load the spritesheet onto the screen then cut it out and hide that spritesheet lol, now it makes a lot more sense.

 

anything