Omnimaga

Calculator Community => TI Calculators => General Calculator Help => Topic started by: saintrunner on January 20, 2012, 09:39:02 pm

Title: scrolling and tilemapping tutorial?!?!
Post by: saintrunner on January 20, 2012, 09:39:02 pm
So after finally learning tilemapping, I am finding I can't figure out how to implement scrolling! I wanted to get it so when I started moving right or left the screen moved the opposite direction. but to be honest I don't think my tilemapping is gonna work. so could someone make me a tutorial on a sidescrolling tilemap? And I want this for a platformer jsyk

Thanks :)
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: nxtboy III on January 20, 2012, 09:39:59 pm
BTW, what platformer are you making?
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: saintrunner on January 20, 2012, 09:45:24 pm
Seeker 2: The Body  OH and this is in axe
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: leafy on January 21, 2012, 01:25:47 am
There are plenty of tutorials lying around this site if you can use that search box up there :P

It's a bit difficult for platformers, especially if you want it to run fast, but you'll figure it out ^^

EDIT: I'll start writing a scrolling platformer tutorial if you guys want.
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: saintrunner on January 21, 2012, 11:36:02 am
Yeah I did search it but I couldn't find something that made sense, so yeah thanks I'd really appreciate it leafy :)
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: turiqwalrus on January 21, 2012, 12:25:18 pm
check the tutorials section...
at the very bottom, you should be able to see yunhua's tutorial...
it's slightly unoptimized for tutorial purposes, but it should be fine.
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: saintrunner on January 21, 2012, 12:47:48 pm
Yeah I saw that but I didn't understand it much. Plus thats for an RPG and I want one easily fitted for a platformer, I'll check it out again anyways thanks, I might understand it now since the last time I checked it was a month ago before I actually understood tile mapping
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: yunhua98 on January 21, 2012, 03:22:39 pm
If your platformer is smooth scrolling with physics, you might have to change the code up quite a bit.  If it uses simple physics, then you can use the same code pretty much, except have a constant gravity.
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: saintrunner on January 21, 2012, 03:27:10 pm
this is my code...can you help modify it to work? and I know the map is small I'll make it larger once i get the scrolling


