Original Post

So, I’m trying to program something here and I’d like to know how to use objects. I’ve read the article on the developer wiki about them and it explains the topic OK, but, there’s no example on how to actually make an object. The only thing I know is that it has something to do with the vbSetObject function, which I looked up in gccVB’s libraries, but I still don’t understand much.

A more functional explanation with example code would be welcome.

8 Replies

You can look at my ManWithBall demo, it includes source code πŸ™‚

It basically involves just copying your object attributes to OAM memory, and then tell the VB how many of the objects you want to display in each world by setting the SPT pointers.

Well I think I partially understand the concept, but I’m sure I’m doing everything wrong so this is my code for displaying character #4 as object #1… which obviously doesn’t work. I really don’t understand palettes and charsegs.

#include "libgccvb.h"
#include "font.h"

int main ()
{
  copymem ((void*)CharSeg3, (void*)FONT, 8192);

  vbSetWorld(31, WRLD_ON|WRLD_OBJ, 0, 0, 0, 0, 0, 0, 384, 224);
  vbSetWorld(30, WRLD_ON, 0, 0, 0, 0, 0, 0, 384, 224);
  vbSetWorld(29, WRLD_END, 0, 0, 0, 0, 0, 0, 0, 0);

  vbDisplayOn();

  vbTextOut(0, 15, 11, "IMPORTANT:");
  vbTextOut(0, 15, 12, "READ INSTRUCTION AND");
  vbTextOut(0, 15, 13, "PRECAUTION BOOKLETS");
  vbTextOut(0, 15, 14, "BEFORE OPERATING");
  vbFXFadeIn(1);

  while(!(vbReadPad() & (K_STA | K_A))) {}
  while(vbReadPad() & (K_STA | K_A)) {}
  vbFXFadeOut(1);
  Cls();
  vbDisplayOn();

  vbSetObject(1, OBJ_ON, 3, VIP_REGS[JPLT0], 4, 4);

  VIP_REGS[SPT3] = 1;
  VIP_REGS[SPT2] = 0;
  VIP_REGS[SPT1] = 0;
  VIP_REGS[SPT0] = 0;

  while(1) {}
}

int Cls ()
{
  int i;

  i = -1;
  while(i < 28)
    {
      i++;
      vbTextOut(0, 0, i, "                                                ");
    }
}

There are a couple of problems with your code. First, the “p” parameter in vbSetObject() doesn’t stand for palette, but parallax (for the 3D effect). So you probably just want to pass it a 0 for the time being.

Secondly, you’re trying to use character #4 which you haven’t initialized. You only load chars (the font) to charseg 3, which contains characters #1536-#2047. There are 4 charsegs, each containing 512 characters. Like this:

Charseg0 = 0-511
Charseg1 = 512-1023
Charseg2 = 1024-1535
Charseg3 = 1536-2047

(Since they are back to back in memory, you can just as well use them as one big charseg containing all 2048 possible chars.)

So, either load the same graphics into charseg0 as well, or use char #1540 for your object to get the intended char.

Last, the SPT pointers. If you only want to display a single object, SPT3 should be set to 0 (since it’s a zero based index), and the rest of them to -1 (or 1023 really). Like this:

VIP_REGS[SPT3] = 0;
VIP_REGS[SPT2] = -1;
VIP_REGS[SPT1] = -1;
VIP_REGS[SPT0] = -1;

That should get you something to show up on screen πŸ™‚

  • This reply was modified 13 years, 11 months ago by DanB.
  • This reply was modified 13 years, 11 months ago by DanB.
  • This reply was modified 13 years, 11 months ago by DanB.

I changed the main function to this and I only get a black screen:

  copymem ((void*)CharSeg3, (void*)FONT, 8192);

  vbSetWorld(31, WRLD_ON|WRLD_OBJ, 0, 0, 0, 0, 0, 0, 384, 224);
  vbSetWorld(30, WRLD_ON, 0, 0, 0, 0, 0, 0, 384, 224);
  vbSetWorld(29, WRLD_END, 0, 0, 0, 0, 0, 0, 0, 0);

  vbDisplayOn();

  vbTextOut(0, 15, 11, "IMPORTANT:");
  vbTextOut(0, 15, 12, "READ INSTRUCTION AND");
  vbTextOut(0, 15, 13, "PRECAUTION BOOKLETS");
  vbTextOut(0, 15, 14, "BEFORE OPERATING");
  vbFXFadeIn(1);

  while(!(vbReadPad() & (K_STA | K_A))) {}
  while(vbReadPad() & (K_STA | K_A)) {}
  vbFXFadeOut(1);
  Cls();

  vbFXFadeIn(1);

  vbSetObject(1, OBJ_ON, 3, 0, 4, kObjCharSeg + 4);

  VIP_REGS[SPT3] = 0;
  VIP_REGS[SPT2] = -1;
  VIP_REGS[SPT1] = -1;
  VIP_REGS[SPT0] = -1;

  while(1) {}

Thanks dasi, it works! Though it looks a bit messy. Oh well, I’ll just move the object init code into another file and call it from there.

The first parameter in your vbSetObject() should probably have been 0 instead of 1 and it would have worked…

And what was wrong with trying out my demo code posted above? πŸ™ πŸ˜›

The first parameter in your vbSetObject() should probably have been 0 instead of 1 and it would have worked…

You’re right!

Thanks to both!

 

Write a reply

You must be logged in to reply to this topic.