Sprites - X Y negative coordinates

Démarré par faeldaniel, 07 Juin 2013 à 20:24:23

« précédent - suivant »

0 Membres et 1 Invité sur ce sujet


Hello Alekmaul,

When we have a new version?  :D

look this, when i am set in coordinates with 0 the sprite disappears :
oamMemory[id + 0] = 0;

if set in coordinates (-50) for example the sprite go to position (200) .
oamMemory[id + 0] = -50;

I would like the coordinates of the sprite corresponds to the size of the background and not 0 to 255, this is possible?


Well, you can put something negative. You must set the hide flash with oamHide that do such thing.
I updated googlecode entries with last version of pvsneslib.
Hope it will help you.


Thank alekmaul will check and test, thanks


take the last version from googlecode, i chnaged some things regarding sprite management.


I get and now im testing in my engine, thanks for contribuition, loved the debug mode in NO$SNS is being very most useful :) .

I try to explain my problem, defined as negative values ​​less than zero or even exceeding the value 255 is reset in screen, for example:
-5 == 250
-25 == 230
325 == 70

I want the sprite gradually disappear from the screen as we see in most games, exactly the same as when you define 253, check that only part of the sprite is visible to another part of this out of the screen.

Basically I need the sprites with positions -25 and 280 where 0 and 255 are the parts visible on the screen.


OK, i understand but I do not have this problem with my current test.
When my x coordinate is more than 240, for a 16x16 sprite, i see only the part on screen.
Could you post a bit of code ?
Perhaps you need to set the high x bit with oamSetXYEx, but it will be slow, the function is not optimized.


i see the function oamSetXYEx what was needed, working in X but bug the sprite, however the idea that this need is.

I found this topic just talking about it and your comment http://forums.nesdev.com/viewtopic.php?p=97047


yep, so i thought that it was fixed ... :(
could you please post a source code to help me to investigate your problem


Sorry for the delay in responding, look this video I found a way to solve this problem, I made a modification to the original code from your example for Animated Sprite I show in the current code and my new code with debug, see the differences:


#include <snes.h>

extern char gfxpsrite, gfxpsrite_end;
extern char palsprite, palsprite_end;

char messtxt[45];

#define FRAMES_PER_ANIMATION 3 // 3 sprites per direction

// The Monster sprite
typedef struct
short x, y;
int gfx_frame;
int state;
int anim_frame;
int flipx;
} Monster;

// The state of the sprite (which way it is walking)
enum SpriteState {W_DOWN = 0, W_UP = 1, W_RIGHT = 2,  W_LEFT = 2};

// Screen dimentions
enum {SCREEN_TOP = -255, SCREEN_BOTTOM = 512, SCREEN_LEFT = -255, SCREEN_RIGHT = 512};

char sprTiles[9]={0,2,4, 6,8,10, 12,14,32};  // Remeber that sprites are interleave with 128 pix width,

int main(void) {
unsigned short pad0,i;
Monster monster = {-30,100};

    // Initialize SNES

// Init Sprites gfx and palette with default size of 16x16
oamInitGfxSet(&gfxpsrite, (&gfxpsrite_end-&gfxpsrite), &palsprite, (&palsprite_end-&palsprite), 0, 0x0000, OBJ_SIZE16);

// Define sprites parameters
//oamSet(0,  monster.x, monster.y, 0, 0, 0, 0, 0);
//oamSetEx(0, OBJ_SMALL, OBJ_SHOW);

oamInitGfxAttr(0x0000, OBJ_SMALL);
oamSetXYEx(0, monster.x, monster.y);

// Now Put in 16 color mode and disable all backgrounds
setMode(BG_MODE1,0); bgSetDisable(0); bgSetDisable(1); bgSetDisable(2);

// Wait VBL 'and update sprites too ;-)

// Wait for nothing :P
while(1) {
// Refresh pad values

// Get current #0 pad
pad0 = padsCurrent(0);

if (pad0) {
// Update sprite with current pad
if(pad0 & KEY_UP) {
if(monster.y >= SCREEN_TOP) monster.y--;
monster.state = W_UP;
monster.flipx = 0;
if(pad0 & KEY_LEFT) {
if(monster.x >= SCREEN_LEFT) monster.x--;
monster.state = W_LEFT;
monster.flipx = 1;
if(pad0 & KEY_RIGHT) {
if(monster.x <= SCREEN_RIGHT) monster.x++;
monster.state = W_LEFT;
monster.flipx = 0;
if(pad0 & KEY_DOWN) {
if(monster.y <= SCREEN_BOTTOM) monster.y++;
monster.state = W_DOWN;
monster.flipx = 0;
if(monster.anim_frame >= FRAMES_PER_ANIMATION){
monster.anim_frame = 0;

sprintf(messtxt,"NEW CODE:  X= %d   Y= %d\n",monster.x, monster.y);


// Now, get current sprite in current animation
monster.gfx_frame = sprTiles[monster.anim_frame + monster.state*FRAMES_PER_ANIMATION ];
//oamSet(0,  monster.x, monster.y, 3, monster.flipx, 0, monster.gfx_frame, 0);

oamSetGfxOffset(0, monster.gfx_frame);
oamSetXYEx(0, monster.x, monster.y);

// Wait VBL 'and update sprites too ;-) )
return 0;

This code works only if the position of the sprite start out screen but do not know if this correct :(.

Found that the position coordinate X or Y is reset when the function oamSetEx (0, OBJ_SMALL, OBJ_SHOW); runs


OK, I See the problem but I think I will update pvsneslib with ASM functions to solve the speed issue we will have if you call all the time SetXYEx.
Need to code now ;) !


Brother it will be wonderful for me, I'll be looking forward to this moment, again thanks for the wonderful work, you have a big fan ;D


OK, I did the 1st fix in ASM. It is in google code. Need to work now on SetXYEx ...