Forums

OverviewFelgo 2 Support (Qt 5) › Few questions about Squaby design decisions

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #15530

    Marcin

    Hello Felgo,
    .
    I have a similar approach to some things like in Squaby demo.
    I try to borrow from it as much as possible, for example the design to have EditableComponent in base object for Entity to have nice Editor, or the way to create multiple instances of the same entity.

    Main topic is component vs item.
    I think I understand the difference, Qt Docs are quite clear here.
    Just don’t understand why you used component in few particular places, what was the benefit there.
    It is not urgent just would like to understand more why I am coping design from you ­čÖé

    1. Is there any particular reason why you wrap Squaby entities with component?
    It looks nice but I don’t understand why not just using normal entities wouldn’t be enough.

       Component {
            id: squabyYellow
            Squaby {
                id: sy
                variationType: "squabyYellow"
                score: balancingSettings.squabyYellow.score
                gold: balancingSettings.squabyYellow.gold
                health: balancingSettings.squabyYellow.health
                damageMultiplicatorNailgun: balancingSettings.squabyYellow.damageMultiplicatorNailgun
                damageMultiplicatorFlamethrower: balancingSettings.squabyYellow.damageMultiplicatorFlamethrower
                damageMultiplicatorTaser: balancingSettings.squabyYellow.damageMultiplicatorTaser
                damageMultiplicatorTesla: balancingSettings.squabyYellow.damageMultiplicatorTesla
                pathMovementPixelsPerSecond: balancingSettings.squabyYellow.pathMovementPixelsPerSecond
            }
        }
    
        Component {
            // high fire resistance
            id: squabyOrange
            Squaby {
                variationType: "squabyOrange"
                score: balancingSettings.squabyOrange.score
                gold: balancingSettings.squabyOrange.gold
                health: balancingSettings.squabyOrange.health
                damageMultiplicatorNailgun: balancingSettings.squabyOrange.damageMultiplicatorNailgun
                damageMultiplicatorFlamethrower: balancingSettings.squabyOrange.damageMultiplicatorFlamethrower
                damageMultiplicatorTaser: balancingSettings.squabyOrange.damageMultiplicatorTaser
                damageMultiplicatorTesla: balancingSettings.squabyOrange.damageMultiplicatorTesla
                pathMovementPixelsPerSecond: balancingSettings.squabyOrange.pathMovementPixelsPerSecond
            }
    }


    2. Another thing is why do you use ComponentBase and not normal Item, as a base for HealthComponent?

    From what I understand from docs, components are not shown by default and are only drawn on demand.
    Components are better for reusing and more encapsulate the internals, better public interface.
    Still not see the main benefit in this scenario.
    I see there is a property owningEntity in ComponentBase so probably is to connect entity and component.
    Why not make health a part of the entity?

    3. Another one about components
    I saw you use few times Style object from Qt(qml/common/SquabyStyle.qml).
    Looks kind of advanced. What was the main reason you went as far as for styles, and just not created anything on your own?

    PS. Any explanation or link to some docs would be useful.
    Of course my game is not that advanced that’s why I won’t use similar approach like in Squaby demo everywhere.
    Would be over complicated without much benefits.

    Best regards,
    Marcin

    #15667

    G├╝nther
    Felgo Team

    Hi and sorry for the late reply!

    I wasn’t part of the Squaby Dev Team, so I’m not sure if this is correct but here’s what I think:

    1. Wrapping Squaby Entities in Components
    An entity is in its essence just a normal QML item. So when dynamically creating entities at runtime there’s two options:
    – Create the entity┬ádirectly from the entity QML file (with┬áEntityManager::createEntityFromUrl)
    – Create the entity from a Component (with EntityManager::createEntityFromComponent)
    But both options actually require a Component before objects can be created at runtime (from the Qt side of things). When manually defining the Component in QML for usage with createEntityFromComponent, the component itself is automatically created along with the other items in your QML file. It is then possible to directly create objects from this component (Qt.createObject) without additional effort.

    If the Component is not defined in QML, it has to be created at runtime┬á(Qt.createComponent) first before you can then use createObject, which is the case when using createEntityFromUrl. These createComponent and createObject functions are used by the EntityManager behind the scenes, so there can be a slight performance improvement when using createEntityFromComponent (no Qt.createComponent call is needed) – although our EntityManager tries to reuse components or pool entities so in the end I guess there is not that much noticeable difference.

    I think for Squaby, the main reason for wrapping the Squabies into Components is this:
    – Theres only one base entity “Squaby” which is defined in Squaby.qml
    – You could now create SquabyYellow.qml, SquabyOrange.qml, …┬áwhich are different variations of┬áSquaby.qml with only small changes
    – But instead, there’s now only SquabyTypes.qml, which defines all the sub-types of the Squaby entities in one file as Components

    So basically there’s
    – maybe a slight performance improvement
    – and no additional QML files are required for the Squaby entity variations

     

    2) HealthComponent

    ComponentBase which is used in HealthComponent is despite its name just a normal Item with a property owningEntity. I guess it was just a design decision to split up the entities and health items. I wouldn’t give it too much thought.

     

    3) Styles

    Well I’ll just put it that way: If Qt already offers UI components that can be restyled for e.g. buttons and other controls, why not use them and just add your own style? Also the separation of style and logic is simply┬áa form of nice code architecture and it might be faster than doing everything with custom items.

    However, as Squaby is a bit old the used Qt controls and custom styles are outdated as well. You now have much better controls and styling options with the Qt Quick Controls 2.

     

    Hope this was helpful!

     

    Best,
    G├╝nther

     

    #15791

    Marcin

    Hi G├╝nther,
    Sorry for late answer ­čÖé
    Thank you for the answers, makes sense.
    Definitely using components in Squaby entities had a lot of sense.

    As for Qt Styles, will investigate a little.
    Not sure if any of the examples on Felgo docs mention using this technique(do not reinvent the wheel with Buttons etc), but if not, maybe would be worth to mention it.

    Thank you,
    Marcin

Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support