Track Concept - Need Help.

I am wondering if anyone has an example of this because just the concept is driving me nuts thinking about it.

i would like to create a little sample game where an object moves around a track ( i guess similar to mario karts ) but I am not sure on how the mapping of the track would be done.

And how would you tell the sides of the squigley track incase the player ran off the road.

I have seen the tilt monster code but the app had no side boundries so it’s not really the same thing.

Any help would be greatly appericated.

Thanks

Larry M
DoubleSlashDesign.com [import]uid: 11860 topic_id: 12384 reply_id: 312384[/import]

Create an array of X and Y value for the path and animate the object through that path.

see the sample below.
click on different screen position to create array of path.
then click the text animate to animate the ball through the path.

[lua]local path = {}
local i =1;local j =1

local ball = display.newCircle( 50, 50, 15 )

local function traceClicks(event)
if event.phase == “ended” then
path[i] = {}
path[i].x = event.x
path[i].y = event.y
print(path[i].x)
i=i+1
end
end

– Move the player when we touch the screen
Runtime:addEventListener(“touch”, traceClicks)

local function move()
transition.to(ball, { time = 800; x= path[j].x; y=path[j].y})
j=j+1
end

local function moveObject(event)
timer.performWithDelay(1000, move, i)
end

local rect = display.newText( “Animate!”, 250, 250, nil, 24 )
rect:addEventListener(“touch”, moveObject)[/lua] [import]uid: 71210 topic_id: 12384 reply_id: 45168[/import]

One more sample.
this gives more smooth animation

[lua]local path = {}
local i =1;local j =1

local function traceClicks(event)
if event.phase == “moved” then
path[i] = {}
path[i].x = event.x
path[i].y = event.y
print(path[i].x)
i=i+1
end
end

Runtime:addEventListener(“touch”, traceClicks)

–create a circle ball
local ball = display.newCircle( 150, 150, 15 )
local animate
local posCount = 1
–moving the object – this is where animation takes place
local function moveObject(event)
if posCount <= #path then
ball.x = path[posCount].x
ball.y = path[posCount].y
posCount = posCount + 1
else
timer.cancel(animate)
end
end

– to move ball when we click the animate text
local function move()
posCount = 1
animate = timer.performWithDelay( 10, moveObject, #path )
end

–create a text which when clicked will animate the object
local text = display.newText( “Animate!”, 220, 50, nil, 40 )
text:addEventListener(“touch”, move)[/lua] [import]uid: 71210 topic_id: 12384 reply_id: 45169[/import]

Interesting little example, I will try this when I get home.

Thanks so much I’ll let you know how it goes.

Larry M
DoubleSlashDesign.com [import]uid: 11860 topic_id: 12384 reply_id: 45209[/import]