• Content count

  • Joined

  • Last visited

Community Reputation

148 Neutral

About Zotoaster

  • Rank
  1. Okay so I tried putting a pixel at 0,0 of the whole image with RGB values 66, 77 and 88. It read them in as 84, 96 and 107, so obviously the colours are either being changed or not read in properly. However, when I try it with a specific alpha value, it reads it in perfectly. I would change my system to only use alpha values but it seems the pixel editor I'm using removes the alpha value once you put in the pixel and blends it in with the rest of the image.
  2. I know for a fact that I'm looping through the correct part of the image because the 'clip' rect is directly taken from the part of my code that renders each sprite frame, which works fine. As for working through all the hex values, each frame is 64x64 pixels, that's 4096 values to look through.   I posted the "important" bits in my second post, but in my first post all the relevant code is there.   I'll try your idea of testing the known positions of the special pixels and report back.   Thanks
  3. I tried it with SDL_MapRGBA but that didn't work either. Here's a condensed version of the code showing only the important bits: // convert special SDL_Color to Uint32 Uint32 spec1 = SDL_MapRGBA(_texture->GetSDLSurface()->format, _spec1.r, _spec1.g, _spec1.b, 255); Uint32 spec2 = SDL_MapRGBA(_texture->GetSDLSurface()->format, _spec2.r, _spec2.g, _spec2.b, 255); // ... // while looping through pixels // get pixel at (x, y) // CODE FOR THIS IN LINK ON FIRST POST Uint32 pix = _texture->GetPixel(x, y); // if pixel is a special value, store it in animation if (pix == spec1) { // breakpoint never reaches here SDL_Point pt = {x, y}; anim->Special1.push_back(pt); found1 = true; } else if (pix == spec2) { SDL_Point pt = {x, y}; anim->Special2.push_back(pt); found2 = true; }
  4. Okay so let me explain roughly what I'm trying to do. I've got a spritesheet of a character, and I wish to attach a sword to his hand. To achieve this I'm putting two pixels on his hand per frame, one being RGB (1, 2, 3) and the other being (3, 2, 1). If I can read in and store the positions of these pixels, I should be able to position the sword as the player animates.   So, I've got a Texture class (which keeps a reference to the SDL surface), and I'm using this code to read pixels: http://sdl.beuc.net/sdl.wiki/Pixel_Access   Now, I'm going through each frame, and for each frame, going through each pixel, and comparing it to 'spec1' and 'spec2', which are Uint32 values which define the pixel colour. Here's the code: // read special pixels if (_readSpecial) { SDL_LockSurface(_texture->GetSDLSurface()); // convert special SDL_Color to Uint32 Uint32 spec1 = SDL_MapRGB(_texture->GetSDLSurface()->format, _spec1.r, _spec1.g, _spec1.b); Uint32 spec2 = SDL_MapRGB(_texture->GetSDLSurface()->format, _spec2.r, _spec2.g, _spec2.b); // start looping through frames for (int f = start; f < end; f++) { int frmx = f % _cols; int frmy = f / _cols; // get rectangle around frame SDL_Rect clip; clip.x = frmx * _frmWidth; clip.y = frmy * _frmHeight; clip.w = _frmWidth; clip.h = _frmHeight; bool found1 = false; bool found2 = false; // loop through all pixels in frame for (int y = clip.y; y < clip.y + clip.h; y++) { if (found1 && found2) break; for (int x = clip.x; x < clip.x + clip.w; x++) { // get pixel at (x, y) Uint32 pix = _texture->GetPixel(x, y); // if pixel is a special value, store it in animation if (pix == spec1) { SDL_Point pt = {x, y}; anim->Special1.push_back(pt); found1 = true; } else if (pix == spec2) { SDL_Point pt = {x, y}; anim->Special2.push_back(pt); found2 = true; } } } // if not found special value, add dummy value SDL_Point none = {-1, -1}; if (!found1) anim->Special1.push_back(none); if (!found2) anim->Special2.push_back(none); } SDL_UnlockSurface(_texture->GetSDLSurface()); } Now, I'm putting breakpoints in the "if (pix == spec1)" statements, to check if the pixels have been found, but that breakpoint never gets reached. I'm trying to figure out why this is. Does anyone have any clues?   Thanks     [Edit]   Forgot to mention, I'm using a PNG image, not sure if that's part of the problem...
  5. Better sword combat in my 2D platformer

    Thank you for all your replies. I clearly need to learn a bit more about animation.   I found on the internet an idea to detect pixels with a designated colour and store their positions in each frame. Using this method, I can put two of them on his hand for each frame, and that should serve to define the sword's position and orientation
  6. Better sword combat in my 2D platformer

    Quite right. Here's the frames for the sword stab.  
  7. Better sword combat in my 2D platformer

    That sounds workable actually. Do you animate the player's arm when attacking, or do you have the arm as part of the sword image and move it all together?
  8. Evenin',   I'm working on an action adventure platformer in 2D and I've just about finished up the first level, and I'm fairly satisfied, except for the sword combat. On the first quest the only thing you have to fight are simple crabs that move back and forward over their territory, and if they touch you you take some damage. This is okay because it's part of the design. But I definitely need to work on the player's combat.   Here's the problem. I'm using a spritesheet for the player, and all attacks are animated in that spritesheet. Each frame is only 64x64 pixels, so there's not an awful lot of room for sword attacks. For this reason I've had to keep the sword pretty short and the only animation I managed to fit was a simple stab.   The game doesn't have much immersion when it comes to combat. The stab doesn't appear like it should do much damage. The reaction to a stab is the crabs take a couple of steps back and a sound bite plays. But I'm just not sucked into it enough.   What are some key design points that I should focus on here? What makes for interesting and immersive sword fights? I'm new to the psychology of games so I'd like to hear your opinion.   I think it's too late to change my engine to use bone-based animation at this point, and if the character was any bigger, he'd be too big, so these are my restraints at the moment.   Thanks for reading
  9. Okay so I have collision with slopes working fairly well on my platformer but I'm thinking it could be better.   Basically, I'm using the Tiled Map Editor, and I draw polylines on the floors where you're supposed to collide. In the game, I basically create a ray between the player's current position, and the position he's going to be in next, and check if it intersects one of these lines. If it does, the "onGround" bool is set to true (which disables gravity), and then I get the gradient of the line segment, find out how far along the X axis I am of it, multiply that by the gradient and set that as the Y coordinate. Simple maths, but it works and it's solid.   However, when I'm running downhill, I'm moving along the X axis, leaving the ground for a bit, falling until I hit the ground, etc. So very little time is actually spent on the ground, which means you can't jump ('onGround' has to be true to jump).   So, I was thinking of following these paths directly, but it's a little bit complicated and I'm confused about how to do it. Note, there are many polylines per level, and most have more than one line segment to them. Does anyone have any experience with this? I could use some help.   Thanks
  10. Ah that's not so bad then. A quick fix, thanks!
  11. Okay so I've never used SDL before and I'm just learning it now. I looked up some code on the internet and created a texture class that I use to draw. Here it is: /** Texture */ Texture::Texture(string file) { SDL_Texture * newTexture = NULL; SDL_Surface * loadedSurface = IMG_Load(file.c_str()); if (!loadedSurface) printf("Unable to load image %s! SDL_image Error: %s\n", file.c_str(), IMG_GetError()); else { newTexture = SDL_CreateTextureFromSurface(SDLDevice::Instance()->GetRenderer(), loadedSurface); if (!newTexture) printf("Unable to create texture from %s! SDL Error: %s\n", file.c_str(), SDL_GetError()); else { _width = loadedSurface->w; _height = loadedSurface->h; } SDL_FreeSurface(loadedSurface); } _texture = newTexture; } Texture::~Texture() { if (_texture) SDL_DestroyTexture(_texture); } int Texture::GetWidth() { return _width; } int Texture::GetHeight() { return _height; } void Texture::SetColour(Uint8 red, Uint8 green, Uint8 blue) { SDL_SetTextureColorMod(_texture, red, green, blue); } void Texture::SetBlendMode(SDL_BlendMode blend) { SDL_SetTextureBlendMode(_texture, blend); } void Texture::SetAlpha(Uint8 alpha) { SDL_SetTextureAlphaMod(_texture, alpha); } void Texture::Render(int x, int y, SDL_Rect * clip, double angle, SDL_Point * center, SDL_RendererFlip flip) { SDL_Rect renderQuad = {x, y, _width, _height}; if (clip) { renderQuad.w = clip->w; renderQuad.h = clip->h; } SDL_RenderCopyEx(SDLDevice::Instance()->GetRenderer(), _texture, clip, &renderQuad, angle, center, flip); } Apparently the 'SDL_RenderCopyEx' call is pretty inefficient, but seeing as I don't yet know how all of this really fits together, I ask if there is a better way to do this while keeping the same general interface, as it's what I'm using for my game.   Thanks
  12. Okay so I'm using SDL and a .tmx parser to try and render some tilemaps from Tiled. I'm using Xcode with C++. So far so good.   But! The tilemaps' XML files refer to relative directories to find the tileset image. This is a problem because the compiled program is then looking relative to the build path rather than relative to the path of the tilemap.   TL;DR: Does anyone know how to access relative directories from the actual source code directories rather than the build directory?   Thanks     Edit: Of course "Directoties" should be "Directories". You get the picture
  13. Nypyren, I can understand your first explanation but I'm not entirely sure about the second one. What is the purpose of 'await' and '=>'? Would this require all statements in my language to be essentially asynchronous?   Madhed,   I considered that but there are a few problems. First, would I put 'everything' in? Just the next few lines? There could be many statements scattered about all over the place that access the image. Not to mention that the library (for handling images etc) is separate from the compiler itself. The compiler only knows about basic types.
  14. So I've been working on a programming language similar to Java/C# as a personal project that compiles to javascript and has a library that can access HTML5 functions. It's working very nicely but there's one problem I can't solve for the life of me.   HTML5 loads images asynchronously and invokes a callback when the image has loaded. In the meantime it continues doing other things. This doesn't fit the scheme of my language, as it doesn't have callbacks. It does have a signal/slot system but it's not compatible with this particular system.   Suppose I want to load an image and get it's dimensions. This is how you'd do it in JS. var imageObj = new Image(); imageObj.onload = function() { var w = this.width; var h = this.height; }; But, in my language, I'd like to do it like this: var img = new Image("test.jpg"); int width = img.Width; int height = img.Height; This of course is impossible because by the time I want to check the dimensions, the image hasn't actually been loaded yet, so it returns 0, 0. The only way I've found around it is to check in the main loop for when the image has been loaded, grab the necessary data and do all processing there, but damn that's ugly.   Does anyone have any ideas how to work around this? Once I solve this problem, I can actually make a half-decent game or app with my language, but until then it feels kinda useless.   Thanks
  15. glu tessellation not working

    Okay I got it fixed. Turns out it stores references to vertices before actually creating them in the 'gluTessEndPolygon()' function. So it was assuming all vertices were the last vertex I gave it. It also wanted 3D vertices which means by polygon class has to have two versions of the vertex list (it could just use the 3d one but then it wouldn't interface well with the rest of the program).