About ParticleSystem and Accelerometer !
Hi.
I want to know how accelerometer work with particlesystem ?
I want to use in my game particlesystem class created by Tim Omernick ,but i find it difficult to understand how particles work with accelerometer.
My question is, how to accelerate particles ?
Any simple code from idevgames experts would be appreciated .
Thanks.
I want to know how accelerometer work with particlesystem ?
I want to use in my game particlesystem class created by Tim Omernick ,but i find it difficult to understand how particles work with accelerometer.
My question is, how to accelerate particles ?
Any simple code from idevgames experts would be appreciated .
Thanks.
bump..
no one know !!!!
no one know !!!!
My guess is no one understands the question. Accelerating particles has nothing to do with the accelerometer. You can read values from the accelerometer and apply those values to your particle system in one way or another, but your post doesn't explain what you're actually trying to do.
Frank C. Wrote:My guess is no one understands the question. Accelerating particles has nothing to do with the accelerometer. You can read values from the accelerometer and apply those values to your particle system in one way or another, but your post doesn't explain what you're actually trying to do.
thnx for reply Frank C. and yes you have right about my question.
I want to use iphone accelerometer for particle directions.
Actually based on particlesystem class by Tim,the direction of particles goes fall off bottom of screen (portrait mode).
Now i want to know how to change the direction of particles based on accelerometer value ?
Help ? ? ? ! ! !
Try posting some code samples and asking specific questions.
About the only answer anyone can give you based on the info you've posted is that you need to apply forces to your particles, derived from the accelerometer data. And I'm not even sure that's what you actually want to do!
About the only answer anyone can give you based on the info you've posted is that you need to apply forces to your particles, derived from the accelerometer data. And I'm not even sure that's what you actually want to do!
backslash Wrote:Try posting some code samples and asking specific questions.
About the only answer anyone can give you based on the info you've posted is that you need to apply forces to your particles, derived from the accelerometer data. And I'm not even sure that's what you actually want to do!
bump !!!!
No one can answer your question because you're not being specific and there's nothing to work with. The best you're going to get is a general answer. Something like use Apple's accelerometer sample code to see how to determine the direction the phone is tilted, then go inside the particle class to see how to modify the particle velocities and/or gravity, and hook the two together.
I think he wants his particles to go "down", where down is determined by the accelerometer. In that case, there's not really much of a question here, I guess he's really asking how to turn accelerometer input into a vector.
Really all there is to do is find a place in your particle engine code to set a force or velocity vector and set it to something calculated from the accelerometer values.
Really all there is to do is find a place in your particle engine code to set a force or velocity vector and set it to something calculated from the accelerometer values.
Howling Moon Software - CrayonBall for Mac and iPhone, Contract Game Dev Work
I assume you mean the particle system implementation found here:
http://pastie.org/863672.txt
If so do the following:
Hookup the accelerator data to send to the ParticleSystem class.
You can do this by putting this in the class init method:
In the ParticleSystem header file make sure you specify that it implements the accelerometer delegate. That means you change the class declaration to:
Also add some class members to store accelerometer data in the ParticleSystem class:
Add this method to your ParticleSystem implementation to store the current accelerometer data to those variables:
Now go modify the code where the velocity of particles is updated, this previously should have looked like this:
And should be changed to respect where gravity *actually* is pointing on the device such as:
You may need to modify whether x/y is multiplied by ax, ay, or az depending on which directions the accelerometer data actually points to. I don't remember off the top of my head, but I'm sure with some trial and error you can figure it out.
Last thing you will need to do is modify the particle kill code so that it kills particles when its far off the screen, and not just far below the screen. Before the code looked like this:
Change it to something like this:
That should do it for you.
http://pastie.org/863672.txt
If so do the following:
Hookup the accelerator data to send to the ParticleSystem class.
You can do this by putting this in the class init method:
Code:
[UIAccelerometer sharedAccelerometer].delegate = self;In the ParticleSystem header file make sure you specify that it implements the accelerometer delegate. That means you change the class declaration to:
Code:
@interface ParticleSystem : NSObject <UIAccelerometerDelegate>Also add some class members to store accelerometer data in the ParticleSystem class:
Code:
float ax;
float ay;
float az;Add this method to your ParticleSystem implementation to store the current accelerometer data to those variables:
Code:
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
ax = acceleration.x;
ay = acceleration.y;
az = acceleration.z;
}Now go modify the code where the velocity of particles is updated, this previously should have looked like this:
Code:
// gravity
static const float gravity = 120.0f;
particle->velocityY += gravity * step;
// velocity
float dx = particle->velocityX * step;
float dy = particle->velocityY * step;
particle->x += dx;
particle->y += dy;And should be changed to respect where gravity *actually* is pointing on the device such as:
Code:
// gravity
static const float gravity = 120.0f;
particle->velocityY += gravity * step * ay;
particle->velocityX += gravity * step * ax;
// velocity
float dx = particle->velocityX * step;
float dy = particle->velocityY * step;
particle->x += dx;
particle->y += dy;You may need to modify whether x/y is multiplied by ax, ay, or az depending on which directions the accelerometer data actually points to. I don't remember off the top of my head, but I'm sure with some trial and error you can figure it out.
Last thing you will need to do is modify the particle kill code so that it kills particles when its far off the screen, and not just far below the screen. Before the code looked like this:
Code:
// fall off bottom of screen
if (particle->y > 500) {
Particle *dead = particle;
particle = particle->next;
[self _freeParticle:dead];
continue;
}Change it to something like this:
Code:
// fall off viewable of screen
if (particle->y > 500 || particle->y < -500 || particle->x > 500 || particle->x < -500) {
Particle *dead = particle;
particle = particle->next;
[self _freeParticle:dead];
continue;
}That should do it for you.
@alerus
Thank you for reply and code.
Example code work great but in touches moved i get this from Debugger Console : Program received signal: “EXC_BAD_ACCESS†,and app stop working.
Any idea ??
Thank you for reply and code.
Example code work great but in touches moved i get this from Debugger Console : Program received signal: “EXC_BAD_ACCESS†,and app stop working.
Any idea ??
EXEX_BAD_ACCESS comes up when you try to reference memory which has been already freed or released (or just plain never allocated in the first place).
You'll have to run through the debugger to see what is happening. What Xcode should do is pause the app where the bad access occurred. So if you launch the debugger (command-shift-y) you can go in and look at which line it occurred. You'll notice in the debugger that it will give you the current stack trace so you can click up to the touches moved method to see where it was having a problem.
You'll have to run through the debugger to see what is happening. What Xcode should do is pause the app where the bad access occurred. So if you launch the debugger (command-shift-y) you can go in and look at which line it occurred. You'll notice in the debugger that it will give you the current stack trace so you can click up to the touches moved method to see where it was having a problem.
alerus Wrote:EXEX_BAD_ACCESS comes up when you try to reference memory which has been already freed or released (or just plain never allocated in the first place).
You'll have to run through the debugger to see what is happening. What Xcode should do is pause the app where the bad access occurred. So if you launch the debugger (command-shift-y) you can go in and look at which line it occurred. You'll notice in the debugger that it will give you the current stack trace so you can click up to the touches moved method to see where it was having a problem.
This is the log from Debugger Console :
Code:
particleDemo[5016:207] *** -[NSCFType accelerometer:didAccelerate:]: unrecognized selector sent to instance 0x245dd0
2010-04-02 18:50:52.348 particleDemo[5016:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFType accelerometer:didAccelerate:]: unrecognized selector sent to instance 0x245dd0'
2010-04-02 18:50:52.366 particleDemo[5016:207] Stack: (
That message means it didn't find the method defined in your object for handling the accelerometer events. So what happened is when the accelerometer updated, it tried to call the method on your object, but it didn't exist so it failed.
Make sure you have the method defined in the same class and that it uses the code I provided for it (otherwise the rest wont work either since it needs to store the accelerometer values).
If you're having trouble with these kinds of messages, you might want to start with some tutorials and defined programming projects in Objective-C, or even just C, so you can get more acquainted with it.
Make sure you have the method defined in the same class and that it uses the code I provided for it (otherwise the rest wont work either since it needs to store the accelerometer values).
If you're having trouble with these kinds of messages, you might want to start with some tutorials and defined programming projects in Objective-C, or even just C, so you can get more acquainted with it.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Game play with the accelerometer | Ropeburn | 3 | 2,352 |
Sep 26, 2010 06:17 PM Last Post: Ropeburn |
|
| accelerometer settings | baddapple | 0 | 2,995 |
Apr 24, 2010 05:39 PM Last Post: baddapple |
|
| Accelerometer occasionally doesn't work | imikedaman | 4 | 3,321 |
Jun 2, 2009 08:09 AM Last Post: imikedaman |
|
| How can I smooth accelerometer signal? | riruilo | 6 | 7,122 |
Feb 10, 2009 04:53 PM Last Post: riruilo |
|
| Accelerometer problem | Parystec | 4 | 3,011 |
Sep 30, 2008 01:28 PM Last Post: kodex |
|

