LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Sprite Width callback

Root / Programming Questions / [.]

BeautySoapCreated:
Is there a way to find out the current width (or height for that matter), in pixels, of a sprite that has been modified with SPSCALE? Using SPDEF ...OUT ... gives you the sprite's unmodified W and/or H, and SPSCALE ... OUT ... gives you the magnification factor. You could multiply those two things, but then to get a discrete number of pixels, do you FLOOR or ROUND? Which one mimics the way SPSCALE rounds? Isn't there some more direct way to get the current dimensions of a sprite without recalculating it oneself? Thanks, if anyone has any light to shed on this.

If I'm reading the documentation correctly, you can use SPCOL to enable a collision box for the sprite and have it auto-adjust with scaling. Then at any point you should be able to use SPCOL OUT to get the x, y, width, and height of the collision box.

If I'm reading the documentation correctly, you can use SPCOL to enable a collision box for the sprite and have it auto-adjust with scaling. Then at any point you should be able to use SPCOL OUT to get the x, y, width, and height of the collision box.
Are you sure it adjusts? It sounds to me like it returns the same values set in SPCOL, which means it does not adjust for scale changes this way. By the way, BeautySoap, does it matter if the sprite has been rotated? Because that complicated things greatly.

Well, if you set the 'scale adjustment' parameter to 'true' when you set SPCOL, then it sounds like the collision box should scale along with any SPSCALE commands. But when I try SPCOL ...OUT ..., it actually does report the initial value as NeatNit suspected (although to me, honestly, from the documentation it doesn't sound like it would do that). What am I not seeing?
SPSET 0,0,0,16,16
SPCOL 0,TRUE
SPCALE 0,3,3
SPCOL 0 OUT SPX,SPY,SPW,SPH,SPSC
SPW and SPH are 16,16, not 48,48. SPSC is indeed 1 ('true') confirming that it it is (suppposedly) scaling the hitbox during the SPSCALE. As for rotation, I don't need it for what I was trying to do when the question came up, but I do think it would be better if the system provided a way to get the real X and Y extent of a rotated sprite.

well to get the corrected X Y W H values, my guess is you can just multiply them by the scale. Going off of your test code:
SPSET 0,0,0,16,16
SPCOL 0,TRUE
SPCALE 0,3,3
SPCOL 0 OUT SPX,SPY,SPW,SPH,SPSC
SPSCALE 0 OUT SPSCX, SPSCY
SPX = SPX * SPSCX
SPY = SPY * SPSCY
SPW = SPW * SPSCX
SPH = SPH * SPSCY
But as you mentioned, these values would have to be either floored or rounded. If I had to guess, I'd say they were probably floored, but the only way to be sure is to test. You can do this by testing with SPHITRC until you find the exact edge of the collision. I'd do it myself if I had SB, since it just so happens I need this info for my own project as well. Let me know what you find out! Edit: fixed code according to calc84maniac's correction below

Actually, SPSC only returns TRUE or FALSE for the scaling. You'd have to do SPSCALE 0 OUT SCX,SCY and then scale SPX and SPW by SCX and scale SPY and SPH by SCY. It would be pretty easy to make a function to do this (conditionally applying scale based on the boolean in SPSC).

Ah, right. I'll edit my previous post to fix it.

It's too bad that didn't work. It'll take some time to test how SPCALE rounds. I'll post my results when I do, though. By the way, as long as we're just multiplying the initial dim by the scaling factor, we don't need to invoke SPCOL at all. The initial W,H can be gotten from "SPDEF...OUT..."