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?
#8663

Alex
V-Play Team

Hi,

the deactivation and reactivation needs to be handled in the onMovedToPool and onUsedFromPool signal handlers of the entity.

Regarding your entities, I’m not quite sure how your exact game logic looks like, but maybe something like this could help you:

As you said, the key detects the collision, so the key obviously knows all the actions that can happen to him, so what i like to do in this cases is having a distinct game logic object that can be accessed from the entities, with functions to handle those actions. This could look like this:

GameLogic {
  function keyCollided(key,collidedWith) {
    // do something like this
    entityManager.removeEntityById(key.entityId)
  }
}

 

Scene {
  id: gameScene

  property alias gameLogic: gameLogic
  GameLogic {
    id: gameLogic
  }
}

 

EntitiyBase {
  id: entitiy

  // ...

  BoxCollider {
    // ...
    fixture.onBeginContact: {
      // actually physical bodies collide, to get the entity we have to navigate <body>.<fixture>.<collider>.<entity>
      var collidedEntity = other.parent.parent.owningEntity
      gameScene.gameLogic.keyCollided(entity,collidedEntity)
    }
  }
}

If the key collides with something, it tells the gameLogic that a collision happened, and passes a reference to himself and the collided entity. Now the gameLogic can access all items that participated in the action. If the actions are different in every level, consider moving the gameLogic to the different levels then.

I hope this helps you :)

Cheers,
Alex

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