Soo. I have been programming in TI-BASIC on a TI-84+ C Silver Edition for a while now and have begun looking through code that uses XLIB. I was able to derive the basics of a few commands, but the rest of the stuff i see makes little or no sense.. I am looking for a tutorial or a link to a tutorial explaining these real( commands. If any of you readers have any experience, please help me get on your level!

Thank you Thank you Thank you! Smiling Cat

Jack
There is no real tutorial, we just use the wiki page at http://dcs.cemetech.net/index.php/Third-Party_BASIC_Libraries_(Color)

And if you run into problems, feel free to ask, but we'll need to see code to offer help.
Thank you tifreak8x!
Welcome to the boards Jack!

I guess I need to create some introductory tutorials for xLIB. I sortof started but slacked off :S.

Is there any particular aspect that you would like to focus on straight up?
tr1p1ea,

I already have a basic understanding, but my biggest question is.. how do i create the sprites? I often see "real(4,0,[arguments]" commands "cookie-cutting" sprites from what i assume are AppVars? How do I create my own and use them properly?
Merthsoft has created a fantastic tool call TokenIDE which is available in this thread: http://www.cemetech.net/forum/viewtopic.php?t=10098&start=0

You are correct that sprite are usually stored in appvars, as 8x8 tiles for use with the tilemap and drawsprite functions in xLIBC.

Tilemaps consist of 8x8 tiles only at this stage, where-as sprite can be constructed in multiples of 8x8 'blocks' as described on the wiki.

I can make some small example programs for you if you like?
That would be great thank you!
Ok so i made a very small demo. All it does is draw an 8x8 sprite and lets you move it around the screen until you press CLEAR.

The files can be found here: http://tr1p1ea.net/files/downloads/xsprtut.zip

Here is the sprite sheet for the appvar (also in the zip):


And here is the source code with comments:
Quote:
"SET LCD 2X MODE
real(0,1,1,0
"CLEAR SCREEN (BOTH SIDES)
real(0,3,4,255,1
real(0,3,4,255,0
"LOAD APPVAR XSPRITE INTO MEM
"XSPRITES
real(5,0,0
"SET VARS FOR SPRITE TO CENTRE SCREEN
real(1,1,0,160/2
real(1,1,1,120/2-4
"INIT BACKUP VARS FOR SPRITE CLEARING. XVARS 0,1=X,Y AND 2,3=BACKUP X,Y
real(1,1,2,160/2
real(1,1,3,120/2-4
"SET TIOSVAR S TO BE THE SPRITE INDEX IN THE APPVAR
"CHANGE THIS IF YOU WANT TO DRAW A DIFFERENT SPRITE
0→S
"MAIN LOOP TO DRAW+MOVE SPRITE UNTIL CLEAR IS PRESSED
Repeat real(2,0,0)=15
"DRAW SPRITE AND UPDATELCD
real(4,1,0,1,1,1,0,0,1,1,0,S
"DRAW OVER OLD SPRITE POSITION TO CLEAR IT ON OLD LCD SIDE
real(7,9,real(1,0,2),real(1,0,3),8,8,255,0
"COPY CURRENT XY TO BACKUP XY
real(1,1,2,real(1,0,0
real(1,1,3,real(1,0,1
"USE XLIBC INPUT FUNCTION TO UPDATE USERVARS BASED ON ARROW PRESS
real(2,1,0,1,8,8
End
"CLEAR SCREEN (BOTH SIDES)
real(0,3,4,255,1
real(0,3,4,255,0
"RESTORE LCD MODE
real(0,1,0,1


There are a few things that you need to know about xLIBC. The first is that the drawing functions all work in Half-Res mode, meaning that the screen is divided in 2, with only 1 half visible at any time. This enables you to draw to the 'non-visible' side of the screen and properly prepare it before display - reducing flicker and such; like double buffering. This is why we see some of the commands issued twice in the code, because it needs to operate on both sides like:
Quote:
"CLEAR SCREEN (BOTH SIDES)
real(0,3,4,255,1
real(0,3,4,255,0


The code pretty much readies the screen, sets up some initial XY values for the sprite, then in the main loop it does the following:

Draws the sprite and updates the LCD so its visible to the user
Draws an 8x8 white rectangle at the 'OLD' XY position on the 'non-visible' side of the screen, effective clearing the sprite
Copies the current XY to the old XY for later use
Uses the built in xLIBC GetKey command to test for arrow presses and update the required XY uservars the line:
Quote:
real(2,1,0,1,8,8

This will test for UP,DOWN,LEFT,RIGHT and update uservars 0,1 by +/-8 pixels if pressed, all in 1 line! There are other GetKey functions as well that can speed up some operations (tile collisions etc)

As a bonus the TIOS VAR 'S' holds the index for the TILE/SPRITE index in the appvar to draw. In the sprite sheet there are 2 sprites that occupy index's 0 & 1 (0=blue, 1 = red). If you change this line from:

Quote:
"CHANGE THIS IF YOU WANT TO DRAW A DIFFERENT SPRITE
0→S

to
Quote:
"CHANGE THIS IF YOU WANT TO DRAW A DIFFERENT SPRITE
1→S


It will draw the red sprite instead!

*NOTE* That all the text comments in the code slow down the program a fair bit, but its a mini-tutorial afterall. Here is a screenie!:



Sorry if its a bit rushed, happy to take any questions.

Of course you will need the latest version of DCSE8 on your calc to run the example.

EDIT - Just for those interested, and to ensure that advertising of DCSE libs is accurate, here is a screenshot of the same program with the text comments removed from the main loop in the code:



Same code, much speedier program Smile.
Ok quick question, I understand a lot of things from looking at this.
What are the last two parameters for displaying the sprite? I don't really understand even after reading the stuff on dcs.cemetech.net
Ahh ok the last 2 arguments are so you can specify a 'list of sprites' to use in different situations.

Say for example you have 4 8x8 sprites that represent UP,DOWN,LEFT,RIGHT at tiles 10,11,12,13 in your sprite sheet appvar.

Then you can simply list all of these in your DrawSprite call and use a variable for the PICINDEXSTART argument to tell the command which one to draw. A handy feature of one of the getkey routines is that it specifies a value based on which arrow key is pressed so it can be used in conjunction with this function.

Sorry if thats a bit of a rushed explanation, i'll do up a small example if i get time.
Oh I see now! So if you have. Few different sprites you want to draw that are in different positions, then you can just place them all in and the first will become 0 and etc. It makes a lot more sense now! Thanks for the help. Also, I just realized you created xLIBC Razz Awesome work tr1p1ea Smile
New question! I encounter this only sometimes, but what is the cause for violent flashing of sprites, shapes, and others?
Its more or less to do with half-res mode and switching between sides of the LCD. Likely this is because the switching is not performed at a constant rate ... hopefully it isnt too distracting.
So you need to switch at a constant rate. How do you control the switching?
How do I use the Tokens program to create appvars? I need to know how to make them and where to save them..
For sprite sheets and stuff, you can use file>open and then an image or draw the sprite. Then, save the whole thing as one of the different .8xv files
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement