Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Davitosan

Pages: [1]
1
General / Re: Artifacts left on screen on plotting program
« on: November 22, 2014, 02:21:57 am »
Ruckamongus, thanks a lot for your answer!

I tried adding points.clear() where you said, but that made the plot disappear entirely. I also tried adding it after the window.display() line, but the result was the same (no plot).

I think the problem is that the array gets created and populated before the while loop (line 172). I moved that line inside the loop, and the points.clear() after window.display(), and now the program runs as expected!

I don't like the idea of creating the entire array at every iteration of the while loop, though. It doesn't seem right, and probably there's a better way of doing this. Any thoughts?

2
General / Artifacts left on screen on plotting program
« on: November 22, 2014, 01:38:26 am »
Hello! I'm currently studying Fourier Series, and our teacher asked us to develop a program that plots one. I had dabbled in SFML before and I thought it would be as good as any other platform for this task.

Without getting too much into it, the function depends on three variables, 'L', 'a' and 't'. I wanted to add three sliders beneath the graph so the user could change the value of each variable in real time. After a few hours, I got everything up and running, but there's a weird problem. The first slider, the one that controls the variable 'L', leaves artifacts on the screen when the plot becomes smaller. This doesn't happen when the graph gets bigger, or with any of the other two variables. I've tried to figure out the reason for this behavior, but I'm stumped.

I've attached pictures of this happening, and the code for the program, which can also be found here: http://pastebin.com/dUPm93rr

I've also attached the compiled file, fourier.bin.

The forum didn't allow me to attach more images, so I couldn't add the png's for the grid and the sliders, but if anyone wishes to compile this, I'll gladly share them.

Relevant data:

SFML 2.0 for linux, downloaded and installed from the ubuntu repositories.
Compiled with g++ in lubuntu

Any help will be truly appreciated.

