Original Post
I've been trying to put pixels on the screen to use as particles, I managed to do it in another graphical engine but SDl doesnt like it. i know its the putpixel(10, 10, 0xffffff); line or function because I commented then out and it compiled. I got the following errors: thanks for looking thanks ToohrVyk fixed one problem as least but as know may know every solution breeds new problems. i got: Access violation writing location 0x0212d58c. and it pointed to this line - ptr[lineoffset + x] = color; any ideas. I also added if (mrgPartX>640||mrgPartX<0) mrgAlive==false; if (mrgPartY>480||mrgPartY<0) mrgAlive==false; to stop drawing the particles when there go off the screen. [Edited by - Ultimate_Fusion on November 27, 2007 7:31:06 AM]
#include "stdafx.h"
#include "ins.h" // SDL includes headers
#include <time.h>
#include <stdlib.h>
#include <math.h>
#include "helicopter.h"
#include "particle.h"
#include "Singleton.h"
//#include "SDL_Draw.h" // tried adding this didn't work
Singleton *sc2;
particle::particle()
{
for(int i=0;i<MAXPARTICLES;i++){
mrgAlive=false;
}
}
void particle::Draw()
{
// Draw all the particles
// if they are alive
for(int i=0;i<MAXPARTICLES;i++){
if(mrgAlive == true){
sc2 = Singleton::Instance();
// Lock surface if needed
if (SDL_MUSTLOCK(sc2->screen))
if (SDL_LockSurface(sc2->screen) < 0)
return;
putpixel(10, 10, 0xffffff);
putpixel(11, 10, 0xff0000);
putpixel(10, 11, 0xff0000);
putpixel(11, 11, 0xff0000);
// Unlock if needed
if (SDL_MUSTLOCK(sc2->screen))
SDL_UnlockSurface(sc2->screen);
}
void particle::Move()
{
for(int i=0;i<MAXPARTICLES;i++)
{
mrgPartX += mrgPartVX;
mrgPartY += mrgPartVY;
}
}
void particle::putpixel(int x, int y, int color)
{
unsigned int *ptr = (unsigned int*)sc2->screen->pixels;
int lineoffset = y * (sc2->screen->pitch / 4);
ptr[lineoffset + x] = color;
}