Created
April 15, 2021 15:58
-
-
Save S-Maxime/0026e80b4af488af4aa92e0ad7634043 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template> | |
| <Page :actionBarHidden="true"> | |
| <AbsoluteLayout height="100%" width="100%" backgroundColor="red"> | |
| <Image src="~/assets/back.jpg" stretch="fill" ref="back" | |
| id="back" /> | |
| <Image src="~/assets/perso.png" id="perso" ref="perso" /> | |
| <!--<StackLayout id="test" ref="perso" :top="tx" :left="ty"></StackLayout>--> | |
| </AbsoluteLayout> | |
| </Page> | |
| </template> | |
| <script lang="ts"> | |
| import { | |
| startAccelerometerUpdates | |
| } from 'nativescript-accelerometer' | |
| import { | |
| Screen | |
| } from '@nativescript/core' | |
| export default { | |
| mounted() { | |
| startAccelerometerUpdates((data: { | |
| x: number, | |
| y: number, | |
| z: number | |
| }) => { | |
| this.$refs.perso.nativeView.animate({ | |
| translate: { | |
| x: (data.x / Screen.mainScreen | |
| .scale) * 100, | |
| y: (data.y / Screen.mainScreen | |
| .scale) * 100 | |
| } | |
| }) | |
| this.$refs.back.nativeView.animate({ | |
| translate: { | |
| x: -((data.x / Screen.mainScreen | |
| .scale) * 50), | |
| y: -((data.y / Screen.mainScreen | |
| .scale) * 50) | |
| } | |
| }) | |
| }, { | |
| sensorDelay: 'ui' | |
| }) | |
| } | |
| } | |
| </script> | |
| <style> | |
| #back { | |
| width: 120%; | |
| height: 120%; | |
| top: 0; | |
| left: 0; | |
| } | |
| #perso { | |
| height: 70%; | |
| width: 70%; | |
| top: 280; | |
| left: 100; | |
| } | |
| /*#test { | |
| background: url("~/assets/perso.png") no-repeat; | |
| background-size: 440 850; | |
| top: 280; | |
| left: 90; | |
| height: 100%; | |
| width: 100%; | |
| }*/ | |
| </style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment