Example 1, move the mouse to move the camera.
sync on
sync rate 0
rem make an image for the sprite
cls rgb( 0, 200, 0 )
get image 1, 0, 0, 48, 48, 1
rem create sprite 1 and give it image 1, then hide it (as we'll be pasting it manually)
sprite 1, screen width() / 2, screen height() / 2, 1
offset sprite 1, 24, 24
hide sprite 1
rem place the mouse in the centre of the screen
position mouse screen width() / 2, screen height() / 2
rem main loop
do
rem get and store the current mouse coordinates as mx, my
mx = mousex()
my = mousey()
rem change the camera's x/y positions based on where in the screen the mouse is (if the mouse is in the centre, the camera won't move, in the mouse is in the upper left, the camera moves in that direction, etc. )
if ( mx => ( screen width() / 2 ) - 32 and mx =< ( screen width() / 2 ) + 32 and my => ( screen height() / 2 ) - 32 and my =< ( screen height() / 2 ) + 32 ) = 0
camx# = camx# - ( ( mx < ( screen width() / 2 ) ) / 2.0 ) + ( ( mx > ( screen width() / 2 ) ) / 2.0 )
camy# = camy# - ( ( my < ( screen height() / 2 ) ) / 2.0 ) + ( ( my > ( screen height() / 2 ) ) / 2.0 )
endif
rem enforce some vague boundaries (box the size of the screen)
if camx# < 0 - screen width() / 2 then camx# = 0 - screen width() / 2
if camy# < 0 - screen height() / 2 then camy# = 0 - screen height() / 2
if camx# > screen width() / 2 then camx# = screen width() / 2
if camy# > screen height() / 2 then camy# = screen height() / 2
rem paste the sprite at it's actual position, minus the camera's position.
paste sprite 1, sprite x( 1 ) - camx#, sprite y( 1 ) - camy#
rem prepare for 2d drawing
lock pixels
rem show the outline of the area shown by the camera when it is at 0, 0 (origin)
line 0 - camx#, 0 - camy#, screen width() - camx#, 0 - camy#
line 0 - camx#, screen height() - camy#, screen width() - camx#, screen height() - camy#
line 0 - camx#, 0 - camy#, 0 - camx#, screen height() - camy#
line screen width() - camx#, 0 - camy#, screen width() - camx#, screen height() - camy#
rem show the centre of the camera (area to put mouse in when you want to stop scrolling)
line ( screen width() / 2 ) - 32, ( screen height() / 2 ) - 32, ( screen width() / 2 ) + 32, ( screen height() / 2 ) - 32
line ( screen width() / 2 ) - 32, ( screen height() / 2 ) + 32, ( screen width() / 2 ) + 32, ( screen height() / 2 ) + 32
line ( screen width() / 2 ) - 32, ( screen height() / 2 ) - 32, ( screen width() / 2 ) - 32, ( screen height() / 2 ) + 32
line ( screen width() / 2 ) + 32, ( screen height() / 2 ) - 32, ( screen width() / 2 ) + 32, ( screen height() / 2 ) + 32
rem show the width and height of the screen
text 0 - camx#, 0 - camy#, "0, 0"
text screen width() - camx#, 0 - camy#, str$( screen width() ) + ", 0"
text 0 - camx#, screen height() - camy#, "0, " + str$( screen height() )
text screen width() - camx#, screen height() - camy#, str$( screen width() ) + ", " + str$( screen height() )
center text screen width() / 2, screen height() / 2, str$( int( camx# ) ) + ", " + str$( int( camy# ) )
unlock pixels
sync
cls 0
loop
Example 2, use the arrow keys to move the camera.
sync on
sync rate 0
rem make an image for the sprite
cls rgb( 0, 200, 0 )
get image 1, 0, 0, 48, 48, 1
rem create sprite 1 and give it image 1, then hide it (as we'll be pasting it manually)
sprite 1, screen width() / 2, screen height() / 2, 1
offset sprite 1, 24, 24
hide sprite 1
rem main loop
do
rem get and store key input
kleft = leftkey()
kright = rightkey()
kup = upkey()
kdown = downkey()
rem change the camera's x/y positions based on key presses
camx# = camx# - kleft + kright
camy# = camy# - kup + kdown
rem enforce some vague boundaries (box the size of the screen)
if camx# < 0 - screen width() / 2 then camx# = 0 - screen width() / 2
if camy# < 0 - screen height() / 2 then camy# = 0 - screen height() / 2
if camx# > screen width() / 2 then camx# = screen width() / 2
if camy# > screen height() / 2 then camy# = screen height() / 2
rem paste the sprite at it's actual position, minus the camera's position.
paste sprite 1, sprite x( 1 ) - camx#, sprite y( 1 ) - camy#
rem prepare for 2d drawing
lock pixels
rem show the outline of the area shown by the camera when it is at 0, 0 (origin)
line 0 - camx#, 0 - camy#, screen width() - camx#, 0 - camy#
line 0 - camx#, screen height() - camy#, screen width() - camx#, screen height() - camy#
line 0 - camx#, 0 - camy#, 0 - camx#, screen height() - camy#
line screen width() - camx#, 0 - camy#, screen width() - camx#, screen height() - camy#
rem show the width and height of the screen
text 0 - camx#, 0 - camy#, "0, 0"
text screen width() - camx#, 0 - camy#, str$( screen width() ) + ", 0"
text 0 - camx#, screen height() - camy#, "0, " + str$( screen height() )
text screen width() - camx#, screen height() - camy#, str$( screen width() ) + ", " + str$( screen height() )
center text screen width() / 2, screen height() / 2, str$( int( camx# ) ) + ", " + str$( int( camy# ) )
unlock pixels
sync
cls 0
loop
Example 3, using some slightly more advanced data handling methods. Use the arrow keys to move the camera.
sync on
sync rate 0
rem declare variables that won't change as constants
#CONSTANT SWIDTH screen width()
#CONSTANT SHEIGHT screen height()
#CONSTANT KLEFT leftkey()
#CONSTANT KRIGHT rightkey()
#CONSTANT KUP upkey()
#CONSTANT KDOWN downkey()
#CONSTANT SCROLLSPEED 1.5
#CONSTANT SPRITE_R 0
#CONSTANT SPRITE_G 200
#CONSTANT SPRITE_B 0
rem declare variables that can change as globals
global camx as float = 0
global camy as float = 0
rem make an image for the sprite
cls rgb( SPRITE_R, SPRITE_G, SPRITE_B ) : get image 1, 0, 0, 48, 48, 1
rem create sprite 1 and give it image 1, then hide it (as we'll be pasting it manually)
sprite 1, SWIDTH / 2, SHEIGHT / 2, 1
offset sprite 1, 24, 24
hide sprite 1
rem main loop
do
rem get and store key input
kleft = leftkey()
kright = rightkey()
kup = upkey()
kdown = downkey()
rem change the camera's x/y positions based on key presses
camx = camx - ( KLEFT * SCROLLSPEED ) + ( KRIGHT * SCROLLSPEED )
camy = camy - ( KUP * SCROLLSPEED ) + ( KDOWN * SCROLLSPEED )
rem enforce some vague boundaries (box the size of the screen)
if camx < 0 - SWIDTH / 2 then camx = 0 - SWIDTH / 2
if camy < 0 - SHEIGHT / 2 then camy = 0 - SHEIGHT / 2
if camx > SWIDTH / 2 then camx = SWIDTH / 2
if camy > SHEIGHT / 2 then camy = SHEIGHT / 2
rem paste the sprite at it's actual position, minus the camera's position.
paste sprite 1, sprite x( 1 ) - camx, sprite y( 1 ) - camy
rotate sprite 1, sprite angle( 1 ) + 0.5
rem prepare for 2d drawing
lock pixels
rem show the outline of the area shown by the camera when it is at 0, 0 (origin)
line 0 - camx, 0 - camy, SWIDTH - camx, 0 - camy
line 0 - camx, SHEIGHT - camy, SWIDTH - camx, SHEIGHT - camy
line 0 - camx, 0 - camy, 0 - camx, SHEIGHT - camy
line SWIDTH - camx, 0 - camy, SWIDTH - camx, SHEIGHT - camy
rem show the width and height of the screen
text 0 - camx, 0 - camy, "0, 0"
text SWIDTH - camx, 0 - camy, str$( SWIDTH ) + ", 0"
text 0 - camx, SHEIGHT - camy, "0, " + str$( SHEIGHT )
text SWIDTH - camx, SHEIGHT - camy, str$( SWIDTH ) + ", " + str$( SHEIGHT )
center text SWIDTH / 2, SHEIGHT / 2, str$( int( camx ) ) + ", " + str$( int( camy ) )
unlock pixels
sync
cls 0
loop
Example 4, same as example 3, but uses cloggy's d3d plugin to draw stuff much faster (if you don't have, I suggest you get it- search it)
sync on
sync rate 0
rem declare variables that won't change as constants
#CONSTANT SWIDTH screen width()
#CONSTANT SHEIGHT screen height()
#CONSTANT KLEFT leftkey()
#CONSTANT KRIGHT rightkey()
#CONSTANT KUP upkey()
#CONSTANT KDOWN downkey()
#CONSTANT SCROLLSPEED 1.5
#CONSTANT SPRITE_R 0
#CONSTANT SPRITE_G 200
#CONSTANT SPRITE_B 0
rem declare variables that can change as globals
global camx as float = 0
global camy as float = 0
rem prepare to use d3d text
d3d_init
d3d_font 1, "arial", 15, 0, 0, 0
rem make an image for the sprite
cls rgb( SPRITE_R, SPRITE_G, SPRITE_B ) : get image 1, 0, 0, 48, 48, 1
rem create sprite 1 and give it image 1, then hide it (as we'll be pasting it manually)
sprite 1, SWIDTH / 2, SHEIGHT / 2, 1
offset sprite 1, 24, 24
hide sprite 1
rem main loop
do
rem get and store key input
kleft = leftkey()
kright = rightkey()
kup = upkey()
kdown = downkey()
rem change the camera's x/y positions based on key presses
camx = camx - ( KLEFT * SCROLLSPEED ) + ( KRIGHT * SCROLLSPEED )
camy = camy - ( KUP * SCROLLSPEED ) + ( KDOWN * SCROLLSPEED )
rem enforce some vague boundaries (box the size of the screen)
if camx < 0 - SWIDTH / 2 then camx = 0 - SWIDTH / 2
if camy < 0 - SHEIGHT / 2 then camy = 0 - SHEIGHT / 2
if camx > SWIDTH / 2 then camx = SWIDTH / 2
if camy > SHEIGHT / 2 then camy = SHEIGHT / 2
rem paste the sprite at it's actual position, minus the camera's position.
paste sprite 1, sprite x( 1 ) - camx, sprite y( 1 ) - camy
rotate sprite 1, sprite angle( 1 ) + 0.5
rem show the outline of the area shown by the camera when it is at 0, 0 (origin)
d3d_color 191, 191, 255, 223
d3d_line 0 - camx, 0 - camy, SWIDTH - camx, 0 - camy
d3d_line 0 - camx, SHEIGHT - camy, SWIDTH - camx, SHEIGHT - camy
d3d_line 0 - camx, 0 - camy, 0 - camx, SHEIGHT - camy
d3d_line SWIDTH - camx, 0 - camy, SWIDTH - camx, SHEIGHT - camy
rem show the width and height of the screen
d3d_starttext
d3d_color 255, 255, 255, 255
d3d_text 1, 0 - camx, 0 - camy, 0, "0, 0"
d3d_text 1, SWIDTH - camx, 0 - camy, 0, str$( SWIDTH ) + ", 0"
d3d_text 1, 0 - camx, SHEIGHT - camy, 0, "0, " + str$( SHEIGHT )
d3d_text 1, SWIDTH - camx, SHEIGHT - camy, 0, str$( SWIDTH ) + ", " + str$( SHEIGHT )
d3d_text 1, SWIDTH / 2, SHEIGHT / 2, 1, str$( int( camx ) ) + ", " + str$( int( camy ) )
d3d_endtext
sync
cls 0
loop
Example 5 - Again, building on example 4, allows you to move the sprite with the mouse. You'll notice that, while the sprite is positioned at the actual location of the mouse, it is drawn at an offset- that offset is the camera's position. So basically:
Sprite is at:
mousex(), mousey()
But is drawn at:
mousex() - camx, mousey() - camy
sync on
sync rate 0
rem declare variables that won't change as constants
#CONSTANT SWIDTH screen width()
#CONSTANT SHEIGHT screen height()
#CONSTANT KLEFT leftkey()
#CONSTANT KRIGHT rightkey()
#CONSTANT KUP upkey()
#CONSTANT KDOWN downkey()
#CONSTANT SCROLLSPEED 4.5
#CONSTANT SPRITE_R 0
#CONSTANT SPRITE_G 200
#CONSTANT SPRITE_B 0
rem declare variables that can change as globals
global camx as float = 0
global camy as float = 0
rem prepare to use d3d text
d3d_init
d3d_font 1, "arial", 15, 0, 0, 0
rem make an image for the sprite
cls rgb( SPRITE_R, SPRITE_G, SPRITE_B ) : get image 1, 0, 0, 48, 48, 1
rem create sprite 1 and give it image 1, then hide it (as we'll be pasting it manually)
sprite 1, SWIDTH / 2, SHEIGHT / 2, 1
offset sprite 1, 24, 24
hide sprite 1
rem main loop
do
rem get and store key input
kleft = leftkey()
kright = rightkey()
kup = upkey()
kdown = downkey()
rem change the camera's x/y positions based on key presses
camx = camx - ( KLEFT * SCROLLSPEED ) + ( KRIGHT * SCROLLSPEED )
camy = camy - ( KUP * SCROLLSPEED ) + ( KDOWN * SCROLLSPEED )
rem enforce some vague boundaries (box the size of the screen)
if camx < 0 - SWIDTH / 2 then camx = 0 - SWIDTH / 2
if camy < 0 - SHEIGHT / 2 then camy = 0 - SHEIGHT / 2
if camx > SWIDTH / 2 then camx = SWIDTH / 2
if camy > SHEIGHT / 2 then camy = SHEIGHT / 2
rem paste the sprite at the actual position of the mouse, minus the camera's position.
sprite 1, mousex(), mousey(), 1
paste sprite 1, sprite x( 1 ) - camx, sprite y( 1 ) - camy
rotate sprite 1, sprite angle( 1 ) + 0.5
rem show the outline of the area shown by the camera when it is at 0, 0 (origin)
d3d_color 191, 191, 255, 223
d3d_line 0 - camx, 0 - camy, SWIDTH - camx, 0 - camy
d3d_line 0 - camx, SHEIGHT - camy, SWIDTH - camx, SHEIGHT - camy
d3d_line 0 - camx, 0 - camy, 0 - camx, SHEIGHT - camy
d3d_line SWIDTH - camx, 0 - camy, SWIDTH - camx, SHEIGHT - camy
rem show the width and height of the screen
d3d_starttext
d3d_color 255, 255, 255, 255
d3d_text 1, 0 - camx, 0 - camy, 0, "0, 0"
d3d_text 1, SWIDTH - camx, 0 - camy, 0, str$( SWIDTH ) + ", 0"
d3d_text 1, 0 - camx, SHEIGHT - camy, 0, "0, " + str$( SHEIGHT )
d3d_text 1, SWIDTH - camx, SHEIGHT - camy, 0, str$( SWIDTH ) + ", " + str$( SHEIGHT )
d3d_text 1, SWIDTH / 2, SHEIGHT / 2, 1, str$( int( camx ) ) + ", " + str$( int( camy ) )
d3d_endtext
sync
cls 0
loop
Hope my endeavors help.
EBA;
FUI; Mario Land Ripoff.
Every time you post a joke in the form of code, mace yourself.