Here’s the whole project – Andreas Jakl wasn’t able to find the error.
It seems that the boxcolliders of the serveral entities (from the same type) depend on each other – although they shouldn’t because they are all unique entities???
Yours KitKat
// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import VPlay 1.0
EntityBase {
entityType: "ball"
// signal collidedWithBall
Component.onCompleted: console.debug("Ball.onCompleted()")
Component.onDestruction: console.debug("Ball.onDestruction()")
width: 32
height: 32
Image {
source: "../img/ball.png"
//anchors.fill: boxCollider
x: boxCollider.x
y: boxCollider.y
width: 32
height: 32
}
BoxCollider {
id:boxCollider
x: -width/2
y: -height/2
Rectangle
{
anchors.fill:parent
color: "blue"
}
fixture.onBeginContact: {
var fixture = other;
var body = fixture.parent;
var component = body.parent;
var collidedEntity = component.owningEntity;
var collidedEntityType = collidedEntity.entityType;
if (collidedEntityType === 'ball') {
removeEntity();
}
if (collidedEntityType==='block1' || collidedEntityType==='block2'
||collidedEntityType==='block3' ||collidedEntityType==='block4'
||collidedEntityType==='block5' || collidedEntityType==='ente'
||collidedEntityType==='auto' ||collidedEntityType==='turm' || collidedEntityType==='teddy') {
//TODO stehenbleiben!
}
}
}
}
// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import VPlay 1.0
import QtQuick 1.1
import "./entities"
import "./levels"
SceneBase{
id:gameScene
//property alias level: level1
//property alias entityContainer: level1
width: 480
height: 320
property string activeLevelStrg
property variant activeLevel
PhysicsWorld {
id:physicsWorld
gravity.y: -9.81
z: 10 // draw the debugDraw on top of the entities
// these are performance settings to avoid boxes colliding too far together
// set them as low as possible so it still looks good
updatesPerSecondForPhysics: 30
// velocityIterations: 2
// positionIterations: 5
}
function enterScene() {
//level1.startGame();
//loadLevel();
}
SimpleButton{
text:"Back to menu"
anchors.right: parent.right
onClicked:backPressed()
}
onBackPressed: {
// it is important to call stopGame() here, because otherwise the entities would not be deleted!
//level1.stopGame();
window.state = "main"
}
// load levels at runtime
Loader {
id: loader
source: "levels/" + gameScene.activeLevelStrg + ".qml"
onLoaded: {
// do not forget to call loadItemWithCocos or the item might not be displayed correct!
loadItemWithCocos(item)
activeLevel = item
item.width = gameScene.width
item.height = gameScene.height
}
}
// set the name of the current level, this will cause the Loader to load the corresponding level
function setLevel(level) {
activeLevelStrg = level
}
EntityBase {
entityId: "ground1"
entityType: "ground"
height: 0
preventFromRemovalFromEntityManager: true
anchors {
bottom: gameScene.bottom
left: gameScene.left
right: gameScene.right
}
Rectangle {
anchors.fill: parent
color: "blue"
}
BoxCollider {
anchors.fill: parent
bodyType: Body.Static // the body shouldnt move
}
}
EntityBase {
// left wall
entityId: leftWall
entityType:"leftWall"
width: 0
height: gameScene.height
preventFromRemovalFromEntityManager: true
anchors {
left: gameScene.left
}
Rectangle {
color: "blue"
anchors.fill: parent
}
BoxCollider {
anchors.fill: parent
bodyType: Body.Static // the body shouldnt move
}
}
EntityBase {
// left wall
entityId: rightWall
entityType:"rightWall"
width: 2
height: gameScene.height
preventFromRemovalFromEntityManager: true
anchors {
right: gameScene.right
//rightMargin: gameScene.right+288
}
Rectangle {
color: "blue"
anchors.fill: parent
}
BoxCollider {
anchors.fill: parent
bodyType: Body.Static // the body shouldnt move
// fixture.onBeginContact: collidedWithBox()
}
}
MouseArea {
width:320
height:320
property Body selectedBody: null
property int lastY;
property int lastX;
property bool newMove : true;
onPressed: {
selectedBody = physicsWorld.bodyAt(Qt.point(mouseX, mouseY)); //nur der Collider!!!
console.debug("selected body at position", mouseX, mouseY, ":", selectedBody);
// if the user selected a body, this if-check is true
if(selectedBody) {
console.debug("in ONPRESSED - Selected Body: ", selectedBody);
lastY = mouseY;
lastX = mouseX;
newMove=true;
}
}
onPositionChanged: {
//TODO wenn true und nicht bewegt wird!
if (newMove===true) {
if (mouseX < lastX) {
// mouseJointWhileDragging.targetPoint = Qt.point(lastX-32, mouseY)
selectedBody.x = selectedBody.x-32;
} else {
//mouseJointWhileDragging.targetPoint = Qt.point(lastX+32, mouseY)
selectedBody.x = selectedBody.x+32;
}
newMove = false;
}
}
}
Component {
id: mouseJoint
MouseJoint {
// make this high enough so the box with its density is moved quickly
maxForce: 30000
// The damping ratio. 0 = no damping, 1 = critical damping. Default is 0.7
dampingRatio: 1
// The response speed, default is 5
frequencyHz: 2
}
}
}
// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import VPlay 1.0
import QtQuick 1.1
import "../entities"
Item{
// the size of the Window can be changed at runtime by pressing the number keys 1-7
// the content of the logical scene size (480x320 by default) gets scaled to the window size based on the scaleMode
// you can set this size to any resolution you would like your project to start with, most of the times the one of your main target device
// this resolution is for iPhone 4 & iPhone 4S
// change this to a portrait resolution (e.g. 640x960) for games in portrait mode
id:level1
Block1 {
x:32
y:256
}
Block4 {
x:96
y:128
}
Block3 {
x:128
y:96
}
Block3 {
x:128
y:288
}
Block1 {
x:320
y:256
}
Ball {
x:32
y:224
}
Ball {
x:64
y:288
}
Ente {
x:96
y:98
}
Ente {
x: 64
y: 224
}
Auto {
x:128
y:256
}
Auto {
x:96
y:288
}
Auto {
x:128
y:64
}
Turm {
x:160
y:288
}
}