Menu

Voir les contributions

Cette section vous permet de consulter les contributions (messages, sujets et fichiers joints) d'un utilisateur. Vous ne pourrez voir que les contributions des zones auxquelles vous avez accès.

Voir les contributions Menu

Messages - faeldaniel

#16
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
#17
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
#18
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.
#19
Thank alekmaul will check and test, thanks
#20
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?
#21
I came to another conclusion, in example "Transparency" I changed the code default for:


      // Initialize SNES
consoleInit();

// Copy tiles to VRAM
bgInitTileSet(0, &LandTiles, &LandPalette, 1, (&LandTiles_end - &LandTiles), (&LandPalette_end - &LandPalette), BG_16COLORS, 0x0000);
bgInitTileSet(1, &CloudTiles, &CloudPalette, 0, (&CloudTiles_end - &CloudTiles), (&CloudPalette_end - &CloudPalette),  BG_4COLORS, 0x1000);

// Copy Map to VRAM
bgInitMapSet(0, &Maps, (&Maps_end - &Maps),SC_32x32, 0x2000);
bgInitMapSet(1, &Mapsc, (&Mapsc_end - &Mapsc),SC_32x32, 0x2400);

// Now Put in 16 color mode and put cloud on top of screen
setMode(BG_MODE1, BG3_MODE1_PRORITY_HIGH); bgSetDisable(2); 

// Set BG3 SubScreen and
bgSetEnableSub(1);

// enable Subscreen Color ADD/SUB and Color addition on BG1 and Backdrop color
setColorEffect(CM_SUBBGOBJ_ENABLE, CM_MSCR_BACK | CM_MSCR_BG1);




its working normally, BG1 front in BG0, but coment this parte the code:


      // Initialize SNES
consoleInit();

// Copy tiles to VRAM
bgInitTileSet(0, &LandTiles, &LandPalette, 1, (&LandTiles_end - &LandTiles), (&LandPalette_end - &LandPalette), BG_16COLORS, 0x0000);
bgInitTileSet(1, &CloudTiles, &CloudPalette, 0, (&CloudTiles_end - &CloudTiles), (&CloudPalette_end - &CloudPalette),  BG_4COLORS, 0x1000);

// Copy Map to VRAM
bgInitMapSet(0, &Maps, (&Maps_end - &Maps),SC_32x32, 0x2000);
bgInitMapSet(1, &Mapsc, (&Mapsc_end - &Mapsc),SC_32x32, 0x2400);

// Now Put in 16 color mode and put cloud on top of screen
setMode(BG_MODE1, BG3_MODE1_PRORITY_HIGH); bgSetDisable(2); 

// Set BG3 SubScreen and
//bgSetEnableSub(1);

// enable Subscreen Color ADD/SUB and Color addition on BG1 and Backdrop color
//setColorEffect(CM_SUBBGOBJ_ENABLE, CM_MSCR_BACK | CM_MSCR_BG1);




The BG1 is behind BG0. I read something about "Main screen" and "Sub screen".

As in this example would be  BG0 in front of the BG1 without transparency in BG_MODE1? it is thus not:

..
bgInitTileSet(1, &LandTiles, &LandPalette, 1, (&LandTiles_end - &LandTiles), (&LandPalette_end - &LandPalette), BG_16COLORS, 0x0000);
bgInitTileSet(0, &CloudTiles, &CloudPalette, 0, (&CloudTiles_end - &CloudTiles), (&CloudPalette_end - &CloudPalette),  BG_4COLORS, 0x1000);

// Copy Map to VRAM
bgInitMapSet(1, &Maps, (&Maps_end - &Maps),SC_32x32, 0x2000);
bgInitMapSet(0, &Mapsc, (&Mapsc_end - &Mapsc),SC_32x32, 0x2400);
..


#22
you refer to it?


while(1) {
...
...
if (move) bgSetScroll(0, scrX,scrY);

//this is refreshing oam memory?
oamSet(0,  mychar.x, mychar.y,  mychar.priority, mychar.direcionSpriter, 0, sprTiles[mychar.positionOffSetSpriter], 0);

WaitForVBlank();
}



In background mode 2
setMode(BG_MODE2,0);
work as I want

Layer 0
Sprite
Layer 1


but mode 2 only has two layers :'(, different mode 1 having three layers .
#23
I made many tests, discovered that this is a problem of lib, because I came to this conclusion? as you can see bgSet trees is 0, so in theory the sprite set as priority 1 would be in front from the trees.
When I start the sprite priority 0 or 1, the sprite is always behind the trees, look this code:


mychar.priority = 0;

//Init spite
oamInitGfxSet(&gfxpsrite, (&gfxpsrite_end - &gfxpsrite), &palsprite, 0, 0x0000, OBJ_SIZE32);
oamSet(0,  mychar.x, mychar.y,  mychar.priority, 0, 0, 0, 0);
oamSetEx(0, OBJ_LARGE, OBJ_SHOW);

//Init Map
bgInitTileSet(0, &patterns, &palette, 0, (&patterns_end - &patterns), 16*2, BG_16COLORS, 0x6000);
bgInitMapSet(0, &map, (&map_end - &map), SC_64x64, 0x5000);


Prints

mychar.priority = 0;


mychar.priority = 1;


but when put as priority 2 sprite goes to the front from the trees

mychar.priority = 2;



