Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: DincoC on November 03, 2012, 04:12:47 pm

Title: Movement on the graph screen
Post by: DincoC on November 03, 2012, 04:12:47 pm
Hello,
I have read this nice tutorial about movement and I tried to do the same thing, but on the graph screen. I tried to add movement in the second dimension. For some reason it doesn't work - once any of the arrow keys is pressed, the pixel goes to the top of the screen and can only be moved horizontally.
Code: [Select]
AxesOff:
FnOff:
ClrDraw:
ClrHome:
32->Y:
48->X:
Repeat K=45:
Pxl-On(Y,X:
Repeat Ans:
Getkey->K:
End:
ClrDraw:
X+(K=26 and X<94)-(K=24 and X>0)->X:
Y+(K=34 and Y<62)-(K=25 and Y>0)->Y:
End:

Also I know that this is a very simple subject, but I'm just a beginner and I can't figure this by myself.
Title: Re: Movement on the graph screen
Post by: dinosteven on November 03, 2012, 04:39:34 pm
When using ClrDraw, the Y variable gets messed up. You should use another variable.
It works fine replacing X,Y with B,A
Title: Re: Movement on the graph screen
Post by: Deep Toaster on November 03, 2012, 04:49:10 pm
Exactly what dinosteven said. Generally in TI-BASIC you should avoid using X and Y because they get updated by drawing commands.
Title: Re: Movement on the graph screen
Post by: ben_g on November 03, 2012, 04:56:10 pm
If you only need to move one pixel around, you should use pxl-off instaed of cleardraw. It's a lot faster, especially when you have got a level as well since then you don't need to redraw the level every frame.
Title: Re: Movement on the graph screen
Post by: dinosteven on November 03, 2012, 05:01:59 pm
By the way, what's better for stopping the pixel from going out of bounds?
DincoC's method or using a max and min command? I've always used max and min, cause that's what's on the TIBD.
Title: Re: Movement on the graph screen
Post by: DincoC on November 03, 2012, 07:21:23 pm
I changed the symbols and now pressing up/down arrow doesn't seem to do anything.
Title: Re: Movement on the graph screen
Post by: dinosteven on November 03, 2012, 07:22:28 pm
What symbols?
EDIT:
Oh the symbols for the variables. Hmmm.... It works on my calc. Make sure every variable is updated, you probably updated the pxl-on() but not the part where it moves up/down.
Title: Re: Movement on the graph screen
Post by: Deep Toaster on November 03, 2012, 07:38:56 pm
Yeah, make sure you update all of them. I count six instances of X and six instances of Y you should replace.
Title: Re: Movement on the graph screen
Post by: DincoC on November 04, 2012, 08:25:21 am
Yeah, I updated all of them. Besides the lack of vertical movement, there is also another bug. When I move the pixel to the left, it goes ok for 13 steps. On the 14th step it jumps one step left and one step down, then it goes to the left for another 8 steps and on the 9th jumps one left and one up. When going back right it does a similar thing, except it jumps up.
Title: Re: Movement on the graph screen
Post by: Deep Toaster on November 04, 2012, 10:15:42 am
Don't see why that would happen from the source... Are you sure you didn't mistype? Especially the Y+(K=34... line.
Title: Re: Movement on the graph screen
Post by: dinosteven on November 04, 2012, 10:28:23 am
It works. Here's a screenie of me scrolling through the code and running it:
(http://img27.imageshack.us/img27/3213/screenshot000.gif)
Title: Re: Movement on the graph screen
Post by: DincoC on November 04, 2012, 11:19:56 am
Ok it works now. I had replaced "K" with "Ans" and this was a mistake. I understand why it wouldn't work with Ans now :)