#53707 - QuantumDoja - Sat Sep 10, 2005 9:20 pm
Im having a problem with moving my sprite just off the screen left, the problem is, i have a sprite 64 by 64, and the sprite doesnt acctually start until 10 pixels in....so i want the sprite to move an extra 10 pixels left when the sprite bounding box hits left edge of the screen....so
Code: |
if (keyDown(KEY_LEFT)) {
if (PlayerSprite.x > 501 && PlayerSprite.x < 511) {
//sprite should be perfectly alligned left
} else {
PlayerSprite.x--;
}
}
|
the problem is the line "if (PlayerSprite.x > 501 && PlayerSprite.x < 511) {" - it never evaluates to true, so the else keeps on getting fired.
_________________
Chris Davis
#53710 - sajiimori - Sat Sep 10, 2005 9:55 pm
Print the value of x each tick so you can see what's happening. Off the top of my head, maybe x is signed.
#53711 - Touchstone - Sat Sep 10, 2005 11:11 pm
Edit: Removed my reply. Not only did I misunderstand the question, I managed to formulate my answer completely wrong. :)
_________________
You can't beat our meat
Last edited by Touchstone on Sun Sep 11, 2005 12:47 am; edited 1 time in total
#53713 - DekuTree64 - Sun Sep 11, 2005 12:19 am
What you want is called a hotspot. It's sort of a reference point for your sprite's position.
First you'll want to add a couple new variables to your sprite structure for the hotspot x/y. For this case set hotspotX to 10, and hotspotY to 0.
Then when you go to position the actual OAM for the sprite, subtract the hotspot offset from the actual position:
Code: |
oam.attr1 = ((PlayerSprite.x - PlayerSprite.hotspotX) & 511);
oam.attr0 = ((PlayerSprite.y - PlayerSprite.hotspotY) & 255); |
The idea is to make your PlayerSprite.x and y refer to the hotspot position, rather than the top left corner. That way you can just make sure PlayerSprite.x doesn't go below 0 to get the effect you described.
You can set the hotspot to anything you want, like where the character's feet are, or on the handle of a sword for easy positioning at a hand. Just make sure you also take the hotspot into account when doing collision detection and stuff.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku
#53730 - tepples - Sun Sep 11, 2005 7:40 am
DekuTree64 wrote: |
You can set the hotspot to anything you want, like where the character's feet are, or on the handle of a sword for easy positioning at a hand. |
The hotspot can vary over time, so you may want to associate the hotspot to each cel.
And you might actually want to associate two hotspots to each sprite cel. If you're familiar with Clickteam products (Klik n Play, The Games Factory, Multimedia Fusion), these are called "hot spot" (used for positioning the sprite itself) and "action point" (generally used for positioning another sprite connected to a sprite).
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#53744 - QuantumDoja - Sun Sep 11, 2005 12:49 pm
Thanks :-)
_________________
Chris Davis