Hi Corona world,
I want to build some game but I am stuck in some where.
My requirement is I have a bike. This bike is build by 3 different sprites.
I am able to show the sprite properly. Now i want to tilt the the object on tilt of the object should move left or right. Which I am able to do. But my huddle is I am not able to do the animation based upon the tilt direction. Means if I tilt in left the bike should show some sequence. If I turn the bike on right then it should show the alternative animation sequence.
My issue is I am not able to show different animation sequence of tilt.
Please help me. I am stuck with this issue for more then 3 days.
Please help me.
The code is given below:
I have defined the sequence out side the main:
– Sequence data defines the different sequences
local sequenceData = {
– { name = “normalRun”, start=1, count=6, time=800, loopCount=10 }, --add loopCount=4
{ name = “normalRun”, start=2, count=1, time=250, loopCount=1 }, --add loopCount=4
{ name = “midToleftRun”, frames={ 2,1 }, time=250 },
{ name = “midTorightRun”, frames={ 2,3 }, time=250 }
}
This is below the sprite definition:
local sheetData = { width=55, height=90, numFrames=3, sheetContentWidth=165, sheetContentHeight=90 }
--Initializing the sprites
local mySheet = graphics.newImageSheet( “assets/images/static/anim_auto.png”, sheetData )
– Basic animation variable for view
animation = display.newSprite( mySheet, sequenceData )
– animation.gravityScale = 0
--Placing the animation on the view
animation.x = display.contentWidth/2 --center the sprite horizontally
animation.y = display.contentHeight/2 --center the sprite vertically
--Start the animation
animation:play()
My tilt function:
local onTilt = function( event )
local prevAnimX = animation.x;
local newTiltY = animation.x + (animTiltSpeed * event.xGravity);
if prevAnimX < newTiltY then
myToast = toast.new(“Right”, 1000)
animation:setSequence( “midTorightRun” )
elseif prevAnimX > newTiltY then
myToast = toast.new(“Left”, 1000)
animation:setSequence( “midToleftRun” )
else
--BASE CASE EMPTY
end
animation.x = animation.x + (animTiltSpeed * event.xGravity)
end
PLease help me…