Author Topic: CLEAN camera transitions x,y to x,y  (Read 1378 times)

0 Members and 1 Guest are viewing this topic.

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: CLEAN camera transitions x,y to x,y
« Reply #15 on: May 15, 2012, 06:53:54 PM »
I've just read through your code Aino, and pasted it straight into my level 1 copying everything (I've made a backup) and it starts, I had to take the globals out though cause it's different for iPad, when loading it up nothing happens, but then I added a few SetCameraTarget(10000,10000) just to test, but nothing happens....

I also changed the

Code: [Select]
CameraStart = {x = 0, y = 0};
to

Code: [Select]
CameraStart = {x = 10000, y = 0};
And it starts up at 0,0 It's got to be an iPad Limitation.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CLEAN camera transitions x,y to x,y
« Reply #16 on: May 16, 2012, 12:04:24 AM »
Code: [Select]
function LevelSetup()


-- some random globals..  can't remember what I all need...
Globals.G.Asteroids=(0)
Globals.G.EnemyFactionsMin=(0)
Globals.G.EnemyFactionsMax=(0)
Globals.G.MinAsteroidSeparation=500
Globals.G.MaxAsteroidNeighbourDist=3500
Globals.G.StartingSeedlings=(10)
Globals.G.GreysProbability=0

-- add some asteroids... a start roid
a = AddAsteroidWithAttribs(0,0, 1,1,1)
a.Name = "Start"
a.Owner = 1
s = a:AddDysonTree()

-- and a destination roid... we need some roids so we can
--  have some kind of fixed, known frame of reference to
-- test the transition effect..
a = AddAsteroidWithAttribs(2000,-1000, 1,1,1)
a.Name = "Destination"
a.Owner = 1
s = a:AddDysonTree()

end

function LevelLogic()

-- initialise variables
startTransition = true
p = 0
camX = GetCameraX()
camY = GetCameraY()

startX = camX
startY = camY
destX = 2000
destY = -1000

-- begin shenanigans

while GameRunning() do

-- Hallo !  Is this the start?  Are we transitioning ?
if startTransition then

-- if we are, start incrementing the counter...
p = p + 0.02

-- if we've reached the end of the transition..
if (p > 1) then

-- set p to a nice round 1, and flip the latch so the base conditional will no longer trigger.
p = 1
startTransition = false

end

-- time to set the camera distance.
-- camera position = start coordinate + ((destination coordinate - start coordinate) * the counter)
camX = startX + ((destX - startX) * p)
camY = startY + ((destY - startY) * p)

-- set the camera to the newly calculated coordinates
SetCameraPosition(camX, camY)

end
  
coroutine.yield()
end


end

Here is code for a complete working level with the screen transition thing.
Does this work for you?
« Last Edit: May 16, 2012, 12:17:43 AM by annikk.exe »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CLEAN camera transitions x,y to x,y
« Reply #17 on: May 16, 2012, 12:04:56 AM »
Also, get the basic one working first before you dive into the math.sin stuff !

On that, I've since found out that my assumption that the average Y value of the sine line where 0 < X < math.pi() is not 0.5... it's actually about 0.67 or something, or more accurately, 2 / math.pi().
So that means my code for the smoothed transition is wrong. :>  It will work kind of, but it will either overshoot the intended coordinates, or fall some way short.... I'm not quite sure which.  In any case, I will see about fixing that at some point...
« Last Edit: May 16, 2012, 12:07:58 AM by annikk.exe »

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: CLEAN camera transitions x,y to x,y
« Reply #18 on: May 16, 2012, 12:15:57 AM »
:O it works

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CLEAN camera transitions x,y to x,y
« Reply #19 on: May 16, 2012, 12:19:57 AM »
The problem I found with the code I copied largely verbatim from your original post, was that you wrote:

Code: [Select]
while gamerunning() do

instead of


Code: [Select]
while GameRunning() do


It turned out it didn't even favour the incorrect bracket precendence in the maths, so this was the only problem all along.

Nice thread it spawned though.. :>

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CLEAN camera transitions x,y to x,y
« Reply #20 on: May 16, 2012, 12:33:56 AM »
Code: [Select]
    camX = startX + (((destX - startX) / steps) * (math.sin(p) / (2 / math.pi())))
    camY = startY + (((destY - startY) / steps) * (math.sin(p) / (2 / math.pi())))


This... I think...  maybe..
It needs the other supporting code too I guess.

I try it :>

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: CLEAN camera transitions x,y to x,y
« Reply #21 on: May 16, 2012, 12:37:03 AM »
Just check this though, I don't just want one camera position, I want one, then something, then another.

Code: [Select]
-- initialise variables
    startTransition = true
    p = 0
    camX = GetCameraX()
    camY = GetCameraY()

    startX = camX
    startY = camY
    destX = 2000
    destY = -1000

WaitReal(3)
destX = 0
    destY = 0

the only thing I added to the whole file you added me was

Code: [Select]
WaitReal(3)
destX = 0
    destY = 0

and thats stopped the transition working, even for the first one.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CLEAN camera transitions x,y to x,y
« Reply #22 on: May 16, 2012, 12:40:41 AM »
Heh, doesn't work.

Back to conceptual stuff I guess.





Anyways...


Just check this though, I don't just want one camera position, I want one, then something, then another.

Code: [Select]
-- initialise variables
    startTransition = true
    p = 0
    camX = GetCameraX()
    camY = GetCameraY()

    startX = camX
    startY = camY
    destX = 2000
    destY = -1000

WaitReal(3)
destX = 0
    destY = 0

the only thing I added to the whole file you added me was

Code: [Select]
WaitReal(3)
destX = 0
    destY = 0

and thats stopped the transition working, even for the first one.

Because you haven't defined a function called WaitReal(), perhaps?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CLEAN camera transitions x,y to x,y
« Reply #23 on: May 16, 2012, 12:42:44 AM »
Add this in at the very very bottom of the level file:


Code: [Select]
function WaitReal(number)
MessageBox(number)
end


Then it will work, because the WaitReal function has been defined.  Not sure what you wanted it to do exactly, but currently it will produce a messagebox containing the number 3!

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: CLEAN camera transitions x,y to x,y
« Reply #24 on: May 16, 2012, 12:43:26 AM »
In the iOS version it's already defined in support.lua which defines many functions

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CLEAN camera transitions x,y to x,y
« Reply #25 on: May 16, 2012, 12:45:03 AM »
Never heard of it :>

I'd recommend testing the gametime instead to find out if it's time to transition or not.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CLEAN camera transitions x,y to x,y
« Reply #26 on: May 16, 2012, 12:48:06 AM »
For example:


Code: [Select]
function LevelSetup()


-- some random globals..  can't remember what I all need...
Globals.G.Asteroids=(0)
Globals.G.EnemyFactionsMin=(0)
Globals.G.EnemyFactionsMax=(0)
Globals.G.MinAsteroidSeparation=500
Globals.G.MaxAsteroidNeighbourDist=3500
Globals.G.StartingSeedlings=(10)
Globals.G.GreysProbability=0

-- add some asteroids... a start roid
a = AddAsteroidWithAttribs(0,0, 1,1,1)
a.Name = "Start"
a.Owner = 1
s = a:AddDysonTree()

-- and a destination roid... we need some roids so we can
--  have some kind of fixed, known frame of reference to
-- test the transition effect..
a = AddAsteroidWithAttribs(2000,-1000, 1,1,1)
a.Name = "Destination"
a.Owner = 1
s = a:AddDysonTree()

end

function LevelLogic()

-- initialise variables
    startTransition = true
    p = 0
    camX = GetCameraX()
    camY = GetCameraY()

    startX = camX
    startY = camY
    destX = 2000
    destY = -1000

-- begin shenanigans

while GameRunning() do


-- Hallo !  Is this the start?  Are we transitioning ?
if startTransition == true and GetGameTime() > 3 then

-- if we are, start incrementing the counter...
p = p + 0.02

-- if we've reached the end of the transition..
if (p > 1) then

-- set p to a nice round 1, and flip the latch so the base conditional will no longer trigger.
p = 1
startTransition = false

end

-- time to set the camera distance.
-- camera position = start coordinate + ((destination coordinate - start coordinate) * the counter)
camX = startX + ((destX - startX) * p)
camY = startY + ((destY - startY) * p)

-- set the camera to the newly calculated coordinates
SetCameraPosition(camX, camY)

   end
  
coroutine.yield()
    end


end

Again, fully working level.


The only change I needed to make was this line:

Code: [Select]
if startTransition then

I changed it to this:

Code: [Select]
if startTransition == true and GetGameTime() > 3 then

if startTransition and if startTransition == true are the same, I just prefer the latter because I think it's clearer. :>

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: CLEAN camera transitions x,y to x,y
« Reply #27 on: May 16, 2012, 12:55:52 AM »
WaitReal(1) would be wait 1 game time second

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CLEAN camera transitions x,y to x,y
« Reply #28 on: May 16, 2012, 11:52:21 AM »
Well you've told me that the level doesn't work if you use the WaitReal command, so as above, my suggestion is to find a different way to implement the delay. :>

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: CLEAN camera transitions x,y to x,y
« Reply #29 on: May 16, 2012, 01:00:21 PM »
What I'm going to do, is focus on getting the levels done, and then when there done ill do the extra sexy bits like this, Thanks Annikk!