help with timing

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
snoopshady
Posts: 5
Joined: Thu Jan 10, 2008 1:49 am

help with timing

Post by snoopshady »

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: Select all

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&#40;"sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust1.png"&#41;
end

if current >101 and current < 200 then
playerimg= Image.load&#40;"sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust2.png"&#41;
end

if current >201 and current < 300 then
playerimg= Image.load&#40;"sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust3.png"&#41;
end


if current >301 and current < 400 then
playerimg= Image.load&#40;"sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust4.png"&#41;
end


if current >401 and current < 500 then
playerimg= Image.load&#40;"sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust5.png"&#41;
end


if current >501 and current < 600 then
playerimg= Image.load&#40;"sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust6.png"&#41;
end


if current >601 and current < 700 then
playerimg= Image.load&#40;"sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust7.png"&#41;
end

if current >701 and current < 800 then
playerimg= Image.load&#40;"sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust8.png"&#41;
end

if current >801 and current < 850 then
playerimg= Image.load&#40;"sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust9.png"&#41;
end

if current >851 and current < 900 then
playerimg= Image.load&#40;"sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust10.png"&#41;
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
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Load the images in the init, putting the ptrs into an array:

Code: Select all

  sonict_images&#91;0&#93; = loadImage&#40;"sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust1.png"&#41;;
  sonict_images&#91;1&#93; = loadImage&#40;"sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust2.png"&#41;;
...
  sonict_images&#91;9&#93; = loadImage&#40;"sprites/lloyd/Battle Sprites/Sonic Thrust/back/sonicthrust10.png"&#41;;
then simply do:

Code: Select all

  playerimg = sonict_images&#91;current/100&#93;;
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.
zilt
Posts: 45
Joined: Tue Feb 21, 2006 11:59 pm
Location: Ontario, Canada
Contact:

Post by zilt »

hmm.. I guess you must be bnc9 over in qj since you posted the exact same question:

http://forums.qj.net/f-psp-development- ... 32245.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
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

I hate to imagine what Mortal Kombat would be like if it loaded images only as requred.
If not actually, then potentially.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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.
snoopshady
Posts: 5
Joined: Thu Jan 10, 2008 1:49 am

Post by snoopshady »

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.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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.
Post Reply