Code: [Select]
:.TILES
:Full
:Lbl TMAP
:ClrDraw
:[010101010101010101010101]→GDB1
:[010000000000000000000001]
:[010000000000000000000001]
:[010000000000000101010101]
:[010000000000000000000001]
:[010001010100000000000001]
:[010000000000000000000001]
:[010101010101010101010101]
:[7E81A581A599817E]→Pic1
:For(B,0,7)
:For(A,0,11)
:{B*12+A+GDB1}→T
:If T
:T--
:Pt-On(A*8,B*8,T*8+Pic1)
:DispGraph
:End
:End
:End
:[3C429581818D423C]→Pic1MAN
:[003C7E7E7E7E3C00]→Pic2MAN
:[3C42A98181B1423C]→Pic3MAN
:45→X:45→Y:0→J:1→D
:Repeat getKey(15)
:
:Pt-On(X,Y,Pic2MAN)r
:If getKey(2) and (pxl-Test(X-1,Y+6)=0) and (pxl-Test(X-1,Y+1)=0)
:X--
:2→D
:End
:If getKey(3) and (pxl-Test(X+8,Y+6)=0) and (pxl-Test(X+8,Y+1)=0)
:X++
:1→D
:End
:If getKey(4) and (pxl-Test(X+1,Y+8) or pxl-Test(X+7,Y+8)
:18→J
:End
:If (J>0)
:Y--
:J--
:End
:If (pxl-Test(X+6,Y+8)=0) and (pxl-Test(X+1,Y+8)=0) and (J=0) or (pxl-Test(X,Y) or (pxl-Test(X+7,Y)
:Y++
:0→J
:End
:If getKey(1) and (pxl-Test(X,Y+8)=0) and (pxl-Test(X,Y+8)=0)
:Y++
:0→J
:End
:If (D=1)
:Pt-Change(X,Y,Pic1MAN)
:End
:If (D=2)
:Pt-Change(X,Y,Pic3MAN)
:End
:Pause 25
:DispGraph
:DispGraphr
:ClrDrawr
:If (D=1)
:Pt-Change(X,Y,Pic1MAN)
:End
:If (D=2)
:Pt-Change(X,Y,Pic3MAN)
:End
:End
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: yunhua98 on January 21, 2012, 03:31:19 pm
could you tell me what each of your pointers, not counting the sprite pointers, do?  I'm really bad at understanding other people's code.  :P
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: saintrunner on January 21, 2012, 03:34:57 pm
A is columns and B is rows, J is for jumping, X and Y are for your characters position, and D is just the direction you face
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: yunhua98 on January 21, 2012, 03:38:12 pm
In line 50, why do you have pxl-test(X, Y+8) twice?  as for scrolling, I'm working on that right now.  ;)
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: saintrunner on January 21, 2012, 03:45:24 pm
Just a copy and paste error :P sorry, and THANKS SO MUCH FOR HELPING ME!!!
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: Adriweb on January 21, 2012, 03:48:18 pm
On TI-Planet ( here (http://tiplanet.org/forum/viewtopic.php?f=12&t=8538&p=120056#p119095) ), a member suggested this :

Quote
Si tu veux faire du tilemapping pixel par pixel, il faut en effet utiliser le smooth scrolling. Je vais essayer de t'expliquer comment faire :
Tout d'abord , tu dois changer de signe deux variables (I et J) en fonction de la direction où tu vas comme ceci :
CODE: TOUT SÉLECTIONNER
:If getKey(3) and (I=0) and (J=0)
:1→I
:End
:If getKey(2) and (I=0) and (J=0)
:-1→I
:End
:If getKey(1) and (I=0) and (J=0)
:1→J
:End
:If getKey(4) and (I=0) and (J=0)
:-1→J
:End


Ensuite tu les ajoutes à H et V (le décalage horizontale et verticale sur la map entre 0 et 8 ) :
CODE: TOUT SÉLECTIONNER
H+I+I→H
V+J+J→V

Lorsque tu as bougé de 8 pixels, tu rajoute (ou soustrait 1) à la position horizontale/verticale (ici P = horizontale et Q = verticale) :
CODE: TOUT SÉLECTIONNER
:If H-8=0 or (H+8=0
:P+I→P
:0→H→I
:End
:If V-8=0 or (V+8=0
:Q+J→Q
:0→V→J
:End


En tout, tu as :
CODE: TOUT SÉLECTIONNER
:Repeat getKey(15)
:
:If getKey(3) and (I=0) and (J=0)
:1→I
:End
:If getKey(2) and (I=0) and (J=0)
:-1→I
:End
:If getKey(1) and (I=0) and (J=0)
:1→J
:End
:If getKey(4) and (I=0) and (J=0)
:-1→J
:End
:
:
:H+I+I→H
:V+J+J→V
:
:If H-8=0 or (H+8=0
:P+I→P
:0→H→I
:End
:If V-8=0 or (V+8=0
:Q+J→Q
:0→V→J
:End
:
:sub(MAP)
:Pt-Off(48,32,Pic1
:DispGraphClrDraw
:End
:Return


sub(MAP) appellera la fonction qui s'occupe d'afficher la map à l'écran et Pic1 contient le sprite du personnage.

Pour voir les tiles sur le bord quand tu te déplace, tu dois avoir préalablement affiché la colonne/ligne d'après/avant.
Voilà maintenant le code de la fonction MAP :
CODE: TOUT SÉLECTIONNER
:Lbl MAP
:For(Y,0,9
:For(X,0,13
:Pt-On(X*8-8-H,Y*8-8-V,{Y+Q*[largeur de la map]+X+P+GDB1}*8+Pic0
:End
:End
:Return

avec GDB1, un pointeur sur la map et Pic0, un pointeur sur les tiles.

En espérant t'avoir aidé.
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: saintrunner on January 21, 2012, 03:49:13 pm
In english?
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: Adriweb on January 21, 2012, 03:50:28 pm
In english?

Google translate the original topic ?

sorry :/
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: saintrunner on January 21, 2012, 03:51:23 pm
ok I'll do that... but I still think if yunhua can put it into my code it would be easier for me to understand
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: yunhua98 on January 21, 2012, 03:54:21 pm
i'm not sure whether this works, if it doesn't could you screenshot it so I can see what's wrong?

Code: [Select]
:.TILES
:Full
:Lbl TMAP
:ClrDraw
:[01010101010101010101010101]→GDB1
:[01000000000000000000000001]
:[01000000000000000000000001]
:[01000000000000010101010101]
:[01000000000000000000000001]
:[01000101010000000000000001]
:[01000000000000000000000001]
:[01010101010101010101010101]
:[7E81A581A599817E]→Pic1
:0→R→C
:[3C429581818D423C]→Pic1MAN
:[003C7E7E7E7E3C00]→Pic2MAN
:[3C42A98181B1423C]→Pic3MAN
:45→X:45→Y:0→J:1→D
:Repeat getKey(15)
:
:Pt-On(X,Y,Pic2MAN)r
:If getKey(2) and (pxl-Test(X-1,Y+6)=0) and (pxl-Test(X-1,Y+1)=0)
:C++
:2→D
:End
:If getKey(3) and (pxl-Test(X+8,Y+6)=0) and (pxl-Test(X+8,Y+1)=0)
:C--
:1→D
:End
:If getKey(4) and (pxl-Test(X+1,Y+8) or pxl-Test(X+7,Y+8)
:18→J
:End
:If (J>0)
:R++
:J--
:End
:If (pxl-Test(X+6,Y+8)=0) and (pxl-Test(X+1,Y+8)=0) and (J=0) or (pxl-Test(X,Y) or (pxl-Test(X+7,Y)
:R--
:0→J
:End
:If getKey(1) and (pxl-Test(X,Y+8)=0)
:R--
:0→J
:End
:If (D=1)
:Pt-Change(X,Y,Pic1MAN)
:End
:If (D=2)
:Pt-Change(X,Y,Pic3MAN)
:End
:Pause 25
:DispGraph
:DispGraphr
:ClrDrawr
:If (D=1)
:Pt-Change(X,Y,Pic1MAN)
:End
:If (D=2)
:Pt-Change(X,Y,Pic3MAN)
:End
:sub(MAP)
:End
:
:Lbl MAP
:For(B,0,9)
:For(A,0,13)
:{B+(R/8)*12+A+(C/8)*8+GDB1}→T
:If T
:T--
:Pt-On(A-1*8+C^8,B-1*8+C^8,T+Pic1)
:DispGraph
:End
:End
:End
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: saintrunner on January 21, 2012, 03:55:12 pm
sure, I'll try it out thanks :)
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: saintrunner on January 21, 2012, 04:10:00 pm
ok so it just drew everything in the top right hand corner I think resulting in a black box in the top corner O.O
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: yunhua98 on January 21, 2012, 04:13:54 pm
I edited the code in my earlier post.

Change line 67 into what it is now.
Its the 8th row from the bottom, I think, with the part where it stores the stuff into T.
and then in line 70, remove the "*8" in the "T*8"
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: saintrunner on January 21, 2012, 04:17:45 pm
ok compiling...one sec

edit: same problem...except it I press right then it draws everything down 8 and right 8..resulting in two black boxes
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: yunhua98 on January 21, 2012, 04:22:18 pm
hmm...  I'm not sure what's wrong.  Its hard to do this without a calc sitting in front of me.  :/
I left it at school this weekend.  :o
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: saintrunner on January 21, 2012, 04:25:29 pm
The problem is defiantly with the tile map drawing :P problem is knowing which part
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: yunhua98 on January 21, 2012, 04:36:07 pm
changed the map routine.
I really have no idea why it shouldn't display the entire screen though...

Code: [Select]
:.TILES
:Full
:Lbl TMAP
:ClrDraw
:[01010101010101010101010101]→GDB1
:[01000000000000000000000001]
:[01000000000000000000000001]
:[01000000000000010101010101]
:[01000000000000000000000001]
:[01000101010000000000000001]
:[01000000000000000000000001]
:[01010101010101010101010101]
:[7E81A581A599817E]→Pic1
:0→R→C
:[3C429581818D423C]→Pic1MAN
:[003C7E7E7E7E3C00]→Pic2MAN
:[3C42A98181B1423C]→Pic3MAN
:45→X:45→Y:0→J:1→D
:Repeat getKey(15)
:
:Pt-On(X,Y,Pic2MAN)r
:If getKey(2) and (pxl-Test(X-1,Y+6)=0) and (pxl-Test(X-1,Y+1)=0)
:C++
:2→D
:End
:If getKey(3) and (pxl-Test(X+8,Y+6)=0) and (pxl-Test(X+8,Y+1)=0)
:C--
:1→D
:End
:If getKey(4) and (pxl-Test(X+1,Y+8) or pxl-Test(X+7,Y+8)
:18→J
:End
:If (J>0)
:R++
:J--
:End
:If (pxl-Test(X+6,Y+8)=0) and (pxl-Test(X+1,Y+8)=0) and (J=0) or (pxl-Test(X,Y) or (pxl-Test(X+7,Y)
:R--
:0→J
:End
:If getKey(1) and (pxl-Test(X,Y+8)=0)
:R--
:0→J
:End
:If (D=1)
:Pt-Change(X,Y,Pic1MAN)
:End
:If (D=2)
:Pt-Change(X,Y,Pic3MAN)
:End
:Pause 25
:DispGraph
:DispGraphr
:ClrDrawr
:If (D=1)
:Pt-Change(X,Y,Pic1MAN)
:End
:If (D=2)
:Pt-Change(X,Y,Pic3MAN)
:End
:sub(MAP)
:End
:
:Lbl MAP
:For(B,0,9)
:For(A,0,13)
:{B+(R/8)*12+A+(C/8)+GDB1}→T
:If T
:T--
:Pt-On(A*8-8+C^8,B*8-8+R^8,T*8+Pic1)
:End
:End
:DispGraph
:
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: saintrunner on January 21, 2012, 04:46:28 pm
Nope :P it just draws REALLY SLOW and all in the upper left corner.
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: yunhua98 on January 21, 2012, 04:47:23 pm
huh.  I'll check it out on my calc later.
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: saintrunner on January 21, 2012, 04:47:48 pm
ok, thanks for all the help anyways :) I really appreciate it
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: leafy on January 21, 2012, 05:16:41 pm
Fellas, here is your problem.

Pt-On(A*8-8+C^8,B*8-8+R^8,T*8+Pic1)

This line, near the end. Axe ignores order of operations, so you're really taking that entire mod 8 which returns a value from 0-7. This means that it'll always draw the tile in the same little corner at the top left. Try this:

Pt-On(A*8-8+(C^8),B*8-8+(R^8),T*8+Pic1)
Title: Re: scrolling and tilemapping tutorial?!?!
Post by: saintrunner on January 21, 2012, 05:25:12 pm
OHHH so close! It draws a bunch of random stuff though but his time all over the screen. I think a few numbers are off