[solved] transition while dragging map

is it possible to make a transition while dragging the map?
if the object isn’t moving it’s easy only i haven’t figured out yet how i can do this with a moving object!
the object is already moving to some coordinates so it doesn’t help if i change the goal of the transition…

sorry for my bad english :wink:

thanks

[edit]
so i have to update the transition coordinates (while already moving)(this is imposible?) or i have to manipulate the x and y coordinates by dragging them with the map (don’t know if this is possible?)

in ghost vs monsters it look likes it’s done with the clouds in the background. does any one know how?
[edit2]
ohh it really gives me headache :frowning:
the ghost vs monsters app pauses the clouds so it’s not relevant for me…
i think i have to make a enterframe event? only that’s also the hard part because the coordinates of the object (ship1) transition are in an array (the route around the obstacles). Here’s the code, i hope you guys know how to fix this because i have no idea :’(

This is the array with the coordinates (newX and newY are the tile numbers (x:5,y:1 next array x:5,y:2 etc) and the xto are the new coordinates where to move to (tiles are 128x128 pixels).
[lua]path = CalcPath(CalcMoves(board, beginx, beginy, endx, endy))
for i = 1, table.getn(path) do
newX = path[i].x
newY = path[i].y
xto=(newX*128-64)-respectivelijkx
yto=(newY*128-64)-respectivelijky

transition.to(ship1, {delay = 500*(i-1),time=500, x=xto, y=yto });
end[/lua]

this is the code for the map dragging:
[lua]function map(event)
if(event.phase == “began”) then

display.getCurrentStage():setFocus (event.target)
nowx = event.x - spritemap.x
nowy = event.y - spritemap.y

nowship1x = event.x - ship1.x
nowship1y = event.y - ship1.y

print(nowship1x)
print(nowship1y)

elseif(event.phase == “moved”) then

previousX = event.x - nowx
previousY = event.y - nowy

previousship1X = event.x - nowship1x
previousship1Y = event.y - nowship1y

if ( previousX <= worldLimits.XMin and previousX >= adjustedXMax ) then spritemap.x = previousX;

ship1.x=previousship1X
respectivelijkx = -previousX
end

if ( previousY <= worldLimits.YMin and previousY >= adjustedYMax ) then spritemap.y = previousY;

ship1.y=previousship1Y
respectivelijky = -previousY
end

elseif(event.phase == “ended”) then
end
end[/lua] [import]uid: 18622 topic_id: 29381 reply_id: 329381[/import]

ok i changed the first part of code into:

[lua]moving=1
path = CalcPath(CalcMoves(board, beginx, beginy, endx, endy))
for i = 1, table.getn(path) do
endX = path[i].x
endY = path[i].y
end[/lua]

and made an enterFrame listener:

[lua]function moving(event)
if(moving==1) then
–endX and endY are the tile number x and tile number y of the goal

local endcoordinatesX = (endX*128-64)-respectivelijkx
local endcoordinatesY = (endY*128-64)-respectivelijky
local xi = 1;
local yi = 1;

print(eindX)
if((ship1.x-10)endcoordinatesX and (ship1.y-10)endcoordinatesY) then
moving = 0
print(“goal reached”)
else
if(path[xi] == endX) then
--reached point x
else
pathxcoordinates = (path[xi]*128-64)-respectivelijkx
if((ship1.x-10)pathxcoordinates) then
xi = xi + 1
else
if(pathxcoordinates < ship1.x) then
ship1.x = ship1.x - 5
elseif(pathxcoordinates > ship1.x) then
ship1.x = ship1.x + 5
end
end
end
end[/lua]

guess this is the way of dealing with the problem (enterFrame). Only now how to treat the movement?
i have to check if the path[i].x is equal to the endX and path[i].y == endY
if not i have to check if ship1.x (or y) are on the correct coordinates (of that tile (xi or yi)), and if so, the xi or yi must raise by 1 for the next tile coordinates. If the ship isn’t on the correct coordinates of the tile i have to check if the ship is left or right (or up or down) of the coordinates, and then the ship must move a view pixels in the correct way (and so on).

i hope my (not working) code will explain better what i tried to say.

i get this error:

test/main.lua:344: attempt to perform arithmetic on field ‘?’ (a table value)
stack traceback:

this is line 344: pathxcoordinates = (path[xi]*128-64)-respectivelijkx

can anyone tell me what i’m doing wrong or how i should handle this?
i haven’t add the ‘correction x and y’ coordinates (of the map dragging) yet because i wanted to test this first.

thanks [import]uid: 18622 topic_id: 29381 reply_id: 118220[/import]

ok this is my code so far:

[lua]function moving(event)
if(moving==1) then
–endX and endY are the tile number x and tile number y of the goal

if(xi==nil) then
xi = 1
endcoordinatesX = (endX*128-64)-respectivelijkx
endcoordinatesY = (endY*128-64)-respectivelijky

if(path[xi].x < endX) then last = (endX+1) end
if(path[xi].x > endX) then last = (endX-1) end
end

if(yi==nil) then y1 = 1 end

print(eindX)
if((ship1.x-10)endcoordinatesX and (ship1.y-10)endcoordinatesY) then
moving = 0
xi = nil
yi = nil
last = nil
print(“goal reached”)
else

print("last " … last)
--print("last 2 " … path[xi].x)

if(path[xi].x == last) then
--reached point x
moving = 0;

else
pathxcoordinates = (path[xi].x*128-64)-respectivelijkx

if((ship1.x-10)pathxcoordinates) then
xi = xi + 1
print(xi)
else
if(pathxcoordinates < ship1.x) then
ship1.x = ship1.x - 5

elseif(pathxcoordinates > ship1.x) then
ship1.x = ship1.x + 5
end
end
end
end
end
end[/lua]

it works until the ship reach its goal. then this error appears:

test/main.lua:359: attempt to index field ‘?’ (a nil value)
line 359: if(path[xi].x == last) then

what am i doing wrong?? :frowning: maybe it is because path[xi].x doesn’t exist (xi number is too high)??
[import]uid: 18622 topic_id: 29381 reply_id: 118366[/import]

I still can’t get it right! Does anyone know how to solve this? :wink: [import]uid: 18622 topic_id: 29381 reply_id: 120052[/import]

Great!:slight_smile: Thats exactly what i was trying to do! I’m going to test this tomorrow but if the group works like you said this isn’t a problem anymore :slight_smile: didn’t know it was that easy haha thank you!!:slight_smile: [import]uid: 18622 topic_id: 29381 reply_id: 120221[/import]

I still can’t get it right! Does anyone know how to solve this? :wink: [import]uid: 18622 topic_id: 29381 reply_id: 120052[/import]

Great!:slight_smile: Thats exactly what i was trying to do! I’m going to test this tomorrow but if the group works like you said this isn’t a problem anymore :slight_smile: didn’t know it was that easy haha thank you!!:slight_smile: [import]uid: 18622 topic_id: 29381 reply_id: 120221[/import]

late reaction, was busy with school.

it works only the display group has only the size of the device. So if you move the map, you will drag the displaygroup away and because the group is to small, the ship will not go further than the border of the display group. i hope you understand what i mean?

i have to make the displaygroup the size of the map, only haven’t find a solution for that yet. (but i’m searching for it). [import]uid: 18622 topic_id: 29381 reply_id: 121821[/import]

Allright its fixed now. Had to change the relative positions in the movement and it works fine now!
So topic solved:) thanks very much!! [import]uid: 18622 topic_id: 29381 reply_id: 121872[/import]

late reaction, was busy with school.

it works only the display group has only the size of the device. So if you move the map, you will drag the displaygroup away and because the group is to small, the ship will not go further than the border of the display group. i hope you understand what i mean?

i have to make the displaygroup the size of the map, only haven’t find a solution for that yet. (but i’m searching for it). [import]uid: 18622 topic_id: 29381 reply_id: 121821[/import]

Allright its fixed now. Had to change the relative positions in the movement and it works fine now!
So topic solved:) thanks very much!! [import]uid: 18622 topic_id: 29381 reply_id: 121872[/import]

wouter,

I may be misunderstanding your goal, but if you want to have objects in a scene which are moving, transitioning, etc. AND if you simultaneously want to move those objects around (as if you are dragging your camera view around the world), simply do this:

  1. Create a group
 local myGroup = display.newGroup()  
  1. Create your content as per usual, except insert it into the group you previously created:

-- create ship 1 as per usual -- <your code here><br><br> -- Insert ship into group<br> myGroup:insert(ship1)<br>

3. Later, when you want to ‘drag the map’, simply move the group by changing its coordinates.
<br> myGroup.x = myGroup.x + 10 -- Move group (and all objects in it 10 pixels to right)<br>

– This will move all of the objects in the group, but not affect their transitions etc.
– The transition changes are all relative to the local coordinate space provided by the group.
– The final rendering will be a composite of object position in its group + the group position relative to screen space.

Hopefully this isn’t too confusing.

Cheers,
Ed M.
[import]uid: 110228 topic_id: 29381 reply_id: 120105[/import]

wouter,

I may be misunderstanding your goal, but if you want to have objects in a scene which are moving, transitioning, etc. AND if you simultaneously want to move those objects around (as if you are dragging your camera view around the world), simply do this:

  1. Create a group
 local myGroup = display.newGroup()  
  1. Create your content as per usual, except insert it into the group you previously created:

-- create ship 1 as per usual -- <your code here><br><br> -- Insert ship into group<br> myGroup:insert(ship1)<br>

3. Later, when you want to ‘drag the map’, simply move the group by changing its coordinates.
<br> myGroup.x = myGroup.x + 10 -- Move group (and all objects in it 10 pixels to right)<br>

– This will move all of the objects in the group, but not affect their transitions etc.
– The transition changes are all relative to the local coordinate space provided by the group.
– The final rendering will be a composite of object position in its group + the group position relative to screen space.

Hopefully this isn’t too confusing.

Cheers,
Ed M.
[import]uid: 110228 topic_id: 29381 reply_id: 120105[/import]