×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    56

    image moving constantly - how?

    I tried in QML
    Code:
        while (image1.running = true) {
        image1.x=image1.x+2
        }
    but I get error
    file:///C:/Users/Arvis/game-build-simulator/qml/game/main.qml:28:11: Expected a qualified name id
    while (image1.running = true) {
    ^
    C:\Users\Arvis\game-build-simulator\debug\game.exe exited with code 0

    And the screen is just grey in simulator.
    Tried mainloop in javascript, but it takes no effect or hangs app if loop starts in the same time as app.

    So how can I move image1.x by 2 units every frame?

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: image moving constantly - how?

    In QML comparison operator is "==" the same as in C and C++.
    And you should use animation object
    http://doc.qt.nokia.com/latest/qml-animation.html

  3. #3
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    56

    Re: image moving constantly - how?

    Okay, I get it I can do it with animation, but is there any normal way of doing it? I mean with using while loop.

  4. #4
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: image moving constantly - how?

    QML is declarative language, while while loop is coming from imperative languages, thus, there is nothing abnormal.
    Last edited by divanov; 2011-03-20 at 19:02. Reason: typo

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Posts
    28

    Re: image moving constantly - how?

    If there's some specific need to avoid using animation elements, QML Timer element can be used:

    Code:
    Timer {
        interval: 20
        running: image1.running
        repeat: true
    
        onTriggered: {
            image1.x = image1.x+2;
        }
    }
    However, I cannot think of any use cases where you'd want to do it like this.

  6. #6
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    56

    Re: image moving constantly - how?

    Quote Originally Posted by Tomi_ View Post
    If there's some specific need to avoid using animation elements, QML Timer element can be used:

    Code:
    Timer {
        interval: 20
        running: image1.running
        repeat: true
    
        onTriggered: {
            image1.x = image1.x+2;
        }
    }
    However, I cannot think of any use cases where you'd want to do it like this.
    Yep, I figured it already and using it. Thanks anyway
    I only got function every time timer starts, so it acts like mainloop. The thing is I don't want to use it only for movement but for a lot of stuff, so that's just the way I like to do it.

  7. #7
    Super Contributor
    Join Date
    Jun 2006
    Location
    India
    Posts
    3,037

    Re: image moving constantly - how?

    property int index : 0

    Image {
    id: movingImage
    source: "test.png"
    x: index
    }

    NumberAnimation on index {
    from: 0
    to: 200
    duration: 1000
    loops: Animation.Infinite
    }

    this is implemented as number animation but there could be several ways to implement this.

Similar Threads

  1. Moving an image
    By purnima.attarsingh in forum Symbian
    Replies: 2
    Last Post: 2010-07-21, 09:41
  2. Image moving application
    By Anamika in forum Mobile Java General
    Replies: 3
    Last Post: 2010-05-28, 13:15
  3. Image moving application
    By Anamika in forum Mobile Java General
    Replies: 1
    Last Post: 2010-05-28, 08:19
  4. Moving Image on screen
    By er.nisha in forum Symbian User Interface
    Replies: 1
    Last Post: 2009-04-24, 05:40
  5. Moving Focus from one image to other image.
    By crazystar in forum Mobile Java General
    Replies: 3
    Last Post: 2007-09-25, 11:37

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •