| View previous topic :: View next topic |
| Author |
Message |
snoopshady
Joined: 10 Jan 2008 Posts: 5
|
Posted: Thu Jan 10, 2008 2:15 am Post subject: Will This Work? |
|
|
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 |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Thu Jan 10, 2008 4:26 am Post subject: |
|
|
| well it might work then :) |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Thu Jan 10, 2008 5:18 am Post subject: |
|
|
| 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 |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Thu Jan 10, 2008 7:29 am Post subject: |
|
|
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 |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Thu Jan 10, 2008 10:11 am Post subject: |
|
|
| 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 |
|
 |
snoopshady
Joined: 10 Jan 2008 Posts: 5
|
Posted: Thu Jan 10, 2008 8:52 pm Post subject: |
|
|
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 |
|
 |
|