Forums

OverviewV-Play 1 Support › Platform Game, with large worlds

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #6068

    Caeser

    It’s is possible to create a platform game with V-play? If so, how is camera movement implemented? (following the character around the world that’s bigger than the window.

    #6069

    Alex
    V-Play Team

    Hi,

    of course it is possible :)

    There is already a platformer made with V-Play in the app stores, Chicken Outbreak, which is also available as game template within the SDK.

    We also have a Camera component which is already available but not yet announced or documented because zooming is not fully implemented (but i guess you don’t need to zoom anyway). You can find its sources here: PathToYourV-PlaySDK\Desktop\V-PlaySDK\qml\VPlay\core\Camera.qml

    And another option for you, i made this short example for you to check out or even take as a base for your own platformer.

    main.qml

    import VPlay 1.0
    import QtQuick 1.1
    
    GameWindow {
      width: 320
      height: 480
      EntityManager {
        id: entityManager
        entityContainer: level
      }
      Scene {
        id: scene
        width: 320
        height: 480
        gridSize: 32
    
        PhysicsWorld {
          gravity.y: -10
          updatesPerSecondForPhysics: 60
          velocityIterations: 5
          positionIterations: 5
        }
    
        Item {
          id: level
          y: -player.y+scene.height/2
    
          Adventurer {
            id: player
            x: scene.gridSize*5
            y: scene.gridSize*8
          }
          Repeater {
            model: 20
            Block {
              x: scene.gridSize*5
              y: scene.gridSize*10-scene.gridSize*index*4
            }
          }
        }
    
        MultiTouchArea {
          anchors.fill: parent
          onClicked: {
            player.jump()
          }
          onSwipeUp: {
            player.superJump()
          }
        }
      }
    }

    Adventurer.qml

    import QtQuick 1.1
    import VPlay 1.0
    
    EntityBase {
      id: player
      entityType: "player"
    
      width: scene.gridSize-2
      height: scene.gridSize-2
    
      property alias collider: collider
    
      Rectangle {
        width: parent.width
        height: parent.height
        color: "red"
      }
    
      BoxCollider {
        id: collider
        anchors.fill: parent
        categories: Box.Category1
      }
    
      function jump() {
        var localForward = collider.body.getWorldVector(Qt.point(0,-300));
        collider.body.applyLinearImpulse(localForward, collider.body.getWorldCenter());
      }
    
      function superJump() {
        var localForward = collider.body.getWorldVector(Qt.point(0,-415));
        collider.body.applyLinearImpulse(localForward, collider.body.getWorldCenter());
      }
    }
    

    Block.qml

    import QtQuick 1.1
    import VPlay 1.0
    
    EntityBase {
      id: block
      entityType: "block"
    
      width: scene.gridSize
      height: scene.gridSize
    
      signal blockClicked
      signal blockDestroyed
    
      Rectangle {
        width: parent.width
        height: parent.height
        color: "blue"
      }
    
      BoxCollider {
        anchors.fill: parent
        bodyType: Body.Static
        // set this to true by default so the player can jump through blocks
        collisionTestingOnlyMode: true
        fixture.onBeginContact: {
          // if a block collides with a player, check if the player is above the block, in this case deactivate
          // the testing mode so the player stays on the block
          if(player.y <= block.y) collisionTestingOnlyMode = false
        }
    
        fixture.onEndContact: {
          // as soon as the player leaves the block we can switch to testing mode again
          collisionTestingOnlyMode = true
        }
      }
    }

     

    When you run this example, you can either click the screen to do a normal jump, or swipe up for a superjump. The player will always be centered in the screen and the level is moved accordingly to the players y-value with one simple property binding:

    Item {
      id: level
      y: -player.y+scene.height/2
      // ...
    }
    

    I hope this helps you :)

    Cheers,
    Alex

     

     

     

    #6070

    Caeser

    Thanx Alex!

    This is more help than I could ever ask for! I’m glad V-play supports this.

     

     

    #7983

    Diego

    I’m trying to execute this using V-Play 2.0, and i’m having the same issue that i was having in the game i’m developing.

    If you execute this in debug mode, you can see the box collider are not align with the Rectangles… Any idea why??

    Screenshot: https://dl.dropboxusercontent.com/u/19194639/vplay-bug.png

    #7984

    Alex
    V-Play Team

    Hi,

    in fact, only the debug draw is wrong, the colliders are in the right place, else the player would not land on the platforms. The reason for this is that the PhysicsWorld item is outside of the level, which is moving. What the Physicsworld does, is using the position of the physical bodys relative to their parent (level) and draw them, unfortunately, relative to itself (by default, the PhysicsWorld fills it’s parent, which is the scene). Now that the level is moving, but the physical bodys are not (at least not relative to their parent) they are drawn incorrect by the PhysicsWorld.

    It’s sometimes a little bit displeasing, that the debug draw is decoupled from the actual physics, as seen in this case…

    If you need correct debug draw, you need to put the PhysicsWorld inside the level item. Furthermore you will have to change the level itself a little bit because in this little demo, it has no actual width and height. We just make use of its 0|0 origin and add blocks and the player relative (as children) to it. Also we are placing the blocks in negative y-direction, which means just setting a height to the level item won’t do the job, because the item will then grow in positive y direction while the blocks are in fact in negative y-direction.

    Long story short, that’s not really a bug, instead my cloud-platform-centered-camera-example is quite poorly designed to work with the debug rendering of the PhysicsWorld :(

    I hope this explanation was good enough for you to implement it better than i did 😉

    Cheers,
    Alex

    • This reply was modified 4 years, 3 months ago by  Alex.
    • This reply was modified 4 years, 3 months ago by  Alex.
    • This reply was modified 4 years, 3 months ago by  Alex.
    • This reply was modified 4 years, 3 months ago by  Alex.
    #7989

    Diego

    Great explanation!

     

    Thanks!

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

RSS feed for this thread

You must be logged in to reply to this topic.

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