Forums

OverviewV-Play 1 SupportEntityBaseDraggable with embedded ParallaxItem › Reply To: EntityBaseDraggable with embedded ParallaxItem

OverviewV-Play 1 SupportEntityBaseDraggable with embedded ParallaxItem › Reply To: EntityBaseDraggable with embedded ParallaxItem
#5228

Alex
V-Play Team

Yeah i was working with the nice settings of your post the whole time, can’t wait to see the real game 😀

 

I was thinking of this setup:
BEButton.qml not changed.
Block.qml

import QtQuick 1.1
import VPlay 1.0
import Box2D 1.0

EntityBaseDraggable {
  id: obstacle
  entityType: "obstacle"

  width: size
  height: size

  property int size: 64

  colliderComponent: collider
  selectionMouseArea.anchors.fill: collider
  gridSize: size

  Rectangle {
    id: rectangle
    color: "yellow"
    x: -width/2
    y: -height/2
    width: parent.width
    height: parent.height
  }
  BoxCollider {
    id: collider
    x: -width/2
    y: -height/2
    bodyType: Body.Static
  }
}

Just a simple standard EntityBaseDraggable this time.
And now main.qml

import VPlay 1.0
import QtQuick 1.1

GameWindow {
    activeScene: scene
    width: 960; height: 640
    focus: true
    Keys.forwardTo: controller

    EntityManager{
        id: entityManager
        entityContainer: levelgrid
        dynamicCreationEntityList: [Qt.resolvedUrl("Block.qml")]
    }

    TwoAxisController {
        id: controller
        inputActionsToKeyCode: {
            "up": Qt.Key_W,
                    "down": Qt.Key_S,
                    "left": Qt.Key_D,
                    "right": Qt.Key_A,
                    "fire": Qt.Key_Space
        }
    }

    MovementAnimation{
        target: levelContainer
        property: "pos"
        running: true
        property real scale: 200
        velocity: Qt.point(controller.xAxis*scale,controller.yAxis*scale)
    }

    Scene {
        id: scene
        width: 480
        height: 320
        state: "levelEditing"

        PhysicsWorld {}

        LevelEditor {
            id: levelEditor
            toRemoveEntityTypes: ["obstacle"]
            toStoreEntityTypes: ["obstacle"]
        }

        // === LEVEL ===
        Item{
            id: levelContainer

            // === BACKGROUND ===
            ParallaxItem{
                id: background
                ratio: Qt.point(0.6,0.6)
                z:1

                Grid{
                    rows: 10; columns: 10; spacing: 50
                    Repeater{
                        model: 100
                        Rectangle{
                            width: 100; height: 100
                            color: "grey"
                        }
                    }
                }
            }

            // === GAME LAYER ===
            Item{
                id: levelgrid
                z:2

                Grid{
                    rows: 10; columns: 10; spacing: 75
                    Repeater{
                        model: 100
                        Rectangle{
                            x: 75; y: 75
                            width: 75; height: 75
                            color: "red"
                        }
                    }
                }
            }

            // === FOREGROUND ===
            ParallaxItem{
                id: foreground
                ratio: Qt.point(1.3,1.3)
                z:3

                Grid{
                    rows: 10; columns: 10; spacing: 100
                    Repeater{
                        model: 100
                        Rectangle{
                            x: 100; y: 100
                            width: 50; height: 50
                            color: "Blue"
                        }
                    }
                }
            }
        }
        BEButton{ }
    }
}

Now we got a parallax background and a parallax foreground, moving with the defined ratio to the (non-parallax but standard Item instead) game layer between them. Note that i also changed the

entityContainer: levelgrid

of the EntityManager for correct visibility (z-order) of the entities.

Now if you run your project, you can see that you can drag and drop around your entities anywhere in the game layer.

I hope this is 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