I am having trouble getting two sprites to show on screen. My goal is to attempt to get two square sprites to appear on screen.
Here is the error image:
Now, I have tried constantly to fix this, but to no avail. As far as I know, it should be working as I've assigned different Ram and VRAM GFXs, and different Ram and VRAM Pal IDs for each sprite.
I've made C++ classes for both objects. The code is shown here:
Player.h
FoodObject.h
main.cpp
Any idea as to what could be causing this issue?
Here is the error image:
Now, I have tried constantly to fix this, but to no avail. As far as I know, it should be working as I've assigned different Ram and VRAM GFXs, and different Ram and VRAM Pal IDs for each sprite.
I've made C++ classes for both objects. The code is shown here:
Player.h
C++:
#ifndef PLAYER_H
#define PLAYER_H
#include <nds.h>
#include <nf_lib.h>
class Player {
public:
Player() {
}
Player(s16 x_pos, s16 y_pos, s16 width, s16 height, const char* name, u8 screen, u16 palid, u16 gfxid, u16 vram, u16 vramPALSLOT, u16 sprID)
{
x = x_pos;
y = y_pos;
w = width;
h = height;
sprite_name = name;
player_screen = screen;
gfxid = gfxid;
palid = palid;
vramGFX = vram;
vrampalSLOT = vramPALSLOT;
spriteID = sprID;
}
void createSprite()
{
NF_LoadSpriteGfx(sprite_name,gfxid,w,h);
NF_LoadSpritePal(sprite_name,palid);
NF_VramSpriteGfx(player_screen,gfxid,vramGFX,TRUE);
NF_VramSpritePal(player_screen,palid,vrampalSLOT);
}
void moveX(s16 moveAmount) {
x+=moveAmount;
}
void moveY(s16 moveAmount) {
y+=moveAmount;
}
void moveSprite() {
NF_CreateSprite(player_screen,spriteID,vramGFX,vrampalSLOT,x,y);
}
protected:
s16 x;
s16 y;
s16 w;
s16 h;
const char* sprite_name;
u8 player_screen;
u16 gfxid;
u16 palid;
u16 vramGFX;
u16 vrampalSLOT;
u16 spriteID;
};
#endif //PLAYER_H
FoodObject.h
C++:
#ifndef FOODOBJECT_H
#define FOODOBJECT_H
#include <nds.h>
#include <nf_lib.h>
#include "Player.h"
class FoodObject : public Player {
public:
FoodObject(s16 x_pos, s16 y_pos, s16 width, s16 height, const char* name, u8 screen, u16 gfxID, u16 palID, u16 vram, u16 vramPALSLOT, u16 sprID)
{
x = x_pos;
y = y_pos;
w = width;
h = height;
enemy_name = name;
enemy_screen = screen;
gfxid = gfxid;
palid = palid;
vramGFX = vram;
vrampalSLOT = vramPALSLOT;
spriteID = sprID;
}
// void createSprite()
// {
// NF_LoadSpriteGfx(sprite_name,gfxid,w,h);
// NF_LoadSpritePal(sprite_name,palid);
// NF_VramSpriteGfx(player_screen,ram,vram,false);
// NF_VramSpritePal(player_screen,vrampalID,vrampalSLOT);
// }
// void moveX(s16 moveAmount) {
// x+=moveAmount;
// }
// void moveY(s16 moveAmount) {
// y+=moveAmount;
// }
void moveSprite() {
NF_CreateSprite(player_screen,spriteID,vramGFX,vrampalSLOT,x,y);
}
private:
const char* enemy_name;
u8 enemy_screen;
};
#endif
main.cpp
C++:
#include <nds.h>
#include <nf_lib.h>
#include "Player.h"
#include "FoodObject.h"
void initSystem() {
NF_Set2D(0,0);
NF_Set2D(0,1);
NF_InitTiledBgBuffers();
NF_InitTiledBgSys(0);
NF_InitSpriteBuffers();
NF_InitSpriteSys(0);
NF_SetRootFolder("NITROFS");
}
int main() {
initSystem();
NF_LoadTiledBg("clearbackground","Background",256,256);
NF_CreateTiledBg(0,3,"Background");
Player player1(256/2 - 16/2,192 - 35,16,16,"box",0,0,0,0,0,0);
FoodObject foodObj(256/2 - 16/2,0,16,16,"spr",0,64,1,10,3,21);
player1.createSprite();
foodObj.createSprite();
// player1.moveSprite();
// foodObj.moveSprite();
consoleDemoInit();
while (1)
{
scanKeys();
NF_SpriteOamSet(0);
swiWaitForVBlank();
oamUpdate(&oamMain);
// foodObj.moveY(3);
// foodObj.moveSprite();
// if (KEY_LEFT & keysHeld())
// {
// player1.moveX(-5);
// player1.moveSprite();
// }
// else if (KEY_RIGHT & keysHeld())
// {
// player1.moveX(5);
// player1.moveSprite();
// }
}
return 0;
}
Any idea as to what could be causing this issue?