Hi,
I am developing an app in corona in which I want the images a sprite is alternating between to change according to the accelerometer. The sprite in question is a person running, so I want that person to turn left when the device is tilted left and to turn right when the device is tilted right. The images corresponding to the person facing right are the images 1 and 2 on the sprite sheet and facing left are images 3 and 4 on the sprite sheet. the code I already have for the sprite is the following:
local sheetData = require “gordinho110”
local spriteData = sheetData.getSpriteSheetData()
local spriteSheet = sprite.newSpriteSheetFromData (“gordinho110.png”, spriteData)
local spriteSet = sprite.newSpriteSet (spriteSheet, 1, 2)
sprite.add( spriteSet, “gordinho110”, 1, 2, 300, 0 ) – play 8 frames every 1000 ms
local aSprite = sprite.newSprite(spriteSet)
aSprite.x=screenW/2
aSprite.y=screenH*7.2/9
aSprite:prepare(“gordinho110”)
aSprite:play()
physics.addBody(aSprite)
aSprite.gravityScale=0
aSprite.myName=“john”
the code for switching the direction in which he’s moving is
local function urTiltFunc( event )
print (event.yGravity)
if event.yGravity>0.1 then
aSprite:setLinearVelocity(-180,0)
isStopping=1
fattySprite:play()
else
if event.yGravity<-0.1 then
aSprite:setLinearVelocity (180,0)
isStopping=1
else
currentFrame=3
aSprite:setLinearVelocity(0,0)
isStopping=0
end
end
end
Runtime:addEventListener( “accelerometer”, urTiltFunc )
How should I do that??
thanks!!!