forums

TNT Basic Forums > Programming Q&A
Hardware/Software Mode Difficulties
< Last Thread     Next Thread >
Author
Thread        Post A Reply

08-30-2006 04:46

Posted by:
moople

Location:
Oregon

Find more posts by moople

So I have been writing a little particle engine for my upcoming game, and I was wondering if I could get some pointers on a programming difficulty I was having.

What I'd like to do is allow my particle images (rendered as multiple sprites) to be able to scale down as they're going offscreen. I already have implemented the entire particle system in software graphics mode (except for the scaling), and when I try to switch into hardware graphics mode, none of my sprites display!

I don't think I'm doing anything that would cause sprites not to show up, and the only hardware-dependant function I want to use is sprite scaling. So... Does anyone have an idea as to what's going on? And, if I choose not to use hardware graphics mode, is there any other way of having my sprites get steadily smaller?

08-30-2006 17:01

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

Hmm...

Do you start the scaling a x scale=1 and y scale=1?

08-30-2006 17:13

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

if you run code without any scaling or hardware-specific code (i.e. code that runs in software mode) in hardware mode, does it run properly?

08-30-2006 18:52

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

I think it does, it always worked for me.

08-30-2006 21:16

Posted by:
moople

Location:
Oregon

Find more posts by moople

yes

Yes, I am starting in sprite x and y scale = 1. And yes, the rest of the code runs fine in both modes, except the sprites never draw on screen. I have other code that writes text, etc. to screen and that displays properly. Just the sprites.

08-30-2006 21:32

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

Well, I'd like to take a look at the code.
I would be goo if you could send the project to j-a-f@earthlink.net, but if you don't want to just post the code here.

08-30-2006 22:22

Posted by:
swagIT

Location:
Great Wet North (Vancouver)

Find more posts by swagIT

I would like to see some code too - as this might impact some things I am working on .... =)

08-31-2006 19:28

Posted by:
moople

Location:
Oregon

Find more posts by moople

code

Okay, here's the entire code for my project. Keep in mind, that this is unedited, and the comments are probably misspelled and all...

------
Graphics Mode Hardware 640,480
'==VARS==
'note:
'for particles, you must establish an array that is 3*max number of particles you will ever need.
Global Int particles[150]
int i
'for i=1 to 150
'particles=0
'next
'==MAIN LOOP==
while not mouse button
set pen colour black
paint canvas
DoParticles(1,0,30,10,0,30,30,1,1)
draw frame
wend
end




procedure DoParticles(int type,int imagenum,int lifetime,int numparticles,int opacdelta,int emitterx,int emittery,int accx,int accy)
'==PARTICLE PROCEDURE==
'note:
'To use the particle procedure in other projects, copy this procedure, and the particle system graphics bank.
'MANUAL:
'Paramater 1: Type of particle effect. Currently only supports 1- directional.
'Paramater 2: Particle image to use- particles can only be referenced from databank 128.
'Parameter 3: Particle Lifetime (in cycles).
'Parameter 4: Number of particles.
'Parameter 5: Particle Opacity Delta (0 is 100% opaque over the entire life) otherwise, # of frames before End of life where fade out starts.
'Parameter 6: Particle Emitter location X
'Parameter 7: Particle Emitter Location Y
'Parameter 8: Particle Acceleration X (Higher Number=Faster Particles)
'Parameter 9: Particle Acceleration Y (Higher Number=Faster Particles)


int i
int particlex
int particley
int particlelife
int particleopac
for i=1 to numparticles
'updater loop
'grab particle x for i
particlex=particles[3*i-2]
particley=particles[3*i-1]
particlelife=particles[3*i]
'check if I'm respawning..
if particlelife>=lifetime or particlelife=0
'spawn me!
particlex=emitterx
particley=emittery
particlelife=1
end if
'declare sprite
sprite 499+i,particlex,particley,imagenum
set image bank 499+i,128
'apply fx
'-opacity delta
particleopac=(100/(lifetime-opacdelta))*(particlelife-(lifetime-opacdelta))
if opacdelta <> 0
if particlelife>opacdelta
'apply opac. delta
Set Sprite Transparency i+499,particleopac
else
Set Sprite Transparency i+499,0
end if
else
Set Sprite Transparency i+499,0
end if
'adjust vars
'add acc
particlex=particlex+accx
particley=particley+accy
'pop vars back
particles[3*i-2]=particlex
particles[3*i-1]=particley
particles[3*i]=particlelife
'for testing
set pen colour white
draw text 20,20,as string(i)
Set Pixel Colour emitterx,emittery,red
next i
'finished
end proc
---------

there. If you can get that working, great.

08-31-2006 19:31

Posted by:
moople

Location:
Oregon

Find more posts by moople

code (new)

