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 - Nolan

Pages: [1]
1
Graphics / Creating an image
« on: June 24, 2011, 09:20:59 am »
Hello, I'm creating a platform game, and i've got everything working so far, but rendering the map is incredibly inefficient. I was wondering how I could speed things up, or just create an image and load that, instead of displaying every piece of the map every single time.

Code: [Select]
void InitBox(int x, int y, int Size,sf::Color Color)
{
Box.AddPoint(0, 0, Color,Color);
Box.AddPoint(Size, 0,Color,Color);
Box.AddPoint(Size, Size,Color,Color);
Box.AddPoint(0, Size,Color,Color);
Box.SetCenter(0,0);
Box.SetPosition(x,y);
Window.Draw(Box);
}


That's the function that I call to display each tile. What can I do to make my game more playable?[/code]

2
General / Obstacles
« on: June 15, 2011, 10:45:57 pm »
Without using GetPixel (Because it is awfully slow and I don't think I'm getting the right DC to the window), what's the best method to implement obstacles / multiple objects?

Thanks in advance :)

3
General / Laggy / Slowness with hotkeys. / Multiple Hotkeys
« on: June 12, 2011, 05:24:45 pm »
Yeah I realized that after messing around with the code, thanks! I also limit framerate to 60.

4
General / Collision Detection Function Doing Weird Things
« on: June 12, 2011, 04:03:14 am »
x1,y1,x2,y2 being the sprite's centers.

5
General / Collision Detection Function Doing Weird Things
« on: June 12, 2011, 04:02:52 am »
If you have multiple objects, why not just use distance formula?



Code: [Select]

bool cool(x1,y1,x2,y2)
{
  int distance = sqrt(pow((x1-x2),2) + pow((y1-y2),2));
  if distance < 1
     return true
  return false
}

6
General / Laggy / Slowness with hotkeys. / Multiple Hotkeys
« on: June 12, 2011, 12:58:22 am »
I have a couple questions / problems, that I'd love if you guys could help.

a) How would I implement multiple hot keys at once? ex. I can be going left and jumping at the same time without lag / freezing.

b) When moving my sprite, I find that there is a lag before it starts to actually move. How can I fix this?

My code is as follows:

Code: [Select]


#include <SFML/Graphics.hpp>
int pX,pY,Speed = 6;
sf::Event Event;
sf::Sprite Box;
HWND hwnd;
int main()
{
hwnd = FindWindow("Test",NULL);
ShowWindow(hwnd,SW_HIDE);
sf::RenderWindow fa(sf::VideoMode(800,600,256),"Test");
sf::Image image;

if(!image.LoadFromFile("res/Box1.png"))
return EXIT_FAILURE;
Box.SetImage(image);
pY = fa.GetHeight() - (image.GetHeight());
pX = fa.GetWidth() / 2;
while(fa.IsOpened())
{
Box.SetPosition(pX,pY);

while(fa.GetEvent(Event))
{
if (fa.GetInput().IsKeyDown(sf::Key::Left))  pX -= Speed;
if (fa.GetInput().IsKeyDown(sf::Key::Right)) pX += Speed;
if(Event.Type == sf::Event::Closed)
fa.Close();
if(pX > fa.GetWidth()) pX = 0;
}
sf::Image bg;
if(!bg.LoadFromFile("res/background.png"))
return EXIT_FAILURE;
sf::Sprite BG;
BG.SetImage(bg);
BG.SetPosition(0,0);
fa.Clear();
fa.Draw(BG);
fa.Draw(Box);
fa.Display();
}

return 0;
}
[/code]

Pages: [1]
anything