dMZX Forums: Unbound Sprites - dMZX Forums

Jump to content

Page 1 of 1

Unbound Sprites

#1 User is offline   CJA 

  • «≡larch bucket≡»
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 3,262
  • Joined: 23-June 05
  • Gender:Male
  • Location:......@.c....

Posted 17 November 2017 - 01:03 AM

Unbound Sprites Mini-Tutorial

This mini-tutorial is a quick reference/starting point for using unbound sprites, a new feature in MZX 2.90 that allows creators to draw sprites at arbitrary pixel coordinates, rather than being "bound" to the tiles that comprise MZX boards. This assumes that you know the sprite basics.

Just for quick reference, a MZX screen is (80 x 25) tiles, each of which are (8 x 14) pixels, giving a total resolution of (640 x 350) pixels. This means that, if the screen is scrolled to the top left, the upper left pixel is (0, 0) and the lower right pixel is (639, 349).


Starter engine

Let’s start with a bare bones mouse engine. Make a cool mouse character, then create a robot and set the robot’s character to the mouse character. Then have some basic mouse code:

. "This robot is the mouse char - set the sprite to reference me"
set "spr255_refx" to "thisx"
set "spr255_refy" to "thisy"
set "spr255_width" to 1
set "spr255_height" to 1
: "l"
. "Redraw mouse cursor"
put c0f Sprite pff at "mousex" "mousey"
cycle 1
goto "l"



Moving to Unbound

Converting coordinates. The main tricky part is, of course, the transition from working on a tile basis to a pixel basis, which can be done in one of these ways:
  • Rewrite the engine. Most often, this is the least painful way.
  • Re-write the way positions are calculated so that they are relative to pixel coordinates, not tile coordinates. For a large, developed engine, this can be much harder than simply rewriting!
  • Find all references to tile coordinates in the engine and multiply by 8 (horizontal) or 14 (vertical) to convert to pixel coordinates. This is not very useful of course, because this means that the sprite will stay on the tile grid, and there is really no point in using unbound sprites.


Reference and size counters. When using unbound sprites, the sprite's reference and size properties are still tile based; do not change them to pixel coordinates:
  • sprN_refx
  • sprN_refy
  • sprN_width
  • sprN_height



Unbound engine

Here's our engine, now unbound!

. "This robot is the mouse char - set the sprite to reference me"
set "spr255_refx" to "thisx"
set "spr255_refy" to "thisy"
set "spr255_width" to 1
set "spr255_height" to 1
set "spr255_unbound" to 1
: "l"
. "Redraw mouse cursor - change mousex/mousey to mousepx/mousepy"
put c0f Sprite pff at "mousepx" "mousepy"
cycle 1
goto "l"


There are a few other cool features that unbound sprites can use, including transparency colors and extra charsets. Stay tuned!

This post has been edited by CJA: 17 November 2017 - 01:09 AM

Need a dispenser here.
0

Share this topic:


Page 1 of 1


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users