 |
|
 |
|
| Sprite Programming |
|
Forum Index - SMW Hacking - General SMW Hacking Help - Tutorials - Sprite Programming |
|
|
|
|
| Posted on 2011-02-05 01:21:55 PM |
Link | Quote |
|
Originally posted by Ramp202@link - you don't return from the graphics routine. (need a RTS)
one day i'm going to suicide... (-_-")
thanks
ok , now it doesn't brick the rom , but i can see nothing, it has no GFX...
|
| Last edited on 2011-02-05 03:35:56 PM by linkunarre. |
|
| Posted on 2011-02-05 10:37:32 PM |
Link | Quote |
|
Then your problem is here:
QuoteGraphics: JSR GET_DRAW_INFO
GET_DRAW_INFO:
Why is GET_DRAW_INFO here? It's supposed to be a separate routine in the file. Get it from here and paste it at the end of the file, and removed the GET_DRAW_INFO label just below the graphics routine.
|
|
| Posted on 2011-02-06 06:30:31 AM |
Link | Quote |
|
it has to be something like this?
Codedcb "INIT"
RTL
dcb "MAIN"
JSR Graphics ; I've added this label. We'll jump here to draw the graphics.
RTL ; After drawing the graphics, end our code.
;===================================
; GRAPHICS ROUTINE HERE
;===================================
Graphics: JSR GET_DRAW_INFO
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; GET_DRAW_INFO
; This is a helper for the graphics routine. It sets off screen flags, and sets up
; variables. It will return with the following:
;
; Y = index to sprite OAM ($300)
; $00 = sprite x position relative to screen boarder
; $01 = sprite y position relative to screen boarder
;
; It is adapted from the subroutine at $03B760
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SPR_T1 dcb $0C,$1C
SPR_T2 dcb $01,$02
GET_DRAW_INFO STZ $186C,x ; reset sprite offscreen flag, vertical
STZ $15A0,x ; reset sprite offscreen flag, horizontal
LDA $E4,x ; \
CMP $1A ; | set horizontal offscreen if necessary
LDA $14E0,x ; |
SBC $1B ; |
BEQ ON_SCREEN_X ; |
INC $15A0,x ; /
ON_SCREEN_X LDA $14E0,x ; \
XBA ; |
LDA $E4,x ; |
REP #$20 ; |
SEC ; |
SBC $1A ; | mark sprite invalid if far enough off screen
CLC ; |
ADC.W #$0040 ; |
CMP.W #$0180 ; |
SEP #$20 ; |
ROL A ; |
AND #$01 ; |
STA $15C4,x ; /
BNE INVALID ;
LDY #$00 ; \ set up loop:
LDA $1662,x ; |
AND #$20 ; | if not smushed (1662 & 0x20), go through loop twice
BEQ ON_SCREEN_LOOP ; | else, go through loop once
INY ; /
ON_SCREEN_LOOP LDA $D8,x ; \
CLC ; | set vertical offscreen if necessary
ADC SPR_T1,y ; |
PHP ; |
CMP $1C ; | (vert screen boundry)
ROL $00 ; |
PLP ; |
LDA $14D4,x ; |
ADC #$00 ; |
LSR $00 ; |
SBC $1D ; |
BEQ ON_SCREEN_Y ; |
LDA $186C,x ; | (vert offscreen)
ORA SPR_T2,y ; |
STA $186C,x ; |
ON_SCREEN_Y DEY ; |
BPL ON_SCREEN_LOOP ; /
LDY $15EA,x ; get offset to sprite OAM
LDA $E4,x ; \
SEC ; |
SBC $1A ; | $00 = sprite x position relative to screen boarder
STA $00 ; /
LDA $D8,x ; \
SEC ; |
SBC $1C ; | $01 = sprite y position relative to screen boarder
STA $01 ; /
RTS ; return
INVALID PLA ; \ return from *main gfx routine* subroutine...
PLA ; | ...(not just this subroutine)
RTS ; /
|
|
| Posted on 2011-02-06 06:57:27 AM |
Link | Quote |
|
Yes, but...
Graphics:
JSR GET_DRAW_INFO
LDA $00
STA $0300,y
LDA $01
STA $0301,y
.....
|
|
| Posted on 2011-02-06 07:12:27 AM |
Link | Quote |
|
maybe like this?
Codedcb "INIT"
RTL
dcb "MAIN"
JSR Graphics ; I've added this label. We'll jump here to draw the graphics.
RTL ; After drawing the graphics, end our code.
;===================================
; GRAPHICS ROUTINE HERE
;===================================
Graphics:
JSR GET_DRAW_INFO
LDA $00
STA $0300,y
LDA $01
STA $0301,y
LDA #$E6
STA $0302,y
LDA #%00000110
ORA $64
STA $0303,y
INY
INY
INY
INY
LDY #$02
LDA #$00
JSL $01B7B3
RTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; GET_DRAW_INFO
; This is a helper for the graphics routine. It sets off screen flags, and sets up
; variables. It will return with the following:
;
; Y = index to sprite OAM ($300)
; $00 = sprite x position relative to screen boarder
; $01 = sprite y position relative to screen boarder
;
; It is adapted from the subroutine at $03B760
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SPR_T1 dcb $0C,$1C
SPR_T2 dcb $01,$02
GET_DRAW_INFO STZ $186C,x ; reset sprite offscreen flag, vertical
STZ $15A0,x ; reset sprite offscreen flag, horizontal
LDA $E4,x ; \
CMP $1A ; | set horizontal offscreen if necessary
LDA $14E0,x ; |
SBC $1B ; |
BEQ ON_SCREEN_X ; |
INC $15A0,x ; /
ON_SCREEN_X LDA $14E0,x ; \
XBA ; |
LDA $E4,x ; |
REP #$20 ; |
SEC ; |
SBC $1A ; | mark sprite invalid if far enough off screen
CLC ; |
ADC.W #$0040 ; |
CMP.W #$0180 ; |
SEP #$20 ; |
ROL A ; |
AND #$01 ; |
STA $15C4,x ; /
BNE INVALID ;
LDY #$00 ; \ set up loop:
LDA $1662,x ; |
AND #$20 ; | if not smushed (1662 & 0x20), go through loop twice
BEQ ON_SCREEN_LOOP ; | else, go through loop once
INY ; /
ON_SCREEN_LOOP LDA $D8,x ; \
CLC ; | set vertical offscreen if necessary
ADC SPR_T1,y ; |
PHP ; |
CMP $1C ; | (vert screen boundry)
ROL $00 ; |
PLP ; |
LDA $14D4,x ; |
ADC #$00 ; |
LSR $00 ; |
SBC $1D ; |
BEQ ON_SCREEN_Y ; |
LDA $186C,x ; | (vert offscreen)
ORA SPR_T2,y ; |
STA $186C,x ; |
ON_SCREEN_Y DEY ; |
BPL ON_SCREEN_LOOP ; /
LDY $15EA,x ; get offset to sprite OAM
LDA $E4,x ; \
SEC ; |
SBC $1A ; | $00 = sprite x position relative to screen boarder
STA $00 ; /
LDA $D8,x ; \
SEC ; |
SBC $1C ; | $01 = sprite y position relative to screen boarder
STA $01 ; /
RTS ; return
INVALID PLA ; \ return from *main gfx routine* subroutine...
PLA ; | ...(not just this subroutine)
RTS ; /
|
| Last edited on 2011-04-18 07:29:50 AM by linkunarre. |
|
| Posted on 2011-02-06 08:26:40 AM |
Link | Quote |
|
Yep, this is correct. But you might want to do this:
dcb "INIT"
RTL
dcb "MAIN"
PHB
PHK
PLB
JSR SpriteCode
PLB
RTL
SpriteCode:
JSR Graphics
*Moar code here*
RTS
Graphics
*Code Here*
|
|
| Posted on 2011-02-06 08:57:55 AM |
Link | Quote |
|
thanks!
E: i've done the 16x16 animated sprite, but it has a glich, look:
here , the code. i know that i put this part of code:
CodePHX
LDA $13
LSR ;\
LSR ; | Slowers the animation rate.
LSR ;/
AND #$01
TAX
LDA TILEMAP,x
STA $0302,y
PLX
in the wrong place:
Codedcb "INIT"
RTL
dcb "MAIN"
PHB ;\
PHK ; | Change the data bank to the one our code is running from.
PLB ; | This is a good practice.
JSR SpriteCode ; | Jump to the sprite's function.
PLB ; | Restore old data bank.
RTL ;/ And return.
;===================================
;Sprite Function
;===================================
RETURN:
RTS
SpriteCode:
JSR Graphics
LDA $14C8,x
CMP #$08
BNE RETURN
LDA $9D
BNE RETURN
JSR SUB_OFF_SCREEN_X0
;===================================
;Graphics Code
;===================================
TILEMAP: dcb $CA,$CC
Graphics:
JSR GET_DRAW_INFO ; Before actually coding the graphics, we need a routine that will get the current sprite's value
; into the OAM.
; The OAM being a place where the tile data for the current sprite will be stored.
LDA $00 ;\
STA $0300,y ;/ Draw the X position of the sprite
LDA $01 ;\
STA $0301,y ;/ Draw the Y position of the sprite
;Those 2 above are always needed to figure out the X/Y position of the sprite
PHX
LDA $13
LSR ;\
LSR ; | Slowers the animation rate.
LSR ;/
AND #$01
TAX
LDA TILEMAP,x
STA $0302,y
PLX
LDA #$07
ORA $64
STA $0303,y ; Write the YXPPCCCT property byte of the sprite
; See this part of the tutorial again for more info
INY ;\
INY ; | The OAM is 8x8, but our sprite is 16x16 ..
INY ; | So increment it 4 times.
INY ;/
LDY #$02 ; Y ends with the tile size .. 02 means it's 16x16
LDA #$00 ; A -> number of tiles drawn - 1.
; I drew only 1 tile so I put in 1-1 = 00.
JSL $01B7B3 ; Call the routine that draws the sprite.
RTS ; Never forget this!
(i don't put the get draw info , and the sub_off_screen, they are obiously at the end of the code)
|
| Last edited on 2011-04-03 01:50:39 PM by linkunarre. |
|
| Posted on 2011-05-02 08:16:07 PM |
Link | Quote |
|
Yea it's a bumpty but i need help.

Weird sprite error. It's fall straight down.
|
|
| Posted on 2011-05-27 07:57:04 AM |
Link | Quote |
|
Thanks man!
and there's a grammar error in the seventh paragraph namely learnt instead of learned. but that's just minor.
THANKS!
|
|
| Posted on 2011-05-27 05:42:12 PM |
Link | Quote |
|
|
"Learned" and "learnt" are both proper spellings.
|
|
| Posted on 2011-09-24 08:07:26 AM |
Link | Quote |
|
I'm trying to make an animated sprite, but it crashes the game when I enter the level.
My Code:
http://pastebin.com/aNSNe33h
EDIT: Never mind I finally got it working and now I'm super happy.
|
| Last edited on 2011-10-04 07:22:11 PM by RainbowLuigi281. |
|
| Posted on 2011-09-24 08:21:39 AM |
Link | Quote |
|
Code
SpriteCode:
JSR Graphics
LDA $14C8,x
CMP #$08
BNE RETURN
LDA $9D
BNE RETURN
JSR SUB_OFF_SCREEN_X0
you need a RTS at the end of your code.
|
| Last edited on 2011-09-24 08:22:08 AM by wiiqwertyuiop. |
|
| Posted on 2011-11-11 12:52:52 PM |
Link | Quote |
|
Iceguy, do you think it would be a good idea to add a note in the "Make use of the extra bit" section that you check different addresses for shooters and generators? When $7FAB10 didn't help me shoot a sprite twice as fast, I checked a generic shooter file and saw it checked $1783 with AND #$40. Looking at a generic generator, that seems to check $18B9 with AND #$40. Granted, I usually have no idea what I'm talking about when it comes to sprite coding, so if I'm missing something obvious, just ignore me :b
I'm sure I've said it before, but for me this is one of the useful tutorials on the site, and I find myself referencing it all the time, even though I usually just make minor edits to existing sprites. Thanks for making it (:
|
|
| Posted on 2011-11-11 01:07:50 PM |
Link | Quote |
|
|
Dont you think its about time to convert this tutorial to xkas? Everything is in TRASM as of now, and a few things could be changed, and add, as well.
|
| Last edited on 2011-11-12 07:54:50 AM by wiiqwertyuiop. |
|
| Posted on 2011-11-11 02:40:52 PM |
Link | Quote |
|
Originally posted by wiiqwertyuiopTRAMS
"Trams" is a valid Swedish word, and it means "nonsense".
Therefore, this is the best typo I have ever seen.
|
|
| Posted on 2011-11-11 06:09:14 PM |
Link | Quote |
|
I made a boss from this tutorial, it inserted it, you cannot jump on it or touch it it just walks through you... immamelia told me to remove the JSR after The suboff screen command, i did and the sprite moved and walked right off screen any help?
EDIT: here is a video...
http://www.youtube.com/watch?v=hv5LEHlIMAg
|
| Last edited on 2011-11-11 08:52:02 PM by tr9536on. |
|
| Posted on 2011-11-12 07:54:18 AM |
Link | Quote |
|
Originally posted by AlcaroOriginally posted by wiiqwertyuiopTRAMS
"Trams" is a valid Swedish word, and it means "nonsense".
Therefore, this is the best typo I have ever seen.
Opps... <.<
*me edits*
|
|
| Posted on 2011-11-14 09:57:04 AM |
Link | Quote |
|
Uh.. I should really check this forum more often.
QuoteIceguy, do you think it would be a good idea to add a note in the "Make use of the extra bit" section that you check different addresses for shooters and generators? When $7FAB10 didn't help me shoot a sprite twice as fast, I checked a generic shooter file and saw it checked $1783 with AND #$40. Looking at a generic generator, that seems to check $18B9 with AND #$40. Granted, I usually have no idea what I'm talking about when it comes to sprite coding, so if I'm missing something obvious, just ignore me :b
Don't worry, you are making sense. Also, good idea, I completely forgot about noting that when writing this tutorial. Thanks for reminding me.
QuoteDont you think its about time to convert this tutorial to xkas? Everything is in TRASM as of now, and a few things could be changed, and add, as well.
Here's the problem: I don't want to 'convert this tutorial to xkas', I want to completely rewrite it but I have no idea when that'll happen. I am sort of dissatisfied with most of the lessons (mainly because my spriting skills weren't that good back then and the explanations could have been slightly better) and the tutorial could greatly be shortened despite many people finding them to be very useful.
QuoteI made a boss from this tutorial, it inserted it, you cannot jump on it or touch it it just walks through you... immamelia told me to remove the JSR after The suboff screen command, i did and the sprite moved and walked right off screen any help?
EDIT: here is a video...
http://www.youtube.com/watch?v=hv5LEHlIMAg
You mean you want the sprite to have interaction with Mario? If so, read lesson 4. If not, please explain what you mean.
|
|
| Posted on 2011-11-17 04:20:05 PM |
Link | Quote |
|
|
Would you mind if I rewrote this for xkas? Obviously I'd put my own spin on it, but I have time to dedicate to something like this so you wouldn't have to worry about it.
|
|
| Posted on 2011-11-17 06:32:53 PM |
Link | Quote |
|
|
What about my ASM tutorial? It will include several sections about making sprites.
|
|
|
|
|
|
|
Forum Index - SMW Hacking - General SMW Hacking Help - Tutorials - Sprite Programming |
|
|
 |
|
 |
The purpose of this site is not to distribute copyrighted material, but to honor one of our favourite games.
Copyright © 2005 - 2013 - SMW Central Legal Information - Link To UsTotal queries: 27
|
|
|
|