- Dav
Edit: Now has 6 functions
Code: Select all
'=====================
'ScreenTransitions.txt
'=====================
'Screen transitions using fullscreen sprites.
'Swaps two fullscreen sprites in interesting ways.
'Can be used for screen transitions in games.
'Coded by Dav, JUNE/2015
'
'SUMMARY OF SCREEN FUNTIONS:
'
'ScreenSwap - One image overlaps another one.
' (left,right,up,down)
'ScreenPush - One image pushs another off screen.
'. (left,right,up,down)
'ScreenZoom - One image zooms in/out over another.
'. (in,out, optional spin)
'ScreenDrop - One image drops in/out over another.
'. (in,out)
'ScreenFade - One images fades in/out over another.
' (in,out)
'ScreenSpin - Spins one image around.
'===================================================
graphics
'=== functions use these variables...
sw=screen_width()!sh=screen_height()
'=== make 4 example sprites to use
refresh off
shadow on
for s=1 to 4
if s=1 then graphics clear 1,0,0
if s=2 then graphics clear 0,0,1
if s=3 then graphics clear 0,1,0
if s=4 then graphics clear 1,1,0
'draw lines
draw size 1
for y=0 to screen_height() step 8
draw color .4,.4,0
draw line 0,y to screen_width(),y
next y
'draw screen numbers
for t= 1 to 50
c=rnd(255)/255
draw color c,c,c
draw font size 50+rnd(100)
x=rnd(sw)!y=rnd(sh)
draw text str$(s) at x,y
next t
draw size 20
draw rect 1,1 to sw,sh
sprite str$(s) scan 0,0,sw,sh
sprite str$(s) at -2000,-2000
sprite str$(s) show
next s
graphics clear 0,0,0
refresh on
'=== show all the screen transitions
do
ScreenSwap("LEFT", "1", "2", .02)!pause .2
ScreenSwap("RIGHT", "2", "3", .02)!pause .2
ScreenSwap("DOWN", "3", "4", .02)!pause .2
ScreenSwap("UP", "4", "1", .02)!pause .2
ScreenPush("LEFT", "1", "2", .01)!pause .2
ScreenPush("RIGHT", "2", "1", .01)!pause .2
ScreenPush("DOWN", "1", "2", .01)!pause .2
ScreenPush("UP", "2", "1", .01)!pause .2
'zoom, no spin
ScreenZoom("IN","1","2",0,.01)!pause .2
ScreenZoom("OUT","1","2",0,.01)!pause .2
'zoom, spin also...
ScreenZoom("IN","1","3",1,.01)!pause .2
ScreenZoom("OUT","1","3",1,.01)!pause .2
ScreenDrop("IN", "1","4",.02)!pause .2
ScreenDrop("OUT", "4","1",.02)!pause .2
ScreenFade("1","3",.02)!pause .2
ScreenFade("3","1",.02)!pause .2
ScreenSpin("1",.02) 'slow
ScreenSpin("1",.01) 'fast
until forever
END
DEF ScreenSwap (way$, img1$, img2$, delay)
sprite img1$ order 1
sprite img2$ order 0
if capstr$(way$)= "LEFT" then
x2 = 0
FOR x = 0 TO .sw / 2 STEP 15
sprite img2$ at x2, 0
sprite img1$ at x,0
x2 = x2 - 15
pause delay
NEXT x
sprite img1$ order 0
sprite img2$ order 1
x2 = 0 - (.sw / 2)
FOR x = .sw / 2 TO 0 STEP -15
sprite img1$ at x,0
sprite img2$ at x2,0
x2 = x2 + 15
pause delay
NEXT x
sprite img2$ at 0,0
end if
if capstr$(way$)= "RIGHT" then
x2 = 0
FOR x = 0 TO -(.sw / 2) STEP -15
sprite img2$ at x2,0
sprite img1$ at x,0
x2 = x2 + 15
pause delay
NEXT x
sprite img1$ order 0
sprite img2$ order 1
x2 = .sw / 2
FOR x = 0 - (.sw / 2) TO 0 STEP 15
sprite img1$ at x,0
sprite img2$ at x2,0
x2 = x2 - 15
pause delay
NEXT x
sprite img2$ at 0,0
end if
if capstr$(way$) = "DOWN" then
y2 = 0
FOR y = 0 TO (.sh / 2) STEP 15
sprite img2$ at 0,y2
sprite img1$ at 0,y
y2 = y2 - 15
pause delay
NEXT y
sprite img1$ order 0
sprite img2$ order 1
y2 = 0 - (.sh / 2)
FOR y = (.sh / 2) TO 0 STEP -15
sprite img1$ at 0,y
sprite img2$ at 0,y2
y2 = y2 + 15!
pause delay
NEXT y
sprite img2$ at 0,0
end if
if capstr$(way$) = "UP" then
y2 = 0
FOR y = 0 TO 0 - (.sh / 2) STEP -15
sprite img2$ at 0,y2
sprite img1$ at 0,y
y2 = y2 + 15
pause delay
NEXT y
sprite img1$ order 0
sprite img2$ order 1
y2 = (.sh / 2)
FOR y = 0 - (.sh / 2) TO 0 STEP 15
sprite img1$ at 0,y
sprite img2$ at 0,y2
y2 = y2 - 15
pause delay
NEXT y
sprite img2$ at 0,0
end if
end def
def ScreenPush(way$, img1$, img2$, delay)
sprite img1$ order 1
sprite img2$ order 0
if capstr$(way$)= "LEFT" then
x2 = .sw
FOR x = 0 TO -(.sw) STEP -15
sprite img2$ at x2, 0
sprite img1$ at x,0
x2 = x2 - 15
pause delay
NEXT x
sprite img2$ at 0,0
end if
if capstr$(way$)= "RIGHT" then
x2 = -(.sw)
FOR x = 0 TO .sw STEP 15
sprite img2$ at x2, 0
sprite img1$ at x,0
x2 = x2 + 15
pause delay
NEXT x
sprite img2$ at 0,0
end if
if capstr$(way$) = "DOWN" then
y2 = -(.sh)
FOR y = 0 TO .sh STEP 15
sprite img2$ at 0,y2
sprite img1$ at 0,y
y2 = y2 + 15
pause delay
NEXT y
sprite img2$ at 0,0
end if
if capstr$(way$) = "UP" then
y2 = .sh
FOR y = 0 TO -(.sh) STEP -15
sprite img2$ at 0,y2
sprite img1$ at 0,y
y2 = y2 - 15
pause delay
NEXT y
sprite img2$ at 0,0
end if
end def
def ScreenZoom(way$, img1$, img2$, spin, delay)
if capstr$(way$)="IN" then
sprite img2$ alpha 0
end if
sprite img1$ order 0
sprite img2$ order 1
if capstr$(way$)="IN" then
x=100
for t = 0 to 100
sprite img2$ alpha t/100
if spin=1 then
sprite img2$ at x,x scale t/100 angle x/15
else
sprite img2$ at x,x scale t/100
end if
x=x-1! pause delay
next t
end if
if capstr$(way$)="OUT" then
for t = 100 to 0 step -1
sprite img2$ alpha t/100
if spin=1 then
sprite img2$ at x,x scale t/100 angle x/15
else
sprite img2$ at x,x scale t/100
end if
x=x+1!pause delay
next t
'reorder
sprite img1$ order 1
sprite img2$ order 0
'restore changed sprite
sprite img2$ alpha 1
sprite img2$ at 0,0 scale 1
end if
end def
def ScreenDrop(way$, img1$, img2$, delay)
if capstr$(way$)="IN" then
sprite img2$ alpha 0
sprite img1$ order 0
sprite img2$ order 1
x=1000!alp=0
for t = 1000 to 100 step -15
sprite img2$ alpha alp/100
sprite img2$ at x-t,x-t scale t/100
pause delay ! x=x-15
alp=alp+5
next t
end if
if capstr$(way$)="OUT" then
sprite img1$ order 1
sprite img2$ order 0
x=0!alp=100
for t = 100 to 1000 step 15
sprite img1$ at x+t-100,x+t-100 scale t/100
'start fading out
if t > 500 then
sprite img1$ alpha alp/100
alp=alp-5
end if
pause delay ! x=x-15
next t
'reorder
sprite img1$ order 0
sprite img2$ order 1
'restore changed sprite
sprite img1$ alpha 1
sprite img1$ at 0,0 scale 1
end if
end def
def ScreenFade(img1$, img2$, delay)
sprite img2$ alpha 0
sprite img1$ order 0
sprite img2$ order 1
for t=0 to 100 step 2
sprite img2$ alpha t/100
pause delay
next t
end def
def ScreenSpin(img1$, delay)
for t =0 to 628 step 10
sprite img1$ at 0,0 angle t/100
pause delay
next t
end def