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

Author Topic: How would I handle displaying cards?  (Read 2743 times)

0 Members and 2 Guests are viewing this topic.

Sixoul

  • Newbie
  • *
  • Posts: 17
    • View Profile
How would I handle displaying cards?
« on: April 01, 2014, 02:25:29 am »
There were a couple things I was wondering. How would someone make a card, like applying the textures and displaying it? I don't think there would be a texture of every single card, that seems inefficient. Let's say for this card from weiss schwarz card game.
http://images.littleakiba.com/tcg/weiss-schwarz/cards/card10699.jpg

I figured something like this would be a shape, maybe something else if it works better. Then a layer of various textures applied. Where the only different texture would be the main image of the card with the rest being the icons. Then text applied appropriately. I'm not sure if that's right or if I'm even on the right track. But also something that has me scratching my head is handling the text boxes. They shrink and expand based on the amount of text. Would that just be stretching or shrinking the texture vertically?
Here's an example of a card with less text.
http://images.littleakiba.com/tcg/weiss-schwarz/cards/card10712.jpg

I'm just using these cards as examples since I like the design of the text boxes and it really maximizes the image.


Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: How would I handle displaying cards?
« Reply #1 on: April 01, 2014, 08:37:26 am »
I think I would make 5 images (textures) one for each suit with pictures of each card in that suit in a grid and one holding jokers and various card backs. Or maybe just one huge texture using Thor::BigTexture.
Then I would make a sprite for each card, mapping its texture coordinates to the proper rectangle within one of my 5 large textures.
For the type of cards you link to (as opposed to normal playing cards) I would probably create a big texture with all the different backgrounds, one with the various elements that can change and then just draw them on top of each other to a render texture or directly to the screen; just layering images on top of each other.
Simple as that.
« Last Edit: April 01, 2014, 08:41:19 am by Jesper Juhl »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: How would I handle displaying cards?
« Reply #2 on: April 01, 2014, 08:38:34 am »
Depending on how dynamic you need it, you could use sf::RenderTexture to pre-render a card from different sprites, text and shapes.

If you want adaptive text that breaks automatically within a box, you need to handle line breaks yourself. Some time ago there have been a few classes around that do this, you could search the forum and wiki.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: How would I handle displaying cards?
« Reply #3 on: April 01, 2014, 08:45:46 am »
The easiest approach regarding rendering would be to have all cards created externally. So you'd just have to set the right texture rect, but this will be quite static if you try to balance things, since you'd have to edit each card externally.
Instead you could just have textures of the backgrounds and shapes. Then you could draw things on top of each other and apply the text manually, thus allowing you to connect the stats at runtime and change it rather easily, without having to edit the cards and possibly missing that once card game stats got changed but the image itself hasn't.
Of course if you render everything on your own, you'll have to do your own math on how big the text box will be etc.

As an optimization it might be useful to prepare cards when starting the game, thus rendering things to a render texture and then using texture rects to select the right cards.

Also keep in mind before you start implementing the visual side of the game, you should work out the back-end, because that's most likely the more difficult part after all. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Peteck

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: How would I handle displaying cards?
« Reply #4 on: April 01, 2014, 08:55:37 am »
As I living of being a web developer my brain want me to split everything up. When coding a layout for website I like to cut everything out into separate files, just so I won't get big image files and long loading times. And most likely I'll find out that I can use simple rectangle shapes to replace the images and then avoid even a bigger image load. When you're designing the cards in photoshop (or whatever program you'll use), I guess you'll use layers. Split all these layers into separate images. But to avoid loading alot of images, you can just put all these common image parts for your cards, into ONE bigger image file and use the setTextureRect() on the sprite class to locate your image parts for your cards.