Forums

OverviewV-Play 1 SupportDisable Bounce on BoxCollider › Reply To: Disable Bounce on BoxCollider

OverviewV-Play 1 SupportDisable Bounce on BoxCollider › Reply To: Disable Bounce on BoxCollider
#4253

phil.jahoda

Here is my Baloon.qml, I am sorry, the code tag does not seem to work.

import QtQuick 1.1
import Box2D 1.0
import VPlay 1.0
import "../particles"

EntityBase {
  id: entity
  width: 20
  height: 25
  entityType: "baloon"
  
  property alias baloonImg: baloonImg
  
  BoxCollider {
    id: boxCollider
    bodyType: Body.Static
    width: baloonImg.width
    height: baloonImg.height
    
    // like this, an offset for the rotation could be set which is only applied for the collider, not for the entity!
    // rotation: 45
    
    anchors.centerIn: parent
    
    // set friction between 0 and 1
    fixture.friction: 0
    // restitution is bounciness
    fixture.restitution: 0
    // if you want to make objects fall faster, increase gravity (and not density)
    // with higher density, the player behaves differently at collisions as it is heavier
    fixture.density: 0
    
    fixture.onBeginContact: {
      
      var fixture = other;
      var body = other.parent;
      var component = other.parent.parent;
      var collidedEntityType = component.owningEntity.entityType;
      
      var collidingType = component.owningEntity.entityType;
      // play the collision sound when the box collides with anything, but not if the sound is already playing
      if(scene.collisionSoundsEnabled && !collisionSound.playing)
        collisionSound.play();
      
      if(scene.particlesEnabled)
        collisionParticleEffect.start();
      
      if(collidingType === "dartarrow" ) {
        entity.removeEntity();
        
        return;
      }
    }
  }
  
  Image {
    id: baloonImg
    source: "../img/baloon_green.png"
    // this is the size compared to the scene size (480x320) - it will automatically be scaled when the window size is bigger than the scene
    // the image will automatically be scaled to this size
    width: 20
    height: 25
    
    // this is required to have the center in the middle of the enity and not the top left point as origin of the image
    anchors.centerIn: boxCollider
  }
  
  // gets played at a collision
  Sound {
    id: collisionSound
    source: "../snd/boxCollision.wav"
  }
  
  // this particle effect is played when colliding with an obstacle
  SmokeParticles {
    id: collisionParticleEffect
  }
}

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