Find the Best Demos and Examples

Check out this quick tour to find the best demos and examples for you, and to see how the Felgo SDK can help you to develop your next app or game!

Forums

OverviewFelgo 1 Support › Whats the common way to smash an entity?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #6412

    florian.kieninger

    Hello,

     

    i want to know what’s the common way to smash an entity when something drops on it.

    So the height becomes smaller and smaller.

     

    I have tried some ways, but with no success.

    For example changing the height of the entity and so on…

     

    Thanks for tips,

    Florian

    #6458

    Alex
    Felgo 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

     

     

     

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

RSS feed for this thread

You must be logged in to reply to this topic.