Author Topic: Need code help with Sprites  (Read 22208 times)

0 Members and 1 Guest are viewing this topic.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Need code help with Sprites
« Reply #15 on: March 07, 2010, 01:15:47 am »
Well, its the way Asm works, and how the compiler doesn't catch the optimization (which it might in the future ;) ).  All data on the calculator is stored in Binary, which is Base 2.  We work in base 10.  In Base 10, its reeeeeaally easy to multiply or divide by 10, or 100 or 100 ect because all you have to do is move the decimal point around.  Like 143 becomes 1430 if you multiply by 10 and 1540 become 154 if you divide by 10.  This also works in Binary, where multiplying by 2 or dividing by 2 is reeaaaally easy for the calculator to do, because all the calculator has to do is shift the decimal point around, just like in Base 10.

Thats a kinda hackish way to say it without going into more specific asm details :P

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Need code help with Sprites
« Reply #16 on: March 07, 2010, 01:23:26 am »
Hey hey!  It certainly does catch the optimization.  But repeated divisions are only optimized in terms of their speed not size.  Regular division is still less code (if you use it a few times).  That's why its not an automatic optimization, you can choose when you need the extra speed with the downside of larger code.

Very nice explanation by the way :)
« Last Edit: March 07, 2010, 01:23:41 am by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Need code help with Sprites
« Reply #17 on: March 07, 2010, 01:43:49 am »
Oh ok. So this is speed optimization, not size. I get it :) Thanks.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Need code help with Sprites
« Reply #18 on: March 07, 2010, 02:14:11 am »
Being a BASIC programmer, I am used to working under extreme speed limitations, so I will probably go for size as much as possible.

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Need code help with Sprites
« Reply #19 on: March 07, 2010, 05:12:31 am »
Yeah, the majority of programs and games have to use pauses to keep good timing.  There is almost no need for greater speed unless it is actually demanded.  We'll see how far the hardware can be pushed in the next version since it can take advantage of 15MHz calculators.  I'm getting about 125 sprites per frame at 30 fps.  That's without any game mechanics, but that usually only makes up a small fraction of the cpu time anyway.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Need code help with Sprites
« Reply #20 on: March 07, 2010, 05:16:31 am »
Nice

Also, we have to make sure to not make our games run too fast either. We have to take the motion blur on the LCD into account, especially TI-Nspire users.

