Auteur Sujet: Sprites - X Y negative coordinates  (Lu 10069 fois)

0 Membres et 1 Invité sur ce sujet

Hors ligne faeldaniel

  • Newbie
  • *
  • Messages: 34
    • Voir le profil
Sprites - X Y negative coordinates
« le: 07 juin 2013 à 20:24:23 »
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?

Hors ligne alekmaul

  • Administrator
  • Hero Member
  • *****
  • Messages: 1149
    • Live Messenger (MSN) - alekmaul@hotmail.fr
    • Voir le profil
    • PortableDev
    • E-mail
Re : Sprites - X Y negative coordinates
« Réponse #1 le: 24 juin 2013 à 14:21:00 »
Hi,
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.

Hors ligne faeldaniel

  • Newbie
  • *
  • Messages: 34
    • Voir le profil
Re : Sprites - X Y negative coordinates
« Réponse #2 le: 27 juin 2013 à 20:31:18 »
Thank alekmaul will check and test, thanks

Hors ligne alekmaul

  • Administrator
  • Hero Member
  • *****
  • Messages: 1149
    • Live Messenger (MSN) - alekmaul@hotmail.fr
    • Voir le profil
    • PortableDev
    • E-mail
Re : Sprites - X Y negative coordinates
« Réponse #3 le: 02 juillet 2013 à 06:20:26 »
take the last version from googlecode, i chnaged some things regarding sprite management.

Hors ligne faeldaniel

  • Newbie
  • *
  • Messages: 34
    • Voir le profil
Re : Sprites - X Y negative coordinates
« Réponse #4 le: 05 juillet 2013 à 05:19:40 »
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.
« Modifié: 05 juillet 2013 à 05:23:44 par faeldaniel »

Hors ligne alekmaul

  • Administrator
  • Hero Member
  • *****
  • Messages: 1149
    • Live Messenger (MSN) - alekmaul@hotmail.fr
    • Voir le profil
    • PortableDev
    • E-mail
Re : Sprites - X Y negative coordinates
« Réponse #5 le: 05 juillet 2013 à 06:33:42 »
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.

Hors ligne faeldaniel

  • Newbie
  • *
  • Messages: 34
    • Voir le profil
Re : Sprites - X Y negative coordinates
« Réponse #6 le: 05 juillet 2013 à 15:14:13 »
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
« Modifié: 05 juillet 2013 à 20:16:35 par faeldaniel »

Hors ligne alekmaul

  • Administrator
  • Hero Member
  • *****
  • Messages: 1149
    • Live Messenger (MSN) - alekmaul@hotmail.fr
    • Voir le profil
    • PortableDev
    • E-mail
Re : Sprites - X Y negative coordinates
« Réponse #7 le: 07 juillet 2013 à 21:14:10 »
yep, so i thought that it was fixed ... :(
could you please post a source code to help me to investigate your problem

Hors ligne faeldaniel

  • Newbie
  • *
  • Messages: 34
    • Voir le profil
Re : Sprites - X Y negative coordinates
« Réponse #8 le: 09 juillet 2013 à 04:01:46 »
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:

http://youtu.be/U_6YaqWhKMA


#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
consoleInit();

// 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);

//new
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 ;-)
WaitForVBlank();

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

// 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;
}
monster.anim_frame++;
if(monster.anim_frame >= FRAMES_PER_ANIMATION){
monster.anim_frame = 0;

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

}
}

// 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);

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


// Wait VBL 'and update sprites too ;-) )
WaitForVBlank();
}
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
« Modifié: 09 juillet 2013 à 04:15:40 par faeldaniel »

Hors ligne alekmaul

  • Administrator
  • Hero Member
  • *****
  • Messages: 1149
    • Live Messenger (MSN) - alekmaul@hotmail.fr
    • Voir le profil
    • PortableDev
    • E-mail
Re : Sprites - X Y negative coordinates
« Réponse #9 le: 13 juillet 2013 à 08:23:54 »
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 ;) !

Hors ligne faeldaniel

  • Newbie
  • *
  • Messages: 34
    • Voir le profil
Re : Sprites - X Y negative coordinates
« Réponse #10 le: 14 juillet 2013 à 05:26:13 »
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

Hors ligne alekmaul

  • Administrator
  • Hero Member
  • *****
  • Messages: 1149
    • Live Messenger (MSN) - alekmaul@hotmail.fr
    • Voir le profil
    • PortableDev
    • E-mail
Re : Sprites - X Y negative coordinates
« Réponse #11 le: 15 juillet 2013 à 07:44:48 »
OK, I did the 1st fix in ASM. It is in google code. Need to work now on SetXYEx ...