Forums

OverviewV-Play 1 SupportWhats the common way to smash an entity? › Reply To: Whats the common way to smash an entity?

OverviewV-Play 1 SupportWhats the common way to smash an entity? › Reply To: Whats the common way to smash an entity?
#6458

Alex
V-Play Team

Hi Florian,

here is a small example how to decrease the height of a “smashable” box everytime another box drops on it.

Box.qml

import QtQuick 1.1
import Box2D 1.0
import VPlay 1.0

EntityBase {
  id: entity
  entityType: "box"

  width: 32
  height: 32
  BoxCollider {
    id: boxCollider
    anchors.fill: parent
    // restitution is bounciness
    fixture.restitution: 0.8

    fixture.onBeginContact: {
      if(variationType != "smashable") return;
      var fixture = other;
      var body = fixture.parent;
      var component = body.parent;
      var collidedEntity = component.owningEntity;
      var collidedEntityType = collidedEntity.entityType;
      var collidedEntityVariationType = collidedEntity.variationType;
      if(collidedEntityType === "box" && entity.height > 5) {
        entity.height = entity.height-3;
      }
    }
  }

  Rectangle {
    id: sprite
    color: "blue"
    anchors.fill: parent
  }
}

 

main.qml

import VPlay 1.0
import QtQuick 1.1
import "entities"

GameWindow {
  id: window

  EntityManager {
    id: entityManager
  }

  Scene {
    id: scene
    PhysicsWorld {gravity.y: -10}

    Box {
      x: 100
    }

    Box {
      x: 100
      y: 300
      variationType: "smashable"
    }

    EntityBase {
      id: ground
      entityType: "ground"
      height: 5
      anchors.left: scene.left
      anchors.right: scene.right
      anchors.bottom: scene.bottom
      Rectangle {
        color: "red"
        anchors.fill: parent
      }
      BoxCollider {
        anchors.fill: parent
        bodyType: Body.Static
      }
    }
  }
}

Is this kind of what you are looking for?

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