Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: Happybobjr on January 12, 2011, 06:12:30 pm
-
I know this is a dumb question but, how can i make a sprite move along a line?
I feel like the answer is obvious but i just can''t figure it out.
-
YOU COULD DISPLAY IT AND THEN USE hORIZONTAL/vERTICAL, OR increment the x/y coordinate... by a constant value
stupid caps lock...
Read it this way, lol: you could display it and then use horizontal/vertical, or increment the x/y coordinate by a constant value.
-
If I understand what you are saying, I don't think that would be the appropriate way to solve my problem for my needs.
-
This might not be the most efficient method, but try this:
[Sprite data]->Pic1
Sprite X-coordinate ->X
Sprite Y-coordinate ->Y
Sprite X-momentum ->S
Sprite Y-momentum ->T
.Main loop
While 1
Stuff
More stuff
ClrDraw
X+S->X
Y+T->Y
Pt-On(X,Y,Pic1)
End
You could make it move in a sort of diagonal pattern if you set both the X and Y values to differing numbers, though it'll skip a little...
-
Do you mean a user-defined line?
-
Do you mean a user-defined line?
umm... i think.
I want it to be like axe's line algorithm except only draw one pixel at a time. and instead of it being a pixel, i want it to be a sprite.
-
If I understand what you are saying, I don't think that would be the appropriate way to solve my problem for my needs.
What are your needs?
Also, sorry about the downrating. I accidentally clicked it.
EDIT: Ninja'd.
You can just use a For( loop and increment the X and/or Y position.
-
If I understand what you are saying, I don't think that would be the appropriate way to solve my problem for my needs.
What are your needs?
Also, sorry about the downrating. I accidentally clicked it.
EDIT: Ninja'd.
You can just use a For( loop and increment the X and/or Y position.
Umm, it says it was rated up ???
a bullet that can pretty much go any direction that is determined by the tanks barrel (I think that's the right word.)
-
Do you mean a user-defined line?
umm... i think.
I want it to be like axe's line algorithm except only draw one pixel at a time. and instead of it being a pixel, i want it to be a sprite.
Try modifying this:
http://ourl.ca/4129/138496 (http://ourl.ca/4129/138496)
-
Well, you'd have to rotate the sprite, but that's simple.
Take this example code:
While 1
Pt-On(X,Y,<pointer>
Dispgraph
Pt-change(X,Y,<pointer>
If <collision detected>
Goto <Collision handling>
Else
X+A->X
Y+B->Y
End
End
To change the direction, just change A and B.
PS: I accidentally downrated your post, so I uprated in response.
-
Crud, more complex stuff :/
Thank you. I'll take a lookDo you mean a user-defined line?
umm... i think.
I want it to be like axe's line algorithm except only draw one pixel at a time. and instead of it being a pixel, i want it to be a sprite.
Try modifying this:
http://ourl.ca/4129/138496 (http://ourl.ca/4129/138496)
Qwerty@ The problem is that i don't know what a and b are. I only know the start point and endpoint.
-
Crud, more complex stuff :/
Thank you. I'll take a lookDo you mean a user-defined line?
umm... i think.
I want it to be like axe's line algorithm except only draw one pixel at a time. and instead of it being a pixel, i want it to be a sprite.
Try modifying this:
http://ourl.ca/4129/138496 (http://ourl.ca/4129/138496)
/me shrugs
Yeah. It's fairly easy to make things go in straight lines, or 45 degree angle lines, but getting things to move at other angles and slopes without skipping a bunch of pixels isn't something I've managed to figure out in Axe.
-
Qwerty@ The problem is that i don't know what a and b are. I only know the start point and endpoint.
You don't know what direction the tank is shooting in? Um, I'm not sure any line drawing algorithm is useful if you don't have the information to figure that out. It can be pretty easily derived from the start and endpoints though.
-
It's easy to derive the slope, true, but if you have a steep vertical slope, your object will end up skipping a bunch of pixels, possibly throwing off collision detection and
making the speed look irregular.
If the tank isn't allowed to fire too high or too low, then you could probably just use an easier method and derive the slope of the line, increment the X value each loop, crunch the new Y value, then display the bullet.
-
So no one knows how to follow along Bresenham's line algorithm?
Edit: Qwerty will you rate that one back down? (to 0 not -1 :P)
-
Michael's code *is* Bresenham's Line algorithm.
-
I think i need to sleep now. I am not processing this well.
-
or if you know the angle the tank is shooting at, use sin(angle) as your y increment and cos(angle) as your x increment.
-
or if you know the angle the tank is shooting at, use sin(angle) as your y increment and cos(angle) as your x increment.
I haven't been in calculus yet.
*yaa summer school ;) (getting ahead, not catching up)
-
or if you know the angle the tank is shooting at, use sin(angle) as your y increment and cos(angle) as your x increment.
Wouldn't that get you a fraction?
Or does it round well?
-
or if you know the angle the tank is shooting at, use sin(angle) as your y increment and cos(angle) as your x increment.
Wouldn't that get you a fraction?
Or does it round well?
sin and cos return -127 through 128 (or something like that)
Edit: *In axe
-
or if you know the angle the tank is shooting at, use sin(angle) as your y increment and cos(angle) as your x increment.
Wouldn't that get you a fraction?
Or does it round well?
sin and cos return -127 through 128 (or something like that)
Edit: *In axe
*Facepalm
-
You shouldn't need any complex line algorithm. Try this, it should animate the sprite "Pic1" moving from (X,Y) to (A,B) in S steps.
:A-X*256//S->C
:B-Y*256//S->D
:For(L,0,S)
:ClrDraw
:Pt-On(C*L//256+X,D*L//256+Y,Pic1)
:DispGraph
:Pause 50
:End
EDIT: Fixed, I forgot the divisions had to be signed.
-
/me hugs Quigibo
I appreciate this so much.
I would have spent many frustrated hours trying to figure all this out
-
or if you know the angle the tank is shooting at, use sin(angle) as your y increment and cos(angle) as your x increment.
Wouldn't that get you a fraction?
Or does it round well?
sin and cos return -127 through 128 (or something like that)
Edit: *In axe
*Facepalm
No, not on Omnimaga.
-
Here's an easy solution:
Draw the line on the backbuffer. Then, use a loop with pixel testing on the back buffer to determine where to draw the sprite next.
-
or if you know the angle the tank is shooting at, use sin(angle) as your y increment and cos(angle) as your x increment.
Wouldn't that get you a fraction?
Or does it round well?
sin and cos return -127 through 128 (or something like that)
Edit: *In axe
*Facepalm
No, not on Omnimaga.
I am not allowed to express disgust at my own stupidity on Omnimaga? Oh.
/me shrugs
@SirCmpwn and Quigbo: Those are awesome solutions! I never would have thought of them.
-
Oh, it was because it was pretty hard to detect if the facepalm was directed at yourself or happybobjr. In the first case it might be fine, although in your case it was not clear because Facepalm is all that your post contained, so it's subject to misinterpretation from other people, who might think it's directed at Happybobjr (and see it as out of line)
-
Oh, it was because it was pretty hard to detect if the facepalm was directed at yourself or happybobjr. In the first case it might be fine, although in your case it was not clear because Facepalm is all that your post contained, so it's subject to misinterpretation from other people, who might think it's directed at Happybobjr (and see it as out of line)
Huh. I didn't even know that you could direct facepalm at others. Well, lesson learned -- one-liners are subject to misinterpretation.
-
Yeah it's possible. If someone asks a question to gain help and you reply "*facepalm*", it generally implies you find the person stupid. Someone here did that once, although the thing is that someone might use Facepalm towards someone but not necessarily mean to be offensive. Since it can be, however, this is why I personally avoid using it or append something after it implying it was directed at me. Text can be confusing when it comes to transmitting emotions sometimes. X.x
-
Yeah text can be finicky when dealing with only a single word x.x Well I really like quigibo's solution! Nice job! :D
-
It works perfectly. I'm still trying to understand it, but i haven't gotten another look this morning after i have woken up. :)
I have learned that/me "...text"
or
smilies really help show how you are meant to interpret text. I would have been banned long ago if i didn't put a :P near most of my jokes ;)