I'm having a bit of trouble with setting the source rectangle for a sprite I'm having. The sprite itself is split up in 4x4 frames just as the normal character sets, and the "@step" variable is equal to either 0, 1, 2 or 3. I have debugged it to make sure that this variable never exceeds 3 or goes below 0, and it does not.
If I do not set a source rectangle with the code, it shows the sprite perfectly fine, but the whole portion of it. I don't know what I'm doing wrong. Might be just something extremely simple that I just can't pinpoint. I have also tried to remove the ox and oy value changes, but all in all I don't see how that'd be a logical fix, anyhow.
Any ideas?
Thanks in advance.
- #--------------------------------------------------------------------------
- # * Set Graphic
- #--------------------------------------------------------------------------
- def set_graphic
- return unless self.visible
- # Obtain width and height of frames
- width = self.bitmap.width / 4
- height = self.bitmap.height / 4
- self.ox = width / 2
- self.oy = height
- # Direction case
- case @dir
- when Left
- self.src_rect.set(@step * width,0,width,height)
- when Right
- self.src_rect.set(@step * width,height,width,height)
- when Jump
- self.src_rect.set(@step * width,height*2,width,height)
- end
- end
Expand to see the code.
If I do not set a source rectangle with the code, it shows the sprite perfectly fine, but the whole portion of it. I don't know what I'm doing wrong. Might be just something extremely simple that I just can't pinpoint. I have also tried to remove the ox and oy value changes, but all in all I don't see how that'd be a logical fix, anyhow.
Any ideas?
Thanks in advance.