May 12, 2012

AhWoon92 AhWoon92
Lab Rat
10 posts

How to create board with block elements

 

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

8 replies

May 12, 2012

Tobias Hunger Tobias Hunger
Mad Scientist
3224 posts

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?

May 12, 2012

Wilk Wilk
Ant Farmer
120 posts

Hello
I’ll just leave it [catb.org] here

May 12, 2012

AhWoon92 AhWoon92
Lab Rat
10 posts

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:

  1. Timer
  2. {
  3.     id:gameTimer
  4.  
  5.     onTriggered:
  6.     {
  7.         console.log("timer")
  8.         var now=new Date();
  9.         var block=now.getSeconds();
  10.         var num=(Math.floor(10*Math.random(block)));
  11.         switch(count)
  12.         {
  13.         case 0:
  14.             console.log("0")
  15.             angryblock.visible=true;
  16.  
  17.             break;
  18.         case 1:
  19.             console.log("1")
  20.             smileblock.visible=true;
  21.             break;
  22.         case 2:
  23.             console.log("3")
  24.             sadblock.visible=true;
  25.             break;
  26.         case 3:
  27.             console.log("4")
  28.             nerdblock.visible=true;
  29.             break;
  30.         case 4:
  31.             console.log("5")
  32.             surpriseblock.visible=true;
  33.             break;
  34.         case 5:
  35.             console.log("6")
  36.             bombblock.visible=true;
  37.             break;
  38.         case 6:
  39.             console.log("7")
  40.             fireblock.visible=true;
  41.             break;
  42.         case 7:
  43.             console.log("8")
  44.             freezeblock.visible=true;
  45.             break;
  46.         case 8:
  47.             console.log("9")
  48.             waveblock.visible=true;
  49.             break;
  50.         case 9:
  51.             console.log("10")
  52.             sunblock.visible=true;
  53.             break;
  54.         }
  55.     }
  56. }

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

May 12, 2012

Tobias Hunger Tobias Hunger
Mad Scientist
3224 posts

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

May 14, 2012

mkfnx mkfnx
Lab Rat
31 posts

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:

  1. BlockArray[index].x = someX
  2. 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?

May 14, 2012

AhWoon92 AhWoon92
Lab Rat
10 posts

T

May 14, 2012

