Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. How to create board with block elements
Forum Updated to NodeBB v4.3 + New Features

How to create board with block elements

Scheduled Pinned Locked Moved Game Development
9 Posts 4 Posters 3.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AhWoon92
    wrote on last edited by
    #1

    I have the block elements but it wont appear on the screen.
    any reference or suggestion to it?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      My suggestion: Take some time to actually provide a description of a problem you are facing before posting on the internet about it.

      Seriously: What exactly are you trying to do? Do you have some code showing the issue? What exactly goes wrong? Do you get error messages/warnings whatever? What have you tried so far?

      1 Reply Last reply
      0
      • W Offline
        W Offline
        Wilk
        wrote on last edited by
        #3

        Hello
        I'll just leave "it":http://www.catb.org/~esr/faqs/smart-questions.html here

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AhWoon92
          wrote on last edited by
          #4

          i am trying to create a game like bejeweled. The problem i faced is i cannot product the random blocks on my game screen.
          For the time being, i am not sure how to create a board and able to generate the blocks.
          i have tried the references from the samegame.qml but is not working.
          i also tried using this way:

          @
          Timer
          {
          id:gameTimer

          onTriggered:
          {
              console.log("timer")
              var now=new Date();
              var block=now.getSeconds();
              var num=(Math.floor(10*Math.random(block)));
              switch(count)
              {
              case 0:
                  console.log("0")
                  angryblock.visible=true;
          
                  break;
              case 1:
                  console.log("1")
                  smileblock.visible=true;
                  break;
              case 2:
                  console.log("3")
                  sadblock.visible=true;
                  break;
              case 3:
                  console.log("4")
                  nerdblock.visible=true;
                  break;
              case 4:
                  console.log("5")
                  surpriseblock.visible=true;
                  break;
              case 5:
                  console.log("6")
                  bombblock.visible=true;
                  break;
              case 6:
                  console.log("7")
                  fireblock.visible=true;
                  break;
              case 7:
                  console.log("8")
                  freezeblock.visible=true;
                  break;
              case 8:
                  console.log("9")
                  waveblock.visible=true;
                  break;
              case 9:
                  console.log("10")
                  sunblock.visible=true;
                  break;
              }
          }
          

          }
          @

          but not working too.
          any better advice or suggestion? thanks

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tobias.hunger
            wrote on last edited by
            #5

            Please tag your code as such using '@' (or just highlight it with the mouse and click on the code icon at the top).

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mkfnx
              wrote on last edited by
              #6

              What part of the code from the same game example doesn't work? I think that you need to read again that tutorial in order to understand it better.

              As I remeber, an array was created to store references to block components that are dinamycally created.
              Once that the array is filled with references to valid components you can access to the property of each block component via the array indexes. For example:

              @BlockArray[index].x = someX
              BlockArray[index].y = someY@

              That's how they make it visible, by setting some x and y that was inside of the game canvas which can be a QML element like a rectangle (also by setting the background image as their parent).

              You aren't doing anything like that in the code that you posted, you are just setting the visible property to true (which is already true by default) to a bunch of elements that we cannot know what they're (from angryblock to sunblock).

              What are this elements? Rectangles? Images?
              Which element is their parent? How are you positioning them? Anchors? Absolute positioning? What are their coordinates?

              1 Reply Last reply
              0
              • A Offline
                A Offline
                AhWoon92
                wrote on last edited by
                #7

                T

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  AhWoon92
                  wrote on last edited by
                  #8

                  @
                  Timer//==================timer to move the block
                  {
                  id:gameTimer

                  onTriggered:
                  {
                      console.log("timer")
                      var now=new Date();
                      var block=now.getSeconds();
                      var num=(Math.floor(10*Math.random(block)));
                      switch(count)
                      {
                      case 0:
                          console.log("0")
                          angryblock.visible=true;
                  
                          break;
                      case 1:
                          console.log("1")
                          smileblock.visible=true;
                          break;
                      case 2:
                          console.log("3")
                          sadblock.visible=true;
                          break;
                      case 3:
                          console.log("4")
                          nerdblock.visible=true;
                          break;
                      case 4:
                          console.log("5")
                          surpriseblock.visible=true;
                          break;
                      case 5:
                          console.log("6")
                          bombblock.visible=true;
                          break;
                      case 6:
                          console.log("7")
                          fireblock.visible=true;
                          break;
                      case 7:
                          console.log("8")
                          freezeblock.visible=true;
                          break;
                      case 8:
                          console.log("9")
                          waveblock.visible=true;
                          break;
                      case 9:
                          console.log("10")
                          sunblock.visible=true;
                          break;
                      }
                  }
                  

                  }

                  Rectangle
                  {
                  id:gameboard
                  visible:false
                  width:360
                  height:640

                  Image
                  {
                      source: "Images/wallpaper/5.background.png"
                  }
                  //timer
                  

                  Rectangle{
                  Image//timer
                  {
                  id:timer
                  x:95
                  y:108
                  source:"Images/buttons/timerclock.png"
                  }
                  }
                  //score bar
                  Rectangle{
                  Image//score bar
                  {

                              id: scorebar
                              x:255
                              y:80
                              source: "Images/bar/scorebar_0%.png"
                          }
                     }
                  

                  //pause button
                  Rectangle{
                  Image//pause button
                  {
                  id:pausebutton

                          source:"Images/buttons/pause_btn.png"
                  
                  
                         x:4
                         y:108
                          MouseArea
                          {
                              anchors.fill: parent
                              onClicked:
                              {
                  
                                  pauseoptions.visible=true;
                  
                                  console.log("Pause")
                  
                              }
                          }
                      }
                  

                  }

                  Rectangle// pause menus
                  {
                          id:pauseoptions
                           visible:false
                          x:20
                          y:180
                  
                   Image
                  {
                     id:pausewall
                      source: "Images/wallpaper/6.pause2.png"
                  
                  
                  
                  Image//resume
                  {
                  id:resumebutton
                  x:100
                  y:90
                  
                  source: "Images/buttons/resume.png"
                  MouseArea
                  {
                      anchors.fill: parent
                      onClicked:
                      {
                          pauseoptions.visible=false
                          gameview.visible=true
                      }
                  }
                  }
                  
                  Image//restart
                  {
                      id:restart
                      x:100
                      y:140
                      source:"Images/buttons/restart.png"
                  }
                  Image//menu
                  {
                      id:mainmenubutton
                      x:85
                      y:190
                      source:"Images/buttons/mainmenu.png"
                      MouseArea
                      {
                          anchors.fill: parent
                          onClicked:
                          {
                              pauseoptions.visible=false
                              firstPage.visible=true
                          }
                      }
                  }
                  
                  }
                  
                      }
                  Rectangle//tile images
                  {
                      id:tile
                      Image
                      {
                          id:angryblock
                          source:"Images/tiles/angry.png"
                          visible:false
                  
                  
                      }
                      Image
                      {
                          id: sadblock
                          source: "Images/tiles/sad.png"
                          visible:false}
                      Image
                      {
                         id:surpriseblock
                         source:"Images/tiles/surprise.png"
                         visible:false
                      }
                      Image
                      {
                          id:smileblock
                          source:"Images/tiles/smile.png"
                          visible:false
                      }
                      Image
                      {
                          id:nerdblock
                          source:"Images/tiles/sad.png"
                          visible:false
                      }
                      Image
                      {
                          id:bombblock
                          source:"Images/tiles/bomb.png"
                          visible:false
                      }
                      Image
                      {
                          id:fireblock
                          source:"Images/tiles/fire.png"
                          visible:false
                      }
                      Image
                      {
                          id:sunblock
                          source:"Images/tiles/sun.png"
                          visible:false
                      }
                      Image
                      {
                          id:freezeblock
                          source:"Images/tiles/frozentimer.png"
                          visible:false
                      }
                      Image
                      {
                          id:waveblock
                          source:"Images/tiles/wave.png"
                          visible:false
                      }
                  
                  }
                  

                  }

                  @

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mkfnx
                    wrote on last edited by
                    #9

                    Well, I wasn't exactly asking for all of your code.

                    The forum's and the help that I, and most of the people, can offer is only for specific questions. But as I said to you before, I think that you need to read again the tutorial, and maybe try to do simple modifications to it (add more colors, change the score, etc.), so you can understand it better.

                    There are many things that you need to understand better. For example:

                    • You can only have one root element in a QML file, here you have two, a timer and a rectangle.
                    • You need to read about positioning elements in the screen. (Absolute Positioning, with x and y coordinates, "Positioning elements":http://doc.qt.nokia.com/4.7/qml-positioners.html and "anchors":http://doc.qt.nokia.com/4.7/qml-anchor-layout.html)
                    • Not everything needs to be inside a rectangle.
                    • You need to specify more properties to the timer in order to make it work (interval, running, repeat)

                    When you have read more about it,I'll be happy to help you with some specific doubt or problem.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved