I really don’t see the need to delete and rebuild your objects and camera just to implement a pause feature in your game. So, I would go with the better way. One thing I would suggest to anyone starting a project is to learn how to use the – Select, Case, Endcase and Endselect commands.
This snippet is just a simple 2-D demo of circles moving around the screen. This same principle will work with 3-D and a pause menu as well.
#constant MAXOBJECTS 25
global kFlag as integer
randomize timer()
set text opaque
type t_Object
xPos as integer
yPos as integer
xDir as integer
yDir as integer
cRadius as integer
endtype
wWidth = screen width()
wHeight = screen height()
dim objCircle(MAXOBJECTS-1) as t_Object
for i=0 to MAXOBJECTS-1
objCircle(i).xPos = rnd(624)+8
objCircle(i).yPos = rnd(464)+8
objCircle(i).xDir = rnd(2)-1
objCircle(i).yDir = rnd(2)-1
objCircle(i).cRadius = rnd(4)+4
next i
sync on
sync rate 60
backdrop on
color backdrop 0
do
gosub DrawCircles
select paused
case 1:
gosub GamePaused
endcase
case default:
gosub UpdateCircles
endcase
endselect
gosub CircleInput
sync
loop
end
` SUBROUTINES
CircleInput:
if KeyBounce()=25
if paused=1
paused = 0
else
paused = 1
endif
endif
return
DrawCircles:
for i=0 to MAXOBJECTS-1
circle objCircle(i).xPos, objCircle(i).yPos, objCircle(i).cRadius
next i
return
GamePaused:
ink 0, -1
center text wWidth/2, wHeight/2-8, "Game Paused"
ink -1, 0
return
UpdateCircles:
for i=0 to MAXOBJECTS-1
if objCircle(i).xPos-objCircle(i).cRadius=<0 or objCircle(i).xPos+objCircle(i).cRadius=>wWidth
objCircle(i).xDir = objCircle(i).xDir*-1
endif
if objCircle(i).yPos-objCircle(i).cRadius=<0 or objCircle(i).yPos+objCircle(i).cRadius=>wHeight
objCircle(i).yDir = objCircle(i).yDir*-1
endif
objCircle(i).xPos = objCircle(i).xPos+objCircle(i).xDir
objCircle(i).yPos = objCircle(i).yPos+objCircle(i).yDir
next i
return
` FUNCTIONS
function KeyBounce()
key = scancode()
if key=kFlag
Value = 0
else
Value = key
kFlag = key
endif
endfunction Value
Edit: Press “p” to pause/resume.