Forums

OverviewV-Play 1 SupportProblems with cocos-renderer › Re: Problems with cocos-renderer

OverviewV-Play 1 SupportProblems with cocos-renderer › Re: Problems with cocos-renderer
#4024

Heini

Hi Chris,

even Qt.resolvedUrl() does not work. CocosRenderer is only able to load my recources by passing an absolute filepath. Strange that the relative paths work with standardQmlRenderer. Here is the code from my main.qml and box.qml:

main.qml:

import VPlay 1.0
import QtQuick 1.1
import Box2D 1.0
import "entities"

GameWindow {

    id: window

    EntityManager{
       id: entityManager
       entityContainer: scene
    }

    Scene
    {
        id: scene

        Component{
            id: mouseJoint
            MouseJoint{
                maxForce: 30000
                dampingRatio: 1
                frequencyHz: 2
            }
        }

        MouseArea{
            anchors.fill: parent

            property Body selectedBody: null
            property MouseJoint mouseJointWhileDragging: null

            onPressed: {
                selectedBody = physicsWorld.bodyAt (Qt.point (mouseX,mouseY));
                console.debug("selected body at position", mouseX, mouseY, ":", selectedBody);
                if (selectedBody)
                {
                    mouseJointWhileDragging = mouseJoint.createObject(physicsWorld)
                    mouseJointWhileDragging.target = Qt.point (mouseX, mouseY)
                    mouseJointWhileDragging.targetBody = selectedBody
                    mouseJointWhileDragging.world = physicsWorld
                }
            }
            onPositionChanged: {
                if(mouseJointWhileDragging)
                {
                    mouseJointWhileDragging.target = Qt.point (mouseX, mouseY)

                }
            }
            onReleased: {
                if (selectedBody)
                {
                    selectedBody = null
                    if (mouseJointWhileDragging)
                        mouseJointWhileDragging.destroy()
                }
            }
        }

        PhysicsWorld{
           id: physicsWorld
            gravity.y: -9.81
        }

        Box {
            x: scene.width/2
            y: 50
        }


        Timer{
            id: timer
            interval: Math.random()*3000+2000
            running: true
            repeat: true
            onTriggered: {
                var newEntityProperties = {
                    x: Math.random()*(scene.width-50)+50,
                    y: 50,
                    rotation: Math.random()*360
                }

                entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("entities/Box.qml"), newEntityProperties);

                interval = Math.random()*3000+2000
                scene.createdBoxes++
                timer.restart()
            }
        }

        property int createdBoxes: 1

        Text
        {
            text: "Boxes: " + scene.createdBoxes
            color: "white"
            z: 1
        }

        Wall{
            //bottom wall
            height: 20
            anchors {
                bottom: scene.bottom
                left: scene.left
                right: scene.right
            }
        }

        Wall{
            //left wall
            width: 20
            anchors{
                top: scene.top
                bottom: scene.bottom
                left: scene.left
            }
        }

        Wall
        {
            //right wall
            width: 20
            height: scene.height
            anchors.right: scene.right
        }

        Wall
        {
            //top wall
            height: 20
            width: scene.width
            anchors{
                top: scene.top
            }
            color: "red"

            onCollidedWithBox: {
                entityManager.removeEntitiesByFilter(["box"]);
                scene.createdBoxes = 0;
            }
        }
    }
}

box.qml:

[// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import VPlay 1.0
import "../particles"

EntityBase
{

    entityType: "box"


    Image{
        id: boxImage
        source: Qt.resolvedUrl("box.png") //does not work
        //source: "box.png" //does not work
        anchors.fill: boxCollider

    }

    BoxCollider{
        id: boxCollider
        width: 32
        height: 32
        anchors.centerIn: parent

        friction: 1.6
        restitution: 0
        density: 100

        fixture.onBeginContact: {
            collisionSound.play();
            collisionParticleEffect.start();

        }
    }

    Sound{
        id: collisionSound
        source: "boxCollision.wav"
    }

    SmokeParticles{
        id: collisionParticleEffect
    }
}

The directory of box.qml is named “entities”, contains box.qml, box.png and boxCollision.wav. Its a subdirectory of the directory containing the main.qml

Greetings

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