Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Making a custom QML type element or just use regular elements
Forum Updated to NodeBB v4.3 + New Features

Making a custom QML type element or just use regular elements

Scheduled Pinned Locked Moved Game Development
3 Posts 3 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shry.harsh
    wrote on last edited by
    #1

    I am making a game. There are two characters in the game like 'hero' and 'enemy'. I have made separate classes of them. Should I declare a new custom type for each character like

    import QtQuick 1.1
    import hero 1.0
    Hero{
    power:100
    energy:100
    image:"/src/hero.png"
    }

    or just use a regular element like

    import QtQuick 1.1
    Image{
    source:hero.getImgSource() //method declared in hero class
    }

    So, I am in confusion to make a new element or just use the existing one and use the C++ bindings with QML. Is there any other approach to do so?

    Thanks in advance...

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Alek Śmierciak
      wrote on last edited by
      #2

      You can either use C++, Python or other bindings or you can implement game logic directly in QML with Javascript. It depends on your approach as it is your decision.
      However, it is good to separate logic (model) from display (view) in my opinion, making the application architecture more elastic and clear to others - and to yourself later on.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        feldifux
        wrote on last edited by
        #3

        Hi,
        in V-Play we have made good experience with the component-based architecture and an entity system that we designed. What this means, is that you have components for displaying an entity (defined in the set of "visual components":http://v-play.net/doc/vplay-group.html#visual-components), some for collision detection, sounds, and then there are some for logic like AI behaviors or others.

        Here is an example how one of a game entity in the open-source game "StackTheBox":http://v-play.net/doc/demos-stackthebox.html looks like, taken from Wall.qml:
        @
        import QtQuick 1.1
        import VPlay 1.0
        import Box2D 1.0 // for accessing the Body.Static type

        EntityBase {
        entityType: "wall"

        // this gets used by the top wall to detect when the game is over
        signal collidedWithBox

        // this allows setting the color property or the Rectangle from outside, to use another color for the top wall
        property alias color: rectangle.color

        Rectangle {
        id: rectangle
        color: "blue"
        anchors.fill: parent
        }
        BoxCollider {
        anchors.fill: parent
        // use "import Box2D 1.0" to access the Body.Static type
        bodyType: Body.Static // the body shouldnt move

         fixture.onBeginContact: collidedWithBox()
        

        }
        }@

        It does not really matter if you write the base components in QML or C++, although I would start with QML & JavaScript and only write the stuff that requires high performance in C++ because you are much faster to develop and iterate quicker.

        You can also have a look at our other open-source games, maybe you find some concepts that you can use in your game: http://v-play.net/doc/vplay-examples.html

        Cheers, Chris

        Founder of Felgo SDK - http://felgo.com/qt

        Felgo simplifies

        • Mobile App Dev with Qt esp. iOS & Android
        • Game Development with Qt

        What others say

        Felgo scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved