gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Limit sprite movement?

#161953 - Quipeace - Wed Aug 20, 2008 10:26 am

hello everyone,

first off all, im new to nds programming, (its my first post here too by the way) so dont flame me if its very simple to do.

heres the situation:

its my third project so far (did a small mario like thing before this).
I got a sprite that has to be able to move sideways, but NOT up and down (like its on rails), i know this is possible with the pad, but id like to use the stylus if possible.

thanks in advance



EDIT: this is my code so far (please dont mind the comment blocks, i find it hard to read the code without those...
Code:
#include <PA9.h>                                               
#include "gfx/all_gfx.c"
#include "gfx/all_gfx.h"
 

//-----------------------------------Standard Stuff----------------------------------------------\\

int main(int argc, char ** argv)
{
   PA_Init();                                               
   PA_InitVBL();
   
   PA_InitText(0,0);
   PA_SetTextCol(0, 31, 31, 31);

   s32 x = 0;  // Sprite X
   s32 y = 0;  // Sprite Y
   
//------------------------------------End of Stuff-----------------------------------------------\\
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//-----------------------------------LOAD BACKGROUND---------------------------------------------\\

    PA_EasyBgLoad(0, 3,   pdabot);
   PA_EasyBgLoad(1, 3, pdatop);
         
//------------------------------------END BACKGROUND---------------------------------------------\\
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//--------------------------------------Load Icons-----------------------------------------------\\
   
   PA_LoadSpritePal(0, // Screen
         0, // Palette number
         (void*)Settingsicon_Pal);   // Palette name
   
   PA_CreateSprite(0, // Screen
         0, // Sprite number
         (void*)Settingsicon_Sprite, // Sprite name
         OBJ_SIZE_64X32, // Sprite size
         1, // 256 color mode
         0, // Sprite palette number
         1, 17); // X and Y position on the screen             
   

//--------------------------------------END ICONS------------------------------------------------\\
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//----------------------------------------BEGIN--------------------------------------------------\\
 
while (1)
{
    PA_MoveSprite(0);
    PA_WaitForVBL();
}
   
return 0;
}


Quipeace[/code]

#161954 - sgeos - Wed Aug 20, 2008 10:47 am

I'm not familiar with PAlib, but I'll hazard a guess and say that sprite positioning and input are separate tasks. If you want to move a sprite with the stylus, you will have to figure out where the stylus is and where your sprite is. If your stylus is dragging the sprite, then you move the sprite with the stylus. This really is not much different from moving with the pad, expect that you need some way to determine if you should be dragging a given game object.

You could set the position of the game object to the cursor location, or to the cursor location plus an offset (if you want to center the on part of the sprite), or you could move the sprite based cursor movement. (change = new - old)

Reading your code, it does not appear that the sprite x and y position variables are being used. My guess is that PA_MoveSprite() is working some automagic that you need to stop using. If you do not want to move up and down, I suspect you'll need to manually update the x, but not y position.

-Brendan

#161955 - AntonioND - Wed Aug 20, 2008 11:13 am

sgeos wrote:
Reading your code, it does not appear that the sprite x and y position variables are being used. My guess is that PA_MoveSprite() is working some automagic that you need to stop using. If you do not want to move up and down, I suspect you'll need to manually update the x, but not y position.

-Brendan

You're right.


Quipeace, you should use:
Code:
PA_MoveSprite(0);
PA_SetSpriteY(0,17);



EDIT: This kind of questions should go to PAlib's forum:
http://www.palib.info/

#161956 - Quipeace - Wed Aug 20, 2008 11:32 am

Thanks alot, and thanks for pointing me to that forum too, i didnt know about it (ill post my palib questions there from now)

THANKS

EDIT: im getting an error using the PA_SetSpriteY, not declared in this scope, but ill go to the palib forum for that ;)

EDIT: got it working, it needed a nother value for the screen ;) thanks again.