Godot Version
4.4
Question
i wanted to make a card game. i see some ppl put all tha cards on one script. is doing that better than making a separated scene for each card. i wanted to do the later
4.4
i wanted to make a card game. i see some ppl put all tha cards on one script. is doing that better than making a separated scene for each card. i wanted to do the later
Either works. Try scene-per-card if you want. The question of “better” is largely a question of opinion, and a lot of that is going to come down to what your cards do in your card game. In the extreme, if you were making (say) something like Magic where every card is unique and has wildly differing capabilities, it would make a lot of sense to split each card into its own script.
In general, I wouldn’t worry too much about “best practices”; try stuff, and you’ll learn what works for your style of programming. You might find in this case that putting all the cards in one script works best for you. You might find putting each card in its own script works best. You might find that there are categories of cards and a script for each category is best.
Try what makes sense to you. Either it’ll work or you’ll learn useful things.
i wanted to know since i its similar to mtg but i heard it could slow stuff
I wouldn’t worry too much about performance for a card game; if it does turn out to be a performance problem you can always merge or split things later, but I bet it runs at a solid 60fps (or whatever your monitor refresh rate is) regardless of how you split the scripts up.
If you were animating thousands of cards at once or trying this on a 16bit cpu it might be different, but even cheap hardware is crazy fast these days.
The one issue to be aware of is that any script with a _process()
or _physics_process()
function will run that function every update if it’s in the scene tree, even if it isn’t visible. A few hundred cards running scant _process()
calls every frame isn’t going to do much, but you probably want to stick something in testing is_visible_in_tree()
so they don’t execute updates when you don’t want them to.
i see thanks. but dont worry i dont plan it to be very flashy like mtg arena