Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Question about the accelerometer
Started by werdinteractive Feb 22 2010 04:38 AM

- - - - -
1 reply to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

werdinteractive

[GLOBAL: userInfoPane.html]
werdinteractive
  • Enthusiast

  • 76 posts
  • Corona SDK

This code allows the user to shake the device to move a cube downward, but I would like to not need to shake the phone to get that functionality. The cube can be found in the site's sample code folders and can be tested in the simulator by changing the orientation of the displayed phone and hitting "command" and "up".
------ The Code

Holder = display.newImage( "cube01.png", 240, 240 )

local function shakeme(event)
Holder.y = Holder.y - event.yGravity
end

Runtime:addEventListener("accelerometer",shakeme)
uid: 4871 topic_id: 539 reply_id: 300539


[TOPIC: post.html]
#2

werdinteractive

[GLOBAL: userInfoPane.html]
werdinteractive
  • Enthusiast

  • 76 posts
  • Corona SDK


-- Fixed and posted for others

local Holder = display.newImage( "cube01.png", 240, 240 )
local Movement = 0

local function shakeme(event)
Movement = event.yGravity
end

local function onEnter(event)
Holder.y = Holder.y - Movement
end

Runtime:addEventListener("enterFrame",onEnter)
Runtime:addEventListener("accelerometer",shakeme)
uid: 4871 topic_id: 539 reply_id: 1043



[topic_controls]
[/topic_controls]