My first pixelater program, the one that went by multiples of 2, I had to slow down the 8x8 part with a For(Z,0,9000:End (at that time I didn't knew the Pause command), to keep the speed similar to the two other parts. With no pausing, the 8x8 rendered so fast I couldn't see the 4x4 at all

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Need code help with Sprites
« Reply #21 on: March 07, 2010, 11:37:01 am »
Wow, 15mhz is going to be fast!

Awesome explanation Builderboy!  Great job on it! :D

Offline ikemike

  • LV3 Member (Next: 100)
  • ***
  • Posts: 67
  • Rating: +4/-0
  • Hmm.
    • View Profile
Re: Need code help with Sprites
« Reply #22 on: March 16, 2010, 10:32:14 pm »
I'm having some trouble of my own in this bit of code involving sprites... In the (marked as, at least) bolded section, I try to get the sprite to default to the first 8 bits in the pic. It said getKey worked this way in the readme, but it's not working the way I expect it to... Or is "and" glitchy?

It messes up the sprite, which is somewhat disconcerting to me.

Code: [Select]
ClrHome
ClrDraw
DiagnosticOff
'DOWN
[3C245A42A5A55A663C245A42A5A55E603C245A42A5A55A663C245A42A5A57A06→Pic1
'RIGHT
[3824445858582838382444586C6894EC3824445858582838382444585C4894EC→Pic2
'LEFT
[1C24221A1A1A141C1C24221A361629371C24221A1A1A141C1C24221A3A122937→Pic3
'UP
[3C244242A5A55A663C244242A5A55E603C244242A5A55A663C244242A5A57A06→Pic4
1→A
1→B
0→X
Pt-On(A,B,Pic1

While getKey(15)=0
[b]If getKey=1 and getKey(1)≠1:Pt-On(A,B,Pic1)End
If getKey=2 and getKey(2)≠1:Pt-On(A,B,Pic2)End
If getKey=3 and getKey(3)≠1:Pt-On(A,B,Pic3)End
If getKey=4 and getKey(4)≠1:Pt-On(A,B,Pic4)End[/b]
Pause 100
DispGraph
X+1→X
If X=20:0→XEnd
If getKey(1)=1
B+1→B
ClrDraw
Pt-On(A,B,X/5*8+Pic1
End
If getKey(2)=1
A-1→A
ClrDraw
Pt-On(A,B,X/5*8+Pic3
End
If getKey(3)=1
A+1→A
ClrDraw
Pt-On(A,B,X/5*8+Pic2
End
If getKey(4)=1
B-1→B
ClrDraw
Pt-On(A,B,X/5*8+Pic4
End
End

I'm new here, and also a n00b programmer. So yeah.
« Last Edit: March 16, 2010, 10:53:11 pm by ikemike »
Anonymous Legend

Offline cooliojazz

  • Support Staff
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 619
  • Rating: +66/-9
  • I omnoms on your soul
    • View Profile
    • Unreal Phantasies
Re: Need code help with Sprites
« Reply #23 on: March 16, 2010, 10:46:48 pm »
Umm I don't really get most of your code, but getkey=1 and getkey(1)/=1 would be contradictory, since getkey sees what key is pressed and getkey(x) sees if key x is pressed, so you're saying, "If the current key being pressed is down, (one) and down is not being pressed, do this"
You get the blue box with the code tag. [ code]Your code here[ /code]
« Last Edit: March 16, 2010, 10:47:47 pm by cooliojazz »
Spoiler For Random signess:
You can not beat my skills.
Trust me.
So don't even try.
And remember never to trust someone who says, "Trust me."

TI File Editor Progress: Remade in java like a boss. 50% we'll call it? IDK =P
Java Libraries: JIRC - 90% JTIF - 5%
TI Projects: Unreal Notator - -5000%
Nomcraft, a Bukkit mod
Some of the music I write can be found here | The Rest Should Be Here (Bandcamp)

Offline ikemike

  • LV3 Member (Next: 100)
  • ***
  • Posts: 67
  • Rating: +4/-0
  • Hmm.
    • View Profile
Re: Need code help with Sprites
« Reply #24 on: March 16, 2010, 10:49:46 pm »
Hmm... It says in the readme that just getKey is "Expression becomes the last key pressed. It is zero if no keys are pressed.".
I'm trying to say "If (direction button) has been pushed last, and (directional button) is not being pushed at the moment, display (direction-appropriate sprite)".

Since this obviously doesn't work, how else could I do something with the same effect?
« Last Edit: March 16, 2010, 10:56:02 pm by ikemike »
Anonymous Legend

Offline cooliojazz

  • Support Staff
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 619
  • Rating: +66/-9
  • I omnoms on your soul
    • View Profile
    • Unreal Phantasies
Re: Need code help with Sprites
« Reply #25 on: March 16, 2010, 11:00:30 pm »
Sorry, you're right, lol, it i the last key pressed, but I *think* it would still be a contradiction...  plus, i think like in basic, once you test for straight getkey, it resets the last key to 0, so you should store the getkey to something first.  somebody correct if i'm wrong.  And so you're trying to change the sprite only when they release the key basically, not just when pressed?
Spoiler For Random signess:
You can not beat my skills.
Trust me.
So don't even try.
And remember never to trust someone who says, "Trust me."

TI File Editor Progress: Remade in java like a boss. 50% we'll call it? IDK =P
Java Libraries: JIRC - 90% JTIF - 5%
TI Projects: Unreal Notator - -5000%
Nomcraft, a Bukkit mod
Some of the music I write can be found here | The Rest Should Be Here (Bandcamp)

Offline ikemike

  • LV3 Member (Next: 100)
  • ***
  • Posts: 67
  • Rating: +4/-0
  • Hmm.
    • View Profile
Re: Need code help with Sprites
« Reply #26 on: March 16, 2010, 11:02:20 pm »
Right, right, why didn't I think of that before?... Set a variable during the if statement, and use that.

############################

How do you ask if ANY key is being pressed, instead of a specific key? Is there a way?

(edit: merged close double-post)
« Last Edit: March 16, 2010, 11:19:30 pm by DJ Omnimaga »
Anonymous Legend

Offline cooliojazz

  • Support Staff
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 619
  • Rating: +66/-9
  • I omnoms on your soul
    • View Profile
    • Unreal Phantasies
Re: Need code help with Sprites
« Reply #27 on: March 16, 2010, 11:12:23 pm »
1. try to edit instead instead of double-posting if the posts are fairly close together. (like yours)
2. thats what getkey w/o the (x) part does, really.
Spoiler For Random signess:
You can not beat my skills.
Trust me.
So don't even try.
And remember never to trust someone who says, "Trust me."

TI File Editor Progress: Remade in java like a boss. 50% we'll call it? IDK =P
Java Libraries: JIRC - 90% JTIF - 5%
TI Projects: Unreal Notator - -5000%
Nomcraft, a Bukkit mod
Some of the music I write can be found here | The Rest Should Be Here (Bandcamp)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Need code help with Sprites
« Reply #28 on: March 16, 2010, 11:21:08 pm »
(merged double-posts)

Unfortunately, I never messed with getkey yet, I only did special graphical effects and animation routines and modified some examples code, so I cannot help. Hopefully, someone who used it a lot might be able to help, though.

Offline ikemike

  • LV3 Member (Next: 100)
  • ***
  • Posts: 67
  • Rating: +4/-0
  • Hmm.
    • View Profile
Re: Need code help with Sprites
« Reply #29 on: March 16, 2010, 11:21:46 pm »
Sorry, I was afraid people might not have noticed it.
Now the sprites flicker... I have this now:

If getKey=0
If D=1:Pt-On(A,B,Pic1)End
If D=2:Pt-On(A,B,Pic2)End
If D=3:Pt-On(A,B,Pic3)End
If D=4:Pt-On(A,B,Pic4)End
End

Anything wrong with this?
Anonymous Legend