alekmaul have any idea what you can this happening?
#24
Look this brothers:  ;D

http://www.youtube.com/watch?v=dWz7ZWBXdcU

The Graphics is bad  ;) , i am studying color palettes, however this to get an idea of what I intend to do, this case I'll add the character to stay behind the trees. In the future, with an awesome graphic artist, the game will have beautiful graphics.  ::)

I buy the Pier Solar for Sega Genesis saw how far we can get with dedication, the boss of the project is a Brazilian like myself.

alekmaul i loved Ultima, i have this game for Nes ;) i search this games for other consoles.

Waiting for that games too.
#25
I want to develop a game rpg, this technique with sprites between bgs who would want to put trees on top of the sprite thus creating a depth effect, i will make new test with this idea and will post the results
#26
yes, oddly only works with this code I quoted, with your code:


...
oamSet(0,  mycharKyle.x, mycharKyle.y, 0, 0, 0, sprTiles[mycharKyle.positionOffSetSpriter], 0);
...

or

..
oamSet(0,  mycharKyle.x, mycharKyle.y, 1, 0, 0, sprTiles[mycharKyle.positionOffSetSpriter], 0);
..


Stands behind and with that always stays in front


..
oamSet(0,  mycharKyle.x, mycharKyle.y, 2, 0, 0, sprTiles[mycharKyle.positionOffSetSpriter], 0);
..

#27
Thanks Brother it worked perfectly, I believe that had not achieved because the MODE1 the Bg 3 only works with 4 colors however got the result you want to see



Code:

bgInitTileSet(2, &patterns_bg, &palette_bg, 4, (&patterns_end_bg - &patterns_bg), (&palette_end_bg - &palette_bg), BG_4COLORS, 0x6000);
bgInitTileSet(0, &patterns_fence, &palette_fence, 5, (&patterns_end_fence - &patterns_fence), (&palette_end_fence - &palette_fence), BG_16COLORS, 0x5000);

bgInitMapSet(2, &map_bg, (&map_end_bg - &map_bg),SC_32x32, 0x4800);
bgInitMapSet(0, &map_fence, (&map_end_fence - &map_fence),SC_32x32, 0x4000);

oamInitGfxSet(&gfxpsrite_kyle_1, (&gfxpsrite_end_kyle_1 - &gfxpsrite_kyle_1), &palsprite_kyle_1, 0, 0x0000, OBJ_SIZE32);
oamSet(0,  mycharKyle.x, mycharKyle.y, 1, 0, 0, sprTiles[mycharKyle.positionOffSetSpriter], 0);
oamSetEx(0, OBJ_LARGE, OBJ_SHOW);

setMode(BG_MODE1, 0);


However lost background-1 and he has 16 colors that makes the background even more beautiful, is it not possible through the previous code?


#28
had already read it, I thought this was only for the priority Gfxs (sprites) and did not work with the BGS, now that quoted calmly read again the documentation can be really so, however I believe that had already tried.

priority =  priority relative to BG : 0 for Low and 3 is the highest

test again and post the result
#29
Watch this video:
http://www.youtube.com/watch?v=kSPknysJaVY

One of the my tests with sprites and background, it was perfect  ;), would like to put an the spriter BG0 between BG1 and in this example it stayed behind the BG0 and BG1, this is part of my code:


// Copy tiles to VRAM
bgInitTileSet(1, &patterns_bg, &palette_bg, 3, (&patterns_end_bg - &patterns_bg), (&palette_end_bg - &palette_bg), BG_16COLORS, 0x6000);
bgInitTileSet(0, &patterns_fence, &palette_fence, 4, (&patterns_end_fence - &patterns_fence), (&palette_end_fence - &palette_fence), BG_16COLORS, 0x5000);

// Copy Map to VRAM
bgInitMapSet(1, &map_bg, (&map_end_bg - &map_bg),SC_32x32, 0x4800);
bgInitMapSet(0, &map_fence, (&map_end_fence - &map_fence),SC_32x32, 0x4000);

//My Char Kyle Blackthorne
oamInitGfxSet(&gfxpsrite_kyle_1, (&gfxpsrite_end_kyle_1 - &gfxpsrite_kyle_1), &palsprite_kyle_1, 0, 0x0000, OBJ_SIZE32);
oamSet(0,  mycharKyle.x, mycharKyle.y, 0, 0, 0, sprTiles[mycharKyle.positionOffSetSpriter], 0);
oamSetEx(0, OBJ_LARGE, OBJ_SHOW);

setMode(BG_MODE1, 0);  bgSetDisable(2);


With this code he stands in front of all background

oamSet(0,  mycharKyle.x, mycharKyle.y, 3, 0, 0, sprTiles[mycharKyle.positionOffSetSpriter], 0);

I would like to stay sprite between background.  ;D
#30
Ok  ;D
Implement in an upcoming release of the lib then, got what I wanted, including the function subString(text, start, length) because it was what I needed, although only work with point, after all the sprintf supports only points.
My code:

char *returnCharsPointMultipleArguments(char *out1, char *out2){

char *outStringPoint;
sprintf(outStringPoint,"%s%s", out1, out2);

return outStringPoint;
}

char *out1Point = "fael";
char *out2Point = "daniel";

consoleDrawText(1,1, "this is union in return: %s", returnCharsPointMultipleArguments(out1Point, out2Point));