AhWoon92 AhWoon92
Lab Rat
10 posts

  1. Timer//==================timer to move the block
  2. {
  3.     id:gameTimer
  4.  
  5.     onTriggered:
  6.     {
  7.         console.log("timer")
  8.         var now=new Date();
  9.         var block=now.getSeconds();
  10.         var num=(Math.floor(10*Math.random(block)));
  11.         switch(count)
  12.         {
  13.         case 0:
  14.             console.log("0")
  15.             angryblock.visible=true;
  16.  
  17.             break;
  18.         case 1:
  19.             console.log("1")
  20.             smileblock.visible=true;
  21.             break;
  22.         case 2:
  23.             console.log("3")
  24.             sadblock.visible=true;
  25.             break;
  26.         case 3:
  27.             console.log("4")
  28.             nerdblock.visible=true;
  29.             break;
  30.         case 4:
  31.             console.log("5")
  32.             surpriseblock.visible=true;
  33.             break;
  34.         case 5:
  35.             console.log("6")
  36.             bombblock.visible=true;
  37.             break;
  38.         case 6:
  39.             console.log("7")
  40.             fireblock.visible=true;
  41.             break;
  42.         case 7:
  43.             console.log("8")
  44.             freezeblock.visible=true;
  45.             break;
  46.         case 8:
  47.             console.log("9")
  48.             waveblock.visible=true;
  49.             break;
  50.         case 9:
  51.             console.log("10")
  52.             sunblock.visible=true;
  53.             break;
  54.         }
  55.     }
  56. }
  57.  
  58. Rectangle
  59. {
  60.     id:gameboard
  61.     visible:false
  62.     width:360
  63.     height:640
  64.  
  65.  
  66.     Image
  67.     {
  68.         source: "Images/wallpaper/5.background.png"
  69.     }
  70.     //timer
  71. Rectangle{
  72.     Image//timer
  73.         {
  74.             id:timer
  75.             x:95
  76.             y:108
  77.             source:"Images/buttons/timerclock.png"
  78.         }
  79. }
  80. //score bar
  81. Rectangle{
  82. Image//score bar
  83.  {
  84.  
  85.                 id: scorebar
  86.                 x:255
  87.                 y:80
  88.                 source: "Images/bar/scorebar_0%.png"
  89.             }
  90.        }
  91. //pause button
  92. Rectangle{
  93. Image//pause button
  94.         {
  95.             id:pausebutton
  96.  
  97.             source:"Images/buttons/pause_btn.png"
  98.  
  99.  
  100.            x:4
  101.            y:108
  102.             MouseArea
  103.             {
  104.                 anchors.fill: parent
  105.                 onClicked:
  106.                 {
  107.  
  108.                     pauseoptions.visible=true;
  109.  
  110.                     console.log("Pause")
  111.  
  112.                 }
  113.             }
  114.         }
  115. }
  116.  
  117.  
  118.     Rectangle// pause menus
  119.     {
  120.             id:pauseoptions
  121.              visible:false
  122.             x:20
  123.             y:180
  124.  
  125.      Image
  126.     {
  127.        id:pausewall
  128.         source: "Images/wallpaper/6.pause2.png"
  129.  
  130.  
  131.  
  132.     Image//resume
  133.     {
  134.     id:resumebutton
  135.     x:100
  136.     y:90
  137.  
  138.     source: "Images/buttons/resume.png"
  139.     MouseArea
  140.     {
  141.         anchors.fill: parent
  142.         onClicked:
  143.         {
  144.             pauseoptions.visible=false
  145.             gameview.visible=true
  146.         }
  147.     }
  148.     }
  149.  
  150.     Image//restart
  151.     {
  152.         id:restart
  153.         x:100
  154.         y:140
  155.         source:"Images/buttons/restart.png"
  156.     }
  157.     Image//menu
  158.     {
  159.         id:mainmenubutton
  160.         x:85
  161.         y:190
  162.         source:"Images/buttons/mainmenu.png"
  163.         MouseArea
  164.         {
  165.             anchors.fill: parent
  166.             onClicked:
  167.             {
  168.                 pauseoptions.visible=false
  169.                 firstPage.visible=true
  170.             }
  171.         }
  172.     }
  173.  
  174.     }
  175.  
  176.         }
  177.     Rectangle//tile images
  178.     {
  179.         id:tile
  180.         Image
  181.         {
  182.             id:angryblock
  183.             source:"Images/tiles/angry.png"
  184.             visible:false
  185.  
  186.  
  187.         }
  188.         Image
  189.         {
  190.             id: sadblock
  191.             source: "Images/tiles/sad.png"
  192.             visible:false}
  193.         Image
  194.         {
  195.            id:surpriseblock
  196.            source:"Images/tiles/surprise.png"
  197.            visible:false
  198.         }
  199.         Image
  200.         {
  201.             id:smileblock
  202.             source:"Images/tiles/smile.png"
  203.             visible:false
  204.         }
  205.         Image
  206.         {
  207.             id:nerdblock
  208.             source:"Images/tiles/sad.png"
  209.             visible:false
  210.         }
  211.         Image
  212.         {
  213.             id:bombblock
  214.             source:"Images/tiles/bomb.png"
  215.             visible:false
  216.         }
  217.         Image
  218.         {
  219.             id:fireblock
  220.             source:"Images/tiles/fire.png"
  221.             visible:false
  222.         }
  223.         Image
  224.         {
  225.             id:sunblock
  226.             source:"Images/tiles/sun.png"
  227.             visible:false
  228.         }
  229.         Image
  230.         {
  231.             id:freezeblock
  232.             source:"Images/tiles/frozentimer.png"
  233.             visible:false
  234.         }
  235.         Image
  236.         {
  237.             id:waveblock
  238.             source:"Images/tiles/wave.png"
  239.             visible:false
  240.         }
  241.  
  242.     }
  243.  
  244. }

May 14, 2012

mkfnx mkfnx
Lab Rat
31 posts

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 [doc.qt.nokia.com] and anchors [doc.qt.nokia.com])
  • 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.

 
  ‹‹ how to use joystick in Qt?      Stuck in loading page For Game ››

You must log in to post a reply. Not a member yet? Register here!