Whoops, that last code was from an earlier version:
-----------------------
Graphics Mode Hardware 640,480
load images 128
'==VARS==
'note:
'for particles, you must establish an array that is 3*max number of particles you will ever need.
Global Int particles[300]
int i
int t,y
t=110
y=110
'for i=1 to 150
'particles=0
'next
'==MAIN LOOP==
while not mouse button
set pen colour black
paint canvas
DoParticles(3,0,60,30,30,t,y,5,5,1,1,1,0)
draw frame
t=mouse x
y=mouse y
wend
end



procedure DoParticles(int type,int imagenum,int lifetime,int numparticles,int opacdelta,int emitterx,int emittery,int accx,int accy,int minaccx,int minaccy,int startscale,int scaledelta)
'==PARTICLE PROCEDURE==
'note:
'To use the particle procedure in other projects, copy this procedure, and the particle system graphics bank.
'MANUAL:
'Paramater 1: Type of particle effect. 1=On (spawn all at once, respawn) , 2=Burst (spawn all at once, no respawn), 3=trickle (spawn slowly, respawn)
'Paramater 2: Particle image to use- particles can only be referenced from databank 128.
'Parameter 3: Particle Lifetime (in cycles).
'Parameter 4: Number of particles.
'Parameter 5: Particle Opacity Delta (0 is 100% opaque over the entire life) otherwise, # of frames before End of life where fade out starts.
'Parameter 6: Particle Emitter location X
'Parameter 7: Particle Emitter Location Y
'Parameter 8: Particle Maximum Acceleration X (Higher Number=Faster Particles)
'Parameter 9: Particle Maximum Acceleration Y (Higher Number=Faster Particles)
'Parameter 10: Particle Minimum Acceleration X (Higher Number=Slower Particles)
'Parameter 11: Particle Minimum Acceleration Y (Higher Number=Slower Particles)
'Parameter 12: Particle scale (.5 = half size of sprite graphic) (the value is the same as sprite x and y scale, except it gets devided by 10.)
'Parameter 13: Particle scale delta (0 is 100% of scaled size for the duration of the particle life, otherwise, its the # of frames before end of life where scale to 0 starts.)


int i
int particlex
int particley
int particlexacc,particleyacc
int particlelife
int particleopac
for i=1 to numparticles
'updater loop
'grab particle x for i
particlexacc=particles[5*i-4]
particleyacc=particles[5*i-3]
particlex=particles[5*i-2]
particley=particles[5*i-1]
particlelife=particles[5*i]
'check if I'm respawning..
if particlelife>=lifetime or particlelife=0
'spawn me!
if type=1 or type=2
particlex=emitterx
particley=emittery
particlexacc=random(minaccx,accx)
particleyacc=random(minaccy,accy)
particlelife=1
else
'type is trickle
'for now, random is whether you spawn now or not...
if random(1,5)=2
particlex=emitterx
particley=emittery
particlexacc=random(minaccx,accx)
particleyacc=random(minaccy,accy)
particlelife=1
end if
end if
end if
'declare sprite
sprite 499+i,particlex,particley,imagenum
set image bank 499+i,128
'apply fx
'-opacity delta
particleopac=(100/(lifetime-opacdelta))*(particlelife-(lifetime-opacdelta))
if opacdelta <> 0
if particlelife>opacdelta
'apply opac. delta
Set Sprite Transparency i+499,particleopac
else
Set Sprite Transparency i+499,0
end if
else
Set Sprite Transparency i+499,0
end if
'for testing
'set sprite colour i+499,red
'adjust vars
'apply sprite scale
'set sprite x scale i+499,(startscale)
'set sprite y scale i+499,(startscale)
set sprite x scale i+499,1.0
set sprite y scale i+499,1.0
'add life
particlelife=particlelife+1
'add acc
particlex=particlex+particlexacc
particley=particley+particleyacc
'pop vars back
particles[5*i-4]=particlexacc
particles[5*i-3]=particleyacc
particles[5*i-2]=particlex
particles[5*i-1]=particley
particles[5*i]=particlelife
if i=3
set pen colour white
draw text 100,100,as string(particlelife)
end if
next i
'for testing
set pen colour white
draw text 20,20,as string(i)
Set Pixel Colour emitterx,emittery,red
'finished
end proc
-----------------
there. That should work.

08-31-2006 22:56

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

'set image bank 499+i,128' must appear before 'sprite 499+i,particlex,particley,imagenum'

it's like you tell: "my sprite 499+i will use bank 128"

if you tell "diplay image 0", then tell it to "switch to bank 128" it may not know which image to use. It works in software mode and not hardware mode probably because of the way they are handled, but it doesn't make sense to change the set the bank ID after the image ID

09-03-2006 15:44

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

Sprite ID

try making the sprite ids to 1499+i.
(bug?)

09-03-2006 18:03

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

1499+i or i+1499 should really make no difference

anyway i found what was the problem just read my post :)

09-03-2006 23:30

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

Someone wrote:
| 1499+i or i+1499 should really make no difference |

Of course it makes no diference!
I copied the code and made the sprite numbers to 1499+i (or i+1499) and it worked.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.