(I apologize beforehand, I'm not a proficient programmer and the code is a little messy)

3
Graphics / Map Scrolling (C#)
« on: December 27, 2010, 01:17:32 pm »
I'm not sure if I understood your question, and I'm a newbie, but since I think I've implemented this in my own platformer, here goes my suggestion:

In your main game loop set the view using SetFromRect, like this

View.SetFromRect(sf::FloatRect(cam_x,cam_y,cam_x2,cam_y2));

where all the parameters are float variables.

Then, in the function where you move your character sprite increment or decrement the x and y values of the view at the same rate as the movement of the character. I did it like this:

(I know that most of this code doesn't make sense without the rest of the program. Just focus on how the view and the character's coordinates change at the same rate when the character is 300 pixels to the right of the x value of the view)

Code: [Select]

if (ventana.GetInput().IsKeyDown(sf::Key::Left) && (animar_x > 0) )
{
caminando_izq = true;
if (caminando_der == true) arranque = -50;
caminando_der = false;

///////// View movement starts here

if ( (animar_x < (cam_x + 300)) && (cam_x >= 0) )
{cam_x = cam_x + arranque * ventana.GetFrameTime(); cam_x2 = cam_x2 - (-arranque) * ventana.GetFrameTime();}

//////// View movement ends here

///////// Character movement starts here

animar_x = animar_x - (-arranque) * ventana.GetFrameTime();
if (arranque > -400) arranque -= 10;
set_x(animar_x);
}


Hope this helps out.

4
Graphics / Problem with scrolling screen
« on: December 14, 2010, 06:40:16 pm »
I managed to keep the framerate fluid by tiling the background. So, just how big an image can I use on SFML before it starts getting slow? I'm trying to make a Castlevania clone (SNES level) and I would be using sprites of varying dimensions.

5
Graphics / Problem with scrolling screen
« on: December 14, 2010, 09:05:51 am »
Hello, everybody! First of all, let me say that I'm very new to programming, C++ and SFML in general. I'm learning C++ alongside SFML because my ultimate goal is to make video games. So please bear with me if I ask rather stupid questions :D

Well, in my project I've managed to do the following:

- Load images and draw the sprites on the screen.
- Move the playable character.
- Animate the playable character.
- Basic collision detection (using my own half-baked algorithm).
- Scroll the screen.

Being a newbie programmer, I was elated to see these results, but now I'm getting a strange problem which I can't figure out. Allow me to elaborate:

Originally, the game had only one screen, a 800x600 area with a same-sized background image, with the character moving and jumping around. In order to test the scrolling, I drew a second "screen" on the right of the original one, an exact copy of the first screen. When I run the game, it all works fine, except that when I get closer to the rightmost edge of the second screen, the program lags considerably. This problem corrects itself if I move the character back to the first screen.

Since both of the screens are being drawn all the time, I can't figure out why it would matter where exactly on the screen the character is at. I understand that the position of the View and the x,y coordinates of the character become larger, but I don't think it should matter that a couple of floats change value from, say, 600 to 1500.

The code used to scroll the screen is tied to the character class' walking function:

Code: [Select]
if (ventana.GetInput().IsKeyDown(sf::Key::Left) && (animar_x > 0) )
{
caminando_izq = true;
if (caminando_der == true) arranque = 50;
caminando_der = false;

///////// SCROLLING STARTS HERE

if ( (animar_x < (cam_x + 300)) && (cam_x >= 0) )
{cam_x = cam_x - (-arranque) * ventana.GetFrameTime(); cam_x2 = cam_x2 - (-arranque) * ventana.GetFrameTime();}


EDIT: I forgot to say the cam_x ends up in View.Move(cam_x,0)

//////// SCROLLING ENDS HERE

animar_x = animar_x - (-arranque) * ventana.GetFrameTime();
if (arranque > -400) arranque -= 10;
set_x(animar_x);
}

if (ventana.GetInput().IsKeyDown(sf::Key::Right) && (animar_x < 1500) )
{
caminando_der = true;
if (caminando_izq == true) arranque = -50;
caminando_izq = false;

if ( (animar_x > (cam_x2 - 300)) && (cam_x2 <= 1600) )
{cam_x = cam_x + arranque * ventana.GetFrameTime();cam_x2 = cam_x2 + arranque * ventana.GetFrameTime();}

animar_x = animar_x + arranque * ventana.GetFrameTime();
if (arranque < 400) arranque += 10;
set_x(animar_x);
}


(Do forgive the spanish in the code. I'm mexican :) )

Just in case it matters, my collision detection goes something like this:

I created a detector class:

Code: [Select]
class detector {

public:

float x;
float y;
bool chocar;

detector()
{
x = (mono.animar_x + 10); // animar_x and animar_y are the x,y coordinates of the character sprite.
y = mono.animar_y;  
chocar = false;
}

void detectar()
{
y = y + 900 * ventana.GetFrameTime();
x = (mono.animar_x + 10);
if (y > 600) y = mono.animar_y + 30; // This prevents the detector from leaving the screen, which it does when the program lags.
}

}det;


This detector will move downwards from the player at a rate faster than free fall of the player. When it reaches a platform class shape, chocar will turn true, and the platform instance will return the detector to its original position.

Code: [Select]
void plataforma::checar()
{
if ((det.chocar == false) && (det.y > limite_y) && (det.y < by2) && (det.x > bx) && (det.x < bx2))

// This IF basically checks if the detector is inside the shape's boundaries.
{
det.y = limite_y; // limite_y is the topmost edge of the shape.
det.chocar = true;
}
if (det.chocar == true)
{
mono.min_y = det.y;  // mono.min_y is the "y" value that the character will consider the "floor".
det.y = (mono.animar_y + 50); // Return the detector to its starting position.
det.chocar = false;
}
}



Maybe this collision detection process is slowing things down, but I'm not sure.

Also, I wanted to ask: Is an 800x600 image too big to use as background for each screen? Should I split it into smaller tiles and draw only the visible ones?

Well, thanks in advance for any comments.

EDIT: I'm using a lower end computer, with Linux Mint distro using fluxbox. Graphics processing is kinda slow. Games like superTux and Battle for Wesnoth have issues with graphics as well (they are slow and jerky). I supposed that my program was too simple for this to matter, but maybe it's my system...

Pages: [1]
anything