forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Will This Work?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
snoopshady



Joined: 10 Jan 2008
Posts: 5

PostPosted: Thu Jan 10, 2008 2:15 am    Post subject: Will This Work? Reply with quote

first of all i would like to say i have a little experience with C++ but only making windows command line apps.
Code:

#include <pspdebug.h>
#include <pspkernel.h>
#include <pspcallbacks.h>
#include <pspctrl.h>
#include "graphics.h"

#define RGB(r, g, b) ((r)|((g)<<8)|((b)<<16))
#define prints PrintTextScreen
PSP_MODULE_INFO("Sprite Movement",0,1,1);



void spritemove();

int main(){
initGraphics();
SetupCallbacks();
SceCtrlData pad;
Color white = RGB(255,255,255);
int x = 200;
int y = 100;
Image*player = loadImage("Player2.png");
while(1){
   sceCtrlPeekBufferPositive(&pad,1);
   clearScreen(white);
   if(pad.Buttons & PSP_CTRL_LEFT ){
   spritemove();
   x--;
   }
   blitAlphaImageToScreen(0,0,18,30,player,x,y);
   sceDisplayWaitVblankStart();
   flipScreen();
   }
   return 0;
   }
void spritemove(){
Image*player = loadImage("Player2.png");
int ctr = 0;
ctr = ctr + 1;
int e = 0;
int d = 0;
int f = 0;
if(ctr >= 40 || ctr <= 0){
ctr = 0;
}
if(ctr == 10){
player = loadImage("Player1.png");
for( d = 0; d < 3; d++){
sceDisplayWaitVblankStart();
}
}
if(ctr == 20){
player = loadImage("Player2.png");
for(f = 0; f < 3; f++){
sceDisplayWaitVblankStart();
}
}
if(ctr == 30){
player = loadImage("Player3.png");
for(e = 0; e < 3; e++){
sceDisplayWaitVblankStart();
}
}
}

Heres the code i normally use in lua (with C modifications) for animating sprites. I believe it should work (hey if it works in LUA technically shouldnt it work in C?). My question is does it?(Im pspless at the moment i cant test it). It compiles fine
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Thu Jan 10, 2008 4:26 am    Post subject: Reply with quote

well it might work then :)
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Thu Jan 10, 2008 5:18 am    Post subject: Reply with quote

There are literally hundreds of "simple" sprite examples on the net in general, and this forum specifically. I even did one that loaded frames for animation from an anigif. Use the d@mn search and read the old threads!
Back to top
View user's profile Send private message AIM Address
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Thu Jan 10, 2008 7:29 am    Post subject: Reply with quote

No it won't. Anyway, it will just crash at some point as it is constantly leaking memory.
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Thu Jan 10, 2008 10:11 am    Post subject: Reply with quote

Yeah, use the loadImage in the init, not the main sprite move function. That loads a new image every time it's called.
Back to top
View user's profile Send private message AIM Address
snoopshady



Joined: 10 Jan 2008
Posts: 5

PostPosted: Thu Jan 10, 2008 8:52 pm    Post subject: Reply with quote

got it to work just changed this
Code:
Image*player = loadImage("Player2.png");
int ctr = 0;(biggest mistake i made)
to this
Code:
Image*player;
int ctr = 0;
and declared them as global variables
EDIT: also thanks Raphael and J.F
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group