First, sorry. I was giving you a hard time because I wasn’t really sure what you were looking for.
Second, I’m still not, but let me take a stab.
For the sake of example, I will assume you have this situation:
-
Lily pads left-to-right: #1 --> #2 – > #3 – > #4 – > … – > N
-
A frog on the left side of the screen.
-
You allow users to tap a lily pad to get the frog to jump from where it is to that lily pad.
-
You want the frog to jump from #1 to #2 to #3 …
-
You don’t want a situation where people click too many lily pads too quickly and the frog jumps oddly. i.e If a user quickly tapped Lilly pad #2 then #3 (before the jump from #1 to #2 was done), the frog could jump right to #3 or move strangely and then move to #3.
-
You don’t want the player to be able to bypass a Lilly pad. i.e. If the frog is at #2, you don’t want to be able to jump right to #4. Only adjacent jumps should be allowed.
Am I missing any constraints, or have I imagined your situation incorrectly?
So, what does my code change do?
Well, assuming all Lilly pads call that same function and assuming that all Lilly pads have visibility to the isJumping variable, then the code I wrote will solve #5.
It won’t solve # 6. However, you can solve #6 by assigning all Lilly pads unique numbers and having your code check to see if that number is +/- 1 for the frogs current location. This is a simple solution for a linear case. It won’t work as easily for Lilly pads in a grid or if your jumping rule is distance based and not just adjacency based.
Note: If you do decide to use this idea for solving #6, do this:
-
When you create your Lily pads, do so left to right and assign them a number:
[lua]for i = 1, 5 do – create 5 pads
local pad = newPad() – Your code to create a pad
pad.myPadNumber = i
end[/lua]
-
Assign a number to the frog/player based on the pad it starts at: [lua]frog.atPad = 1[/lua]
-
Every time you jump to a new pad, assign that pads number to the frog (code marked w/ EFM)
[lua]local isJumping = false
local function padTouched(event)
local pad = event.target
if event.phase == “ended” then
if( isJumping ) then
return true
end
if( math.abs( myFrog.atPad - pad.myPadNumber ) > 1 ) – EFM Too far
return true
end
isJumping = true
local angleBetween = math.ceil( math.atan2( (pad.y - myFrog.y),
(pad.x - myFrog.x) ) * 180 / math.pi ) + 90
myFrog.rotation = angleBetween
myFrog:play()
myFrog.atPad = pad.myPadNumber --EFM ( change as jump starts )
transition.to ( myFrog, {
time=frogJumpSpeed,
x=pad.x,
y=pad.y,
transition=easing.inOutQuad,
onComplete = jumpComplete } )
end
end[/lua]
Again, sorry for the slight jibe in my last e-mail. Let me know if I missed the mark or if more clarification is needed
[import]uid: 110228 topic_id: 33314 reply_id: 132418[/import]