PDA

View Full Version : Mobil roll



Viper666
4th December 2012, 15:05
Hi,
I make a program with aim and it move when i roll phone. I try this Sensor (http://www.developer.nokia.com/Community/Wiki/Implementing_custom_orientation_changes_animation_ with_QML) but i want roll about 45°.
Can someone help me?

wysota
4th December 2012, 16:29
What exactly is the problem?

Viper666
9th December 2012, 14:48
I have next problem i have two MouseArea, first is full background and second is only on one objeck but signals don't work now

wysota
9th December 2012, 21:56
Please define "don't work".

Viper666
10th December 2012, 14:07
onClicked:
{
console.log("this work")
}
I never see: "this work" :D

wysota
10th December 2012, 14:19
onClicked:
{
console.log("this work")
}
I never see: "this work" :D

This is not a valid QML file.

Viper666
10th December 2012, 19:09
i don't understand my code simple


import ...
Item {
id: background
MouseArea {
id: mouse
onPositionChanged: {
...
//something
...
}
}
Rectangle {
id: rect
MouseArea {
onClicked: { console.log("work") }//this is only test that it's work but it's never emit i never see "work"
}
}
}

wysota
10th December 2012, 19:14
The code above will make the MouseArea have null size thus you will never hit it.

Viper666
10th December 2012, 19:58
i forgot anchors.fill: parent but it it there in each mousearea

wysota
10th December 2012, 20:35
In that case your first mouse area overlaps with the second one and overrides it. Thus the first mouse area will work and the second one will not.

Viper666
10th December 2012, 21:21
ok i will make it else i have duck and i have own crosshair and shotbutton how can i do thath when you press shotbutton you will shot duck i can't use something like if(duck.x == aim.x && duck.y == aim.y) because i want full duck and not only one pixel?
Do you understand me sorry my English is horrible .

wysota
10th December 2012, 22:02
I don't understand what you mean. And it's not about the language, it's more about the content of your posts. You should really post a minimal complete example that demonstrates the problem.

Viper666
11th December 2012, 16:19
Ok i make a game first time. I want simple game you must shot duck. And i don't know how make it. When you shot how can i detect that you shot duck
i can't use if(click.y == duck.y && click.x == duck.x) because you never click on this one pixel. So how can i do that? My first idea: Duck { MouseArea { id: mouse; onClicked: { console.log("shot"); }} but this is wrong because i have a aim(crosshair) image

wysota
11th December 2012, 20:04
I'd have to see some real code to be able to comment on it. I don't know how the crosshair is related to the action of "shooting". Are you "aiming" by hovering mouse and "shooting" by clicking it?

Viper666
11th December 2012, 21:04
Are you "aiming" by hovering mouse and "shooting" by clicking it? Yes but now how detect that player shoot the duch?

wysota
11th December 2012, 21:44
Here is one possibility:

import QtQuick 1.1

Rectangle {
id: root
width: 360
height: 360

Rectangle {
property bool hit: false
id: duck
width: 50
height: width
radius: width/2
color: "red"
y: 60
NumberAnimation on x {
duration: 3000
from: 0
to: root.width
loops: NumberAnimation.Infinite
running: !duck.hit
}
NumberAnimation on y {
duration: 500
to: root.height
running: duck.hit
}
}

Rectangle {
id: crosshair
width: 40
height: width
border.color: "black"
border.width: 1
color: "transparent"
}

MouseArea {
id: aim
anchors.fill: parent
hoverEnabled: true
onPositionChanged: {
crosshair.x = mouse.x-crosshair.width/2
crosshair.y = mouse.y-crosshair.height/2
}
onClicked: {
if(mouse.x >= duck.x && mouse.x <= duck.x+duck.width && mouse.y >= duck.y && mouse.y <= duck.y+duck.height) {
duck.hit = true
}
}

}
}

Here is another:

import QtQuick 1.1

Rectangle {
id: root
width: 360
height: 360

Rectangle {
property bool hit: false
id: duck
width: 50
height: width
radius: width/2
color: "red"
y: 60
NumberAnimation on x {
duration: 3000
from: 0
to: root.width
loops: NumberAnimation.Infinite
running: !duck.hit
}
NumberAnimation on y {
duration: 500
to: root.height
running: duck.hit
}
MouseArea {
anchors.fill: parent
onClicked: duck.hit = true

}
}

Rectangle {
id: crosshair
width: 40
height: width
border.color: "black"
border.width: 1
color: "transparent"
}

MouseArea {
id: aim
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.NoButton
onPositionChanged: {
crosshair.x = mouse.x-crosshair.width/2
crosshair.y = mouse.y-crosshair.height/2
}

}
}

Viper666
12th December 2012, 13:14
i need this thanks