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

Author Topic: Designquestion Spinning Card  (Read 1792 times)

0 Members and 1 Guest are viewing this topic.

Raincode

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Designquestion Spinning Card
« on: April 17, 2015, 11:35:21 pm »
Hello dear community,

EDIT: Current solution: Using 1-Dimensional vector. Not sure if it will work all the way through. Maybe should have put more time into library specific design.

I saw the spinning card in the projects forum a while back. Now I have to make a memory game, and I immediately thoght about it, and how cool it would be to use it.

I altered the example and achieved an effec exactly what I want it to look like (with a single card, in a single main function).

However, it becomes much more difficult in an object oriented environment:

I have created a class that uses the spinning card classes "Card". (I also used this in my minimal example).
It manages the 2 spinning cards/sprites and provides a 'flip' and 'update' function and also inherits sf::Drawable.

In my Game class I wanted an array<array<Card, 4>, 6>, representing the memory cards. My Problem: There is no suitable default constructor for Card, because there is none for SpinningCard either. So, the compiler complains, and gives an Error C2512:
error C2512: 'std::array<std::array<Card,4>,6>' : no appropriate default constructor available

I don't know how to solve this Problem. I simply can't initialize the cards before loading the sprites and setting their position.

I hope somebody can give me some tips on how to change my design to make it work.

Raincode
« Last Edit: April 18, 2015, 12:07:47 am by Raincode »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10823
    • View Profile
    • development blog
    • Email
Re: Designquestion Spinning Card
« Reply #1 on: April 18, 2015, 12:30:13 am »
EDIT: Current solution: Using 1-Dimensional vector. Not sure if it will work all the way through. Maybe should have put more time into library specific design.
That's the best way to do it. Multi dimensional arrays are not recommended with C-arrays, nor std::array, nor std::vector.
Use a std::vector and calculate the "multiple" dimensions from the indices itself.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Raincode

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: Designquestion Spinning Card
« Reply #2 on: April 18, 2015, 10:35:46 am »
Hey eXpl0it3r,

thanks very much for your reply. The fact that SFML provides a "contains()" function really made it easier for me and allowed me to easily use a 1D vector simply storing the elements.

Raincode

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Designquestion Spinning Card
« Reply #3 on: April 19, 2015, 10:49:53 pm »
Hi again, Raincode.

I did post this is in the actual Spinning Card thread too but just so that this thread has the information, here it is again:
Quote
Spinning Card wasn't designed to be used as an actual object itself (that is copied, moved, compared, sorted etc.) but rather an animation object that temporarily replaces a standard sprite (the card) during the spin animation and then re-replaced by the sprite (the card - most likely, the other side). This way, if you only spin one card at a time, you only require one instance of SpinningCard, and it only needs to exist for the duration of the spin animation.

This would mean that you only need to have a container of sprites and a "handful" of SpinningCards, depending on how many cards you need to be spinning at once. It could be just one or many but they can be destroyed when the spin animation is over, where you would start displaying the original sprite again with its texture altered to show the side required.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything