Forums

OverviewV-Play 2 Support (Qt 5)How to access signals from dynamically created entities? › Reply To: How to access signals from dynamically created entities?

OverviewV-Play 2 Support (Qt 5)How to access signals from dynamically created entities? › Reply To: How to access signals from dynamically created entities?
#8813

Martin

Thanks for the suggestion – I made the problem “go away” for a while, so I only just got back to this.   I need to deal with it now.

I hope you will understand what I mean when I observe that while this obviously works, its not “good” in the sense of “clean design”.

signals exist to provide a clean interface between entities.   This solution breaks that: it requires that the scene instantiating the entity have a fixed name, and have a logic block with a fixed name as well.

What if I need to use the entity in more than one “game scene”?   Maybe I want to make little display in my credits scene, for example?   Then the entity will not have a “gameScene” to refer to.

I’ve worked out that I can actually achieve what I’m trying to do by using function-properties instead of signals:

In my Grunt.qml:

EntityBase {
    id: grunt
    entityType: "grunt"

    property var kickedNinja: function() {console.log("grunt kicked ninja - no further action")}


    
    fixture.onBeginContact: {
      # ... blah blah

     if (collidedEntityType == "ninja") {
                var ninja = collidedEntity
                if (ninja.kickState == "idle") {
                    console.log("Hah! (grunt kicks ninja)")
                    ninjaKicked.play()
                    kickedNinja()

 

 

Where a change is needed statically (in QML) of a level:

    function highlightKickController() {
        jumpKickController.highlightKick = true;
    }

    Repeater {
        model: 3
        Grunt {
            x: blockPlatformLeft.x+blockPlatformLeft.width + width * index
            y: 0
            kickedNinja: highlightKickController
        }
    }

And where it needs to be added to a dynamically created entity:

                // make a new grunt
                var newGruntProperties = {
                    y: gruntEntryY,
                    x: gruntEntryX,
                    kickedNinja: newKickedNinja
                }
                entityManager.createEntityFromUrlWithProperties(
                            Qt.resolvedUrl("../entities/Grunt.qml"),
                            newGruntProperties);

where newKickedNinja is of course a function pointer passed into this routine by the level that wants to do something different.

It’s kind of do-it-yourself signals ….

 

 

 

 

  • This reply was modified 3 years, 6 months ago by  GreenAsJade.
  • This reply was modified 3 years, 6 months ago by  GreenAsJade.

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