Results 1 to 3 of 3

Thread: Two dynamically created object interaction issue

  1. #1
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Two dynamically created object interaction issue

    In my arkanoid like game I have bar and the ball which interacts with that bar, or rather which should interacts with the bar, because I have no idea how to deliver this.

    I create both ball and bar in the my js script and place them in specific location on the grid (which is an item defined in main.qml). But know I am facing the problem
    1. how to implement moving the ball with the bar at the same time if ball lies on the bar ? Currently bar is moved with drag.** properties set in Bar.qml, and it works great, because I can click and press the bar and it moves , but how to inform the ball object to move also but only if it knows it lies on the bar

    Qt Code:
    1. import QtQuick 1.0
    2. import "logic/barMechanics.js" as BAR_MECHANIC
    3.  
    4. Rectangle {
    5. id: bar
    6. smooth: true
    7. radius: 30
    8. opacity: 0.9
    9. gradient: Gradient {
    10. GradientStop { position: 0.0 ; color: "red"}
    11. GradientStop { position: 0.5 ; color: "yellow" }
    12. GradientStop { position: 1.0 ; color: "black"}
    13. }
    14.  
    15. signal clicked;
    16. property bool sticky: false //this property if true means that ball does not bounce from bar but gets atteched to it
    17.  
    18. MouseArea { //!!!! <--- CUSTOMIZE IT ---> !!!!//
    19. id: mouseArea
    20. anchors.fill: bar
    21. drag.target: bar
    22. drag.axis: Drag.XAxis
    23. drag.minimumX: 0
    24. drag.maximumX: bar.parent.width - bar.width + 10
    25.  
    26. onPressed: BAR_MECHANIC.barMoving(); //sets anchor to undefined
    27. }
    28. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. import QtQuick 1.0
    2.  
    3. ///there will be three possible bal (red,green,blue)
    4.  
    5. Item {
    6. id: bal
    7. property int type: 0
    8. property bool nitro: false //ball goes fast
    9. property bool destroyer: false //ball do not bounce from obstacles it goes throught them crushig em
    10. property bool onBar: false
    11.  
    12. //setting the bal colour
    13. Image {
    14. id: bal_colour
    15. anchors.fill: bal
    16. smooth: true
    17. source: {
    18. if(type == 0){
    19. return "resources/redBall.png";
    20. }else if (type == 1){
    21. return "resources/yellowBall.png";
    22. }else{
    23. return "resources/greenBall.png"
    24. }
    25. }
    26. }
    27. MouseArea {
    28. id: ballMouseArea
    29. anchors.fill: parent
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 

    any suggestion ? if any other code part is required let me know...
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

  2. #2
    Join Date
    May 2011
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Two dynamically created object interaction issue

    how to implement moving the ball with the bar at the same time if ball lies on the bar ?
    ...perhaps if you reparent it, and still moving only the Bar....

    Qt Code:
    1. Rectangle{
    2. id: main
    3. width: 640
    4. height: 400
    5. Bar {
    6. id: bar
    7. }
    8. Bal{
    9. id:bal
    10. onOnBarChanged:{
    11. if (onBar == true)
    12. {
    13. var position = mapToItem(bar, 0,0)
    14. bal.parent = bar
    15. bal.x = position.x
    16. bal.y = position.y
    17. }
    18. else {
    19. var position = mapToItem(main, 0,0)
    20. bal.parent = main
    21. bal.x = main.x
    22. bal.y = main.y
    23. }
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Two dynamically created object interaction issue

    I solved that by using anchoring which I previously had thought would had been impossible.
    The key to solve it was to set specific anchor to undefined.
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

Similar Threads

  1. Replies: 3
    Last Post: 11th August 2011, 17:16
  2. Dynamically created buttons.
    By Tomasz in forum Newbie
    Replies: 26
    Last Post: 2nd December 2010, 09:40
  3. PaintEvent() in a dynamically created and destroyed objet not working.
    By savaliya_ambani in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 20th October 2010, 08:49
  4. QMainWindow ignores dynamically created, floating QDockWidget
    By stefanadelbert in forum Qt Programming
    Replies: 1
    Last Post: 2nd March 2010, 01:06
  5. QtScript. How to add created object to script?
    By sergey_85 in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2010, 14:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.