home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
mag_discs
/
11
/
sprite2
/
PART_2
Wrap
Text File
|
1994-02-15
|
5KB
|
121 lines
+--------------------------------------------+
| SPRITE HANDLING PART 2 |
| Moving and Scaling Sprites |
| © Atle Mjelde Bårdholt |
| - The ARM Club - |
| 15th February 1994 |
| |
+--------------------------------------------+
This article is the second part of my Sprite Handling series.
The first part was included in Eureka Issue 10. If you don`t have this part,
then either contact me or The ARM Club.
MOVING Sprites is almost the same as displaying. When you display a sprite,
you tell the computer at what x and y position the sprite should be displayed
from. Beware that this x and y value is the down-left corner of the sprite.
So in short terms it is just a matter of altering these x and y values in some
routines. Like moving up(y+)/down(y-), left(x-)/right(x+), circles and so on.
You must also remember that different modes have different x/y borders.
An example of a Mode 13 screen :
^ (0,1023) (1279,1023) ^
| |
| __________ |
| | | |
| | SPRITE | |
y | |__________| |
| (x,y) |
| |
| |
| |
| (0,0) (1279,0)|
|___________________________________________|
x
This parts Sprite example (!Sprite2), includes the ball and some sprites that
contain some useful information. You can move the ball up/down if you click
select with the pointer over the Up or Down sprites. The ball can be scaled
with Menu or Adjust clicks and be restored with a Select click.
If you have scaled the ball down to far, you might need to click Select several
times to restore it.
I will here describe some of the BBC BASIC code found in the listing :
When you want to move sprites on the screen you need to use screen banks.
This is used to avoid flickering. I use two variables sc1% and sc2% as
screen bank 1 and screen bank 2.
Use : Do a screens work then swap banks and then a screens work .......
The routine :
DEF PROCupdate_screen
WAIT : REM Wait for vertical sync
SYS 6,112,sc1%
SYS 6,113,sc2%
SWAP sc1%,sc2%: REM Exchange the contents of the two variables
CLS : REM Clear the screen
ENDPROC
The main Mouse check routine :
MOUSE x,y,z : REM Reads the mouse position and status
CASE z OF
REM Mouse Adjust zooms out
WHEN 1:!scale% += 40:scale%!4 += 40
REM Mouse Menu zooms in
WHEN 2:!scale% -= 40:scale%!4 -= 40
REM Mouse Select checks position/restores sprite
WHEN 4:PROCcheck_pointer
REM Click on all = END
WHEN 7:END
ENDCASE
To scale sprites, we need to define some memory :
DIM scale% 16 : REM allocate space for a byte array
!scale% = 640: REM x multiplier <- Alter these values to
scale%!4 = 640: REM y multiplier see what they do !
scale%!8 = 640: REM x divisor
scale%!12 = 640: REM y divisor
And to display the scaled sprite :
SYS sprite%,&234,sprite_area%,sprite_addr_1%,50,y_ball%,0,scale%,-1
R0 R1 R2 R3 R4 R5 R6 R7
R0 = &234 : This is 512 + 52 : 512 is a pointer to user sprite area
52 is the "Put sprite scaled" command
R1 = sprite_area% : Our pointer to the defined sprite area block
R2 = sprite_addr_1% : Pointer to the address where we have our sprite
R3 = the x coordinate
R4 = the y coordinate
R5 = plot action : 0 = Overwrite colour on screen with sprite pixel colour
R6 = the scale factors
R7 = pixel translation table
-------------------------------------------------------------------------------
In the next article I will explain ARM & Sprites.
See you then !
-------------------------------------------------------------------------------
Please feel free to contact me if you have any questions about
sprites or if you want me to cover some other topic(s) of the sprite
world. Please mark all post Subject : Sprites
^^^^^^^^^^^^^^^^^
E-mail: atle.baardholt@kih.no
Regular mail: Atle Mjelde Bårdholt
Schlanbuschvei 8
N-3600 Kongsberg
Norway