If you are just wanting both scenes to share the same camera angles, you need to make the x# and y# variables global. I have rewritten your code in this snippet demonstrating this solution.
global g_StateFlag as integer
global g_OldKey as integer
global g_CamAngX as float
global g_CamAngY as float
gosub _Init
do
CamControl()
text 5,5, "PRESS SPACE TO ENTER TO CHANGE SCENE. PRESS ESC TO EXIT."
if (keystate(1))
g_StateFlag = 0
endif
select g_StateFlag
case 1:
Scene1()
endcase
case 2:
Scene2()
endcase
case default:
exit
endcase
endselect
sync
loop
end
_Init:
disable escapekey
sync on
sync rate 60
backdrop on
color backdrop 0
make object cube 1, 25
color object 1, 0xFFFF0000
make object cube 2, 25
color object 2, 0xFF0000FF
hide object 2
g_StateFlag = 1
return
function CamControl()
if (mouseclick()=2)
hide mouse
g_CamAngX = g_CamAngX+mousemovey()/1.5
g_CamAngY = g_CamAngY+mousemovex()/1.5
xrotate camera 0, g_CamAngX
yrotate camera 0, g_CamAngY
else
show mouse
mousemovey() = 0
mousemovex() = 0
endif
endfunction
function GetKey()
local Key as integer
Key = scancode()
if (Key=g_OldKey)
Key = 0
else
g_OldKey = Key
endif
endfunction Key
function Scene1()
if (GetKey()=57)
g_StateFlag = 2
hide object 1
show object 2
endif
endfunction
function Scene2()
if (GetKey()=57)
g_StateFlag = 1
hide object 2
show object 1
endif
endfunction
However, if you want to preserve the camera angles for each scene, you’ll need to store the camera angles for each scene globally. Something like this.
type t_CAMANG
x as float
y as float
z as float
endtype
dim g_CamAng(1) as t_CAMANG
global g_StateFlag as integer
global g_OldKey as integer
gosub _Init
do
CamControl()
text 5,5, "PRESS SPACE TO ENTER TO CHANGE SCENE. PRESS ESC TO EXIT."
if (keystate(1))
g_StateFlag = 0
endif
select g_StateFlag
case 1:
Scene1()
endcase
case 2:
Scene2()
endcase
case default:
exit
endcase
endselect
sync
loop
end
_Init:
disable escapekey
sync on
sync rate 60
backdrop on
color backdrop 0
make object cube 1, 25
color object 1, 0xFFFF0000
make object cube 2, 25
color object 2, 0xFF0000FF
hide object 2
for i=0 to 1
g_CamAng(i).x = camera angle x()
g_CamAng(i).y = camera angle y()
g_CamAng(i).x = camera angle z()
next i
g_StateFlag = 1
return
function CamControl()
if (mouseclick()=2)
hide mouse
g_CamAng(g_StateFlag-1).x = g_CamAng(g_StateFlag-1).x+mousemovey()/1.5
g_CamAng(g_StateFlag-1).y = g_CamAng(g_StateFlag-1).y+mousemovex()/1.5
xrotate camera 0, g_CamAng(g_StateFlag-1).x
yrotate camera 0, g_CamAng(g_StateFlag-1).y
else
show mouse
mousemovey() = 0
mousemovex() = 0
endif
endfunction
function GetKey()
local Key as integer
Key = scancode()
if (Key=g_OldKey)
Key = 0
else
g_OldKey = Key
endif
endfunction Key
function Scene1()
if (GetKey()=57)
g_StateFlag = 2
hide object 1
show object 2
rotate camera g_CamAng(g_StateFlag-1).x, g_CamAng(g_StateFlag-1).y, 0
endif
endfunction
function Scene2()
if (GetKey()=57)
g_StateFlag = 1
hide object 2
show object 1
rotate camera g_CamAng(g_StateFlag-1).x, g_CamAng(g_StateFlag-1).y, 0
endif
endfunction