| View previous topic :: View next topic |
| Author |
Message |
snoopshady
Joined: 10 Jan 2008 Posts: 5
|
Posted: Sat Jan 12, 2008 12:47 am Post subject: help with timing |
|
|
I was having a little trouble with loading sprites from my previous program (Tales of Symphonia the Homebrew (im trying to port it to C)) basically I want to the load attacking sprites without having to hold the required button combo until the attack finishes. Normally in lua i would do this:
| Code: |
function sonicthrustback()
counter:start()
current = counter:time()
if current >1050 then
status = "false"
playerimg = playerimgback
counter:reset()
end
if current >0 and current < 100 then
playerimg= Image.load("sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust1.png")
end
if current >101 and current < 200 then
playerimg= Image.load("sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust2.png")
end
if current >201 and current < 300 then
playerimg= Image.load("sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust3.png")
end
if current >301 and current < 400 then
playerimg= Image.load("sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust4.png")
end
if current >401 and current < 500 then
playerimg= Image.load("sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust5.png")
end
if current >501 and current < 600 then
playerimg= Image.load("sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust6.png")
end
if current >601 and current < 700 then
playerimg= Image.load("sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust7.png")
end
if current >701 and current < 800 then
playerimg= Image.load("sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust8.png")
end
if current >801 and current < 850 then
playerimg= Image.load("sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust9.png")
end
if current >851 and current < 900 then
playerimg= Image.load("sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust10.png")
end
end
|
is there a way to do this in C?(im not sure how one gets timers in C also)
EDIT:nvm i got it guess i got frustrated over nothing |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sat Jan 12, 2008 4:55 am Post subject: |
|
|
Load the images in the init, putting the ptrs into an array:
| Code: | sonict_images[0] = loadImage("sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust1.png");
sonict_images[1] = loadImage("sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust2.png");
...
sonict_images[9] = loadImage("sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust10.png"); |
then simply do:
| Code: | | playerimg = sonict_images[current/100]; |
Again, you are loading images in a place where you shouldn't. All images should be loaded before the game (or level if different for level) starts, then just use the pointers in the main code. |
|
| Back to top |
|
 |
zilt
Joined: 21 Feb 2006 Posts: 45 Location: Ontario, Canada
|
Posted: Sat Jan 12, 2008 5:33 am Post subject: |
|
|
hmm.. I guess you must be bnc9 over in qj since you posted the exact same question:
http://forums.qj.net/f-psp-development-forum-11/t-help-with-timers-132245.html
For your current level of C++ expertise, you'll probably get more help there. These really are basic questions you're asking. _________________ "We are dreamers, shapers, singers, and makers. We study the mysteries of laser and circuit, crystal and scanner, holographic demons and invocations of equations. These are the tools we employ and we know... many things." -- Elric, B5 |
|
| Back to top |
|
 |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Sat Jan 12, 2008 12:32 pm Post subject: |
|
|
I hate to imagine what Mortal Kombat would be like if it loaded images only as requred. _________________ If not actually, then potentially. |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sat Jan 12, 2008 1:29 pm Post subject: |
|
|
| Art wrote: | | I hate to imagine what Mortal Kombat would be like if it loaded images only as requred. |
Some 2D fighters for the PS1 actually DID load some images on the fly due to lack of memory. So certain transformations or attacks for certain characters would bring the game to a virtual halt while it loaded the images from CD.
That shouldn't be needed for a simple PSP game. |
|
| Back to top |
|
 |
snoopshady
Joined: 10 Jan 2008 Posts: 5
|
Posted: Sat Jan 12, 2008 1:49 pm Post subject: |
|
|
yea normally i would load images and then call them in the main code however the person who made this code(SavageSnip3r (hes part of my team and a good friend)) was too lazy to make variables in the beginning and i just
copied his code. |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sat Jan 12, 2008 4:59 pm Post subject: |
|
|
| snoopshady wrote: | | yea normally i would load images and then call them in the main code however the person who made this code(SavageSnip3r (hes part of my team and a good friend)) was too lazy to make variables in the beginning and i just copied his code. |
That's not lazy programming, it's BAD programming. It creates a new image every time you switch images. Even on a PC, this would eventually crash when you exhausted the virtual memory. On the PSP, it'll blow up REAL quick since you don't have that much memory to play with.
That and the fact that the code has that ridiculous if/then method of choosing the image demonstrates that whoever wrote the code needs a few more lessons. |
|
| Back to top |
|
 |
|