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

Author Topic: Moving vertex arrays?  (Read 2333 times)

0 Members and 1 Guest are viewing this topic.

new_to_sfml

  • Newbie
  • *
  • Posts: 3
    • View Profile
Moving vertex arrays?
« on: April 07, 2021, 08:49:13 pm »
Hi, I'm new to SFML and to object oriented C++ and I want to make a Tetris clone. I'm using vertex array to represent tetrominos. Is it the best way to do it?
If it is, then is there a convenient way to move them on the screen?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Moving vertex arrays?
« Reply #1 on: April 07, 2021, 10:46:31 pm »
If you're just starting out, you're probably better off using sprites instead. That way you don't have to figure out the proper math to transform everything, but you get nice functions.

Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

new_to_sfml

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Moving vertex arrays?
« Reply #2 on: April 09, 2021, 11:04:44 am »
So a tetromino would be a sprite containing 4 square shapes? But how to arrange them so that they form a correct tetromino?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Moving vertex arrays?
« Reply #3 on: April 09, 2021, 11:17:31 am »
If you just want the shape without texturing, then you could also use rectangle shapes.
You could for example draw four squares next to each other for a straight tetromino etc.

If you search the project section for Tetris, you should find quite a few examples, often with code, that might help you understand, how one could go about writing such a game.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

new_to_sfml

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Moving vertex arrays?
« Reply #4 on: April 09, 2021, 11:33:22 am »
I can draw four squares next to each other etc., but I also need the program to "see" those four squares as one entity because I think it would make it simpler to use. So I have to join them somehow in code and I'm not sure how to do it.
I don't see any method that seems helpful to do so in sf::Sprite documentation.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Moving vertex arrays?
« Reply #5 on: April 09, 2021, 11:47:54 am »
You can wrap them in a class and use that as your "glue" code.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything