Line 1,536:
Line 1,536:
== Pixel Referencing and Offset ==
== Pixel Referencing and Offset ==
+
+
You may have read up to this point and have been thinking along the way, “dammit stop saying ignore offset!”, well today you become a man, erm, I mean you learn what offset and pixel referencing is, sorry I often get the two mixed up... Anyway, I’ll start with the offset first of all as it is the easiest to understand.
+
+
In plain terms, offset means not set correctly. Think about your screen, it’s a grid made up of tens of thousands of dots, each of these dots has a ‘default’ location, top left pixel is (0,0), when you change the offset, you move where these locations are. For example, when you go to print an image at location (100, 100), then it will print with its top left corner at the coordinate (0,0) and print the rest of the pixels based on that.
+
+
If however, you were to print that image at location (100,100) with an offset of (10,10) then you would print that image at location (110,110). You can calculate the offset by adding the coordinates, this goes for negatives as well, a few examples.
+
+
<source lang="cpp">Coordinates OffSet PrintLocation
+
(10, 40) (-20, 4) (-10, 44)
+
(300, 0) (0, 0) (300, 0)
+
Etc</source>
+
+
That’s about all there is to offset, so let’s look at the slightly more complex, Pixel Referencing. The easiest way to understand pixel references is an example. In sprite.cpp we looked at the following SetPosition() function:
+
+
<source lang="cpp">sprite2.SetPosition(320, 240);</source>
+
+
This was one method of setting where the image should be printed, but I completely ignored the other which is, SetRefPixelPositioning()
+
+
<source lang="cpp">void wsp::Sprite::SetRefPixelPositioning ( REFPIXEL_POSITIONING
+
positioning )
+
Sets how the sprite should react on X and Y coordinates.
+
Parameters:
+
positioning Specifies the type of the positioning.</source>
+
+
Usually when you print an image to the screen, it, by default, prints to the top left (wsp::REFPIXEL_POSITIONING, default parameter in the emuneration is REFPIXEL_POS_TOPLEFT), but what we have done here, is instead pass it a different parameter that lets you customize where your image will print by default. We pass the function REFPIXEL_POS_PIXEL, which in is defined in the enum section:
+
+
REFPIXEL_POS_PIXEL The reference pixel is placed at the X and Y coordinates.
+
+
This is just another method of setting where you want to print your image, the x any y coordinates move the reference pixel to the coordinate specified and when SetPosition() is called and the image is printed at the centre of the screen.
+
+
What this does is effectively cut out part of the image. Say we have an image that has a resolution of 150 x 150 pixels and we print it at location (0,0) then it may look something like this:
+
+
[[Image:Flexfig17.png]]
+
+
Now say that we have set the pixel reference to (10,10) then it will find the pixel on the image that is at location (10,10) which would be where the black dot is on the below image:
+
+
[[Image:Flexfig18.png]]
+
+
The image will be printed like this at location (0,0)
+
+
[[Image:Flexfig19.png]]
+
+
If you look closely you can see that some of the image has been cut off, 10 pixels starting at the right side and 10 pixels starting from the top have been cut off and the image is printed at the coordinate (0,0) just as it would if it had no pixel referencing. You essentially crop the image from the top left corner using whatever values you have assigned the parameters. So looking at the call in sprite.cpp to the refpixel function you can see that the image is still being printed but is also passed the enumeration REFPIXEL_POS_PIXEL. That brings me to the end of another (but short) lesson on the Libwiisprite, hope you learned something.
+
+
If you wish to contact me drop me an email at phlex.wii@gmail.com
== EXAMPLE PROGRAMS ==
== EXAMPLE PROGRAMS ==