Forums

OverviewV-Play 1 Support › Show only a section of a level

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #4317

    Thomas

    Hi  @all.

     

    I want to create a little game, where an object can move freely in space.

    Now i want to create a big Level, and when playing, on the screen, only a small section of the level should be shown. And this section should moce according to the objects position in the level.

    Is this somehow possible at the moment.

    i was thinking of a scene inside a scene? one scene is the big level, the other just the cut-out, where the moving object is centered..

     

    cheers,

    TS

    #4322

    Christian
    V-Play Team

    Hi,

    the easiest way to do this, is by moving the Level inside the scene. The level would be of a bigger size and is a child of the Scene, and it contains all game entities. By moving the Level then, you adjust the visible portion of the Scene. This is the same approach we are using for our Chicken Outbreak demo, where we move the level endlessly to the top, which has the visual effect of all objects going down. You can test that with the following example code:

    GameWindow {
        Scene {
          width: 480
          height: 320
           
          Level {
            // make the Level any size, only the 480x320 section will be visible though
            width: 4000
            height: 3000
            
            Rectangle {
              width: 50; height: 30
            }
            
            Rectangle {
              x: 300
              width: 50; height: 30
            }
            
            Rectangle {
              x: 600
              width: 50; height: 30
            }
            
            // this will move the level from its original x position 0 to -800, which will have the effect of the Rectangles moving right
            // instead of this NumberAnimation, you can set the position of your level to whatever you want your visible part to be
            NumberAnimation on x {
              from: 0
              to: -800
              duration: 3000          
            }
            
          }// Level
        }// Scene
      }// GameWindow

     

    The Level item is just a normal QML Item element, but if you design multiple levels you will probably put that file into an own qml file and name it Level01, Level02, etc.

    Cheers, Chris

    #4325

    Thomas

    thank you very much. i knew i was on the right track. that did it for me..

     

    another problem: how to keep my object in the center of my scene while moving it through the level?

    at the moment i have something like this:

    GameWindow {
    activeScene: scene
    width: 960
    height: 640
    id: gameWindow
    Scene {
    id: scene
    width: 480
    height: 320
    x: 480 - level.space_ship.x * 2
    y: 320 - level.space_ship.y * 2
    Level {
    id: level
    width: gameWindow.width
    height: gameWindow.height
    }
    }
    }

    what i do here is to scale the movement of the object to the scaling factor, in this case 2.

    this is a problem when it comes to other screensizes.

    is there a better way to handle this?

     

    thanks again!

    cheers,

    TS

    #4330

    Christian
    V-Play Team

    Hi,

    please do not move the Scene, but the Level as I have written above. Otherwise you get problems with different screen sizes, and you cannot position any GUI elements that should remain the same position in you Scene. To simplify the movement within larger scenes, we are working on a Camera item, which will probably make it into version 1.4. If you want to upvote its implementation, please add it to the Roadmap forum post here: https://v-play.net/developers/forums/t/v-play-roadmap/

    If you want to keep the player in the center of the screen, you should move the level by the position of the player + the half of the scene size to make it centered.

    Cheers, Chris

    #4341

    Thomas

    hey!

    thanks again for the advice to move the level! i think i overread that before. Now everything works just perfectly fine. Even on other displaysizes!

    but i think, that a camera item is useful tough, so i will upvote it.

     

    Cheers,

    TS

Viewing 5 posts - 1 through 5 (of 5 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