clearifing something up with sprites [SOLVED!]
Re: clearifing something up with sprites
yes I knew that
Last edited by Tomdev on Mon Feb 15, 2010 10:23 pm, edited 1 time in total.
Re: clearifing something up with sprites
ok, so i changed the grit code for backgrounds to work with the newest libnds but it's not working perfectly: i get some graphical glitches here's my code:
but do i have to use BG_BMP8_256x256 instead of TEXTBG_SIZE_256x256
also i don't get where this is standing for BG_TILE_BASE(0) | BG_MAP_BASE(4). sylus said that it was where the graphics where located by offset but how does this exactly work?
Code: Select all
#include <nds.h>
#include "moon.h"
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
// enable the main screen with background 0 active
videoSetMode(MODE_0_2D | DISPLAY_BG0_ACTIVE);
// map bank A for use with the background
vramSetBankA(VRAM_A_MAIN_BG);
// enable background 0 in 256 color mode with a 256x256 map
// BG_TILE_BASE changes the offset where tile data is stored
// BG_MAP_BASE gives the offset to the map data
BGCTRL[0] = BG_TILE_BASE(0) | BG_MAP_BASE(4) | BG_COLOR_256 | BG_BMP8_256x256;
// use dma to copy the tile, map and palette data to VRAM
// CHAR_BASE_BLOCK gives us the actual address of the tile data
// SCREEN_BASE_BLOCK does the same thing for maps
// these should match the BG_TILE_BASE and BG_MAP base numbers above
dmaCopy(moonPal,BG_PALETTE,moonPalLen);
dmaCopy(moonTiles,(void *)CHAR_BASE_BLOCK(0),moonTilesLen);
dmaCopy(moonMap,(void *)SCREEN_BASE_BLOCK(4),moonMapLen);
// finally, hang around in an infinite loop
// using swiWaitForVBlank here puts the DS into a low power loop
while(1) {
swiWaitForVBlank();
}
return 0;
}
also i don't get where this is standing for BG_TILE_BASE(0) | BG_MAP_BASE(4). sylus said that it was where the graphics where located by offset but how does this exactly work?
Re: clearifing something up with sprites
now ok, no backgrounds then(i do not have to load tiled backgrounds in my project) but my question was mainly about sprites. so because the libnds is updated etc. there are some things changed so could someone please post an examples for sprites using grit? and not the whole pataterstuff because the sprites are there loaded with a lot of un needed pointers i think.
Re: clearifing something up with sprites
Although I'm not new to programming, I'm still pretty new to the world of libnds, but maybe i can help.
Grit Code (taken from the patater tutorials)
This "loads" the graphics
This code however only solves part of the problem, as it doesn't give you any real way to manipulate the sprite. I would recommend looking at the example called SpriteAllocationTest.
\devkitPro\examples\nds\Graphics\2D
Grit Code (taken from the patater tutorials)
Code: Select all
# Set the warning/log level to 3
-W3
# Tell grit to include a palette (the first index in it will be transparent)
-p
# Tile the image
-gt
# Set the bit depth to 4 (16 colors)
-gB4
Code: Select all
//loads the palette
dmaCopyHalfWords(DMA_CHANNEL, //0-3
fileNamePal, //grit generated
&SPRITE_PALETTE[0 * 16], // 0 = first palette, 16 = 16 colors
fileNamePalLen); //grit generated
//loads the "sprite"
dmaCopyHalfWords(DMA_CHANNEL,//0-3
fileNameTiles, //grit generated
gfx, //destination (oamAllocateGfx() will return a u16* you can use here)
fileNameTilesLen);//grit generated
\devkitPro\examples\nds\Graphics\2D
Re: clearifing something up with sprites
The SpriteAllocationTest example may be a little difficult to follow, but the SimpleSprite example shows a more straightforward example of oamSet(), which will be a catch all function for setting sprite parameters.
The difficulty is that although Patater has updated his tutorial so that it's compatible with libnds, it doesn't include usage of Dovoto's new sprite functions, which are pretty handy.
The difficulty is that although Patater has updated his tutorial so that it's compatible with libnds, it doesn't include usage of Dovoto's new sprite functions, which are pretty handy.
Re: clearifing something up with sprites
ok thanks for the code, so instead of a mess of pointer to paramaters(in pataters tutorial) you can set them also with oamset during the vbl? and wich handy functions of dovoto do you mean?
and would this code work?:
and would this code work?:
Code: Select all
#include <nds.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
int i;
videoSetMode(MODE_0_2D);
vramSetBankA(VRAM_A_MAIN_SPRITE);
oamInit(&oamMain, SpriteMapping_1D_32, false);
dmaCopyHalfWords(DMA_CHANNEL, //0-3
fileNamePal, //grit generated
&SPRITE_PALETTE[0 * 16], // 0 = first palette, 16 = 16 colors
fileNamePalLen); //grit generated
//loads the "sprite"
dmaCopyHalfWords(DMA_CHANNEL,//0-3
fileNameTiles, //grit generated
gfx = oamAllocateGfx(oam, size, format);, //destination (oamAllocateGfx() will
fileNameTilesLen);//grit generated
while(1) {
oamSet(&oamMain, //main graphics engine context
0, //oam index (0 to 127)
0, 0, //x and y pixle location of the sprite
0, //priority, lower renders last (on top)
0, //this is the palette index if multiple palettes or the alpha value if bmp sprite
SpriteSize_16x16,
SpriteColorFormat_256Color,
gfx, //pointer to the loaded graphics
-1, //sprite rotation data
false, //double the size when rotating?
false); //hide the sprite?
swiWaitForVBlank();
}
return 0;
}
Re: clearifing something up with sprites
Quite honestly, I'm not 100% on which functions are new and which are not. From what I understand, oamInit() is new, and at the very least oamSet().
What is extremely important is that you make the connection between what Patater's tutorial covers and what is being done for us already in the newest libnds.
Patater takes you through creating a SpriteEntry structure, which was the standard way of doing things for what I gather is quite a long time. With libnds 1.3.1 this structure has already been defined for you, two of them in fact, one for each engine.
Would that code work? For the most part, yes I think so. You need to have DMA_CHANNEL defined, or just use 3.
Look again at how oamAllocateGfx is used in the SimpleSprite example and apply that to this. For the 3rd parameter in the second dmaCopyHalfWords you'd likely just have gfx and would have used oamAllocateGfx earlier, with different parameters than what is there. "oam" for instance would either be &oamMain or &oamSub. "fileName" anywhere it occurs I'm assuming would be replaced with the image filename that was converted by grit.
What is extremely important is that you make the connection between what Patater's tutorial covers and what is being done for us already in the newest libnds.
Patater takes you through creating a SpriteEntry structure, which was the standard way of doing things for what I gather is quite a long time. With libnds 1.3.1 this structure has already been defined for you, two of them in fact, one for each engine.
Would that code work? For the most part, yes I think so. You need to have DMA_CHANNEL defined, or just use 3.
Look again at how oamAllocateGfx is used in the SimpleSprite example and apply that to this. For the 3rd parameter in the second dmaCopyHalfWords you'd likely just have gfx and would have used oamAllocateGfx earlier, with different parameters than what is there. "oam" for instance would either be &oamMain or &oamSub. "fileName" anywhere it occurs I'm assuming would be replaced with the image filename that was converted by grit.
Re: clearifing something up with sprites
thanks sylus, i gonna test it when i changed the code. and when is was looking up in the libnds documentation i saw oamset and I thought already: is this not someting easier to manage sprites than in the patater tutorial(when i read that i had no knowledge of pointers so it was very very difficult for me to understand...)
Re: clearifing something up with sprites
ok, so i tested the code no errors, but there was no sprite showing up wahts the problem?:
Code: Select all
#include <nds.h>
#include "test.h"
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
videoSetMode(MODE_0_2D);
vramSetBankA(VRAM_A_MAIN_SPRITE);
oamInit(&oamMain, SpriteMapping_1D_32, false);
u16* gfx = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_256Color);
dmaCopyHalfWords(3, testPal, &SPRITE_PALETTE[0 * 16], testPalLen); //grit generated
dmaCopyHalfWords(3,//0-3
testTiles, //grit generated
gfx, //destination (oamAllocateGfx() will
testTilesLen);//grit generated
while(1) {
oamSet(&oamMain, //main graphics engine context
0, //oam index (0 to 127)
0, 0, //x and y pixle location of the sprite
0, //priority, lower renders last (on top)
0, //this is the palette index if multiple palettes or the alpha value if bmp sprite
SpriteSize_32x32,
SpriteColorFormat_256Color,
gfx, //pointer to the loaded graphics
-1, //sprite rotation data
false, //double the size when rotating?
false); //hide the sprite?
swiWaitForVBlank();
}
return 0;
}
Re: clearifing something up with sprites
About the only thing that I'm thinking may be wrong, is the sprite palette part. I'm pretty sure you're just going to want to use:
or
Which is the same thing. dmaCopy is in HalfWords and uses Channel 3 by default.
on second thought, &SPRITE_PALETTE[0] and SPRITE_PALETTE should pretty well be the same thing in this case... so maybe that's not it. Any chance you can post the graphic you started with and grit rule?
Code: Select all
dmaCopyHalfWords(3, testPal, SPRITE_PALETTE, testPalLen);
Code: Select all
dmaCopy(testPal, SPRITE_PALETTE, testPalLen);
on second thought, &SPRITE_PALETTE[0] and SPRITE_PALETTE should pretty well be the same thing in this case... so maybe that's not it. Any chance you can post the graphic you started with and grit rule?
Who is online
Users browsing this forum: No registered users and 1 guest