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

Pages: 1 [2]
16
Window / Resizing window.
« on: January 21, 2012, 07:53:31 am »
So here's what I came up with. Notice that we're not moving the sprite around, we're moving the view (camera) around. The other thing is that I think (hope) that this is the wrong way to move the view around, setting it every time, but it's the only way I could find.
Code: [Select]


#include <SFML/Graphics.hpp>

int main()
{
// Set up the window
sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "SFML Sample Application");
   
// Load resources
sf::Image ourImage;
ourImage.Create(64, 64, sf::Color(85, 85, 85));

sf::Texture ourTexture;
ourTexture.Create(64, 64); // Give our texture a width (in pixels)
ourTexture.LoadFromImage(ourImage);

sf::Sprite ourSprite;
ourSprite.SetTexture(ourTexture);
ourSprite.SetPosition(0, 0);
ourSprite.SetScale(5, 5);

// Create our own view (none of that sissy default stuff)
sf::View ourView;
ourView.Reset(sf::FloatRect(100, 100, 400, 200));
ourView.SetViewport(sf::FloatRect(0.f, 0.f, 1.f, 1.f));
Window.SetView(ourView);

// Main loop
while (Window.IsOpen())
{
// Handle Events
sf::Event e;
while (Window.PollEvent(e))
{
// Lets handle the events
switch (e.Type)
{
case sf::Event::Closed:
Window.Close();
break;
case sf::Event::KeyPressed:
// Handle Keyboard input
if(e.Key.Code == sf::Keyboard::W)
ourView.Move(0.f, -10.f); // Move up
else if(e.Key.Code == sf::Keyboard::A)
ourView.Move(-10.f, 0.f); // Move left
else if(e.Key.Code == sf::Keyboard::S)
ourView.Move(0.f, 10.f);// Move down
else if(e.Key.Code == sf::Keyboard::D)
ourView.Move(10.f, 0.f);// Move right
break;
default:
break;
}
}

// Clear the old stuff
Window.Clear(sf::Color(0, 255, 255));

// Re-draw our sprite
Window.Draw(ourSprite);

// Display the window (swap buffers?)
Window.SetView(ourView);
Window.Display();
}
return 0;
}

17
Window / Resizing window.
« on: January 21, 2012, 05:25:11 am »
It's basically a camera. I'm trying to code up a demo, but I built SFML 2, and the tutorials are for 1.6.

18
Window / Resizing window.
« on: January 20, 2012, 05:57:31 am »
Well, I'm a bit of an amateur, but yeah, that should work. I'm tempted to use the System::Clock object instead, but having the game run in a continuous loop like that would peg the CPU, right?

What I mean by the meter thing is this: You can't control how many pixels a user has. How big their screen is is something that is just beyond your control. Because of this, you have to create your own system of measurement that you can convert to pixels during render time. Looking at the Window::View object, I think SFML might even be doing that for you. I'm not sure. I pretty much started it today.

Suppose you did measure by pixels, and your player sprite is 100px^2. Your view might be 800x600px. If the user makes the window smaller, they can change that number without scaling the player (in theory). What happens if the world is shrunk to 90px? The player size doesn't change, so now your collision goes berserk.

Another problem is that if you measure everything in pixels, you can't have fractions. What if your sprite is 33 pixels, and you need to shrink it down 50%, and then expand it by 200%. With floating point numbers you'd go from 33 to 16.5 to 33 again. With pixels (integers) you'd go from 33 -> 16 -> 32. You'd be slowly losing information due to rounding errors.

However, suppose the player is 1 "unit" wide and high, and the world view is 100x100 "units." Each unit, at render time, is equivalent to a certain number of pixels. If the view gets changed, then you can change that number of pixels. Everything is just as many "units" big as it was before, so even though it is drawn the smaller on the screen, everything is still proportionate.

I'm not sure if that makes any more sense...

19
Window / Resizing window.
« on: January 20, 2012, 03:19:52 am »
I'm actually trying to figure this out myself at the moment.

It sounds like you're having two problems: The first is the way you're measuring time, and the second is how you're measuring space.

When you make the window really big, there are more pixels involved, and your video card has to do more work. This means that it takes a longer time to get things done. This means that if you put the player's movement in the main loop (no timer), then the speed can vary depending on how long it takes for the rest of the loop to execute.

One way to handle this would be to have a timer execute everything every so many milliseconds. This means that everything (ideally) happens at fixed intervals. Another way is to measure the time that has passed since the player's move function was called. Then you can use this to calculate how much to move the player in a given direction. If the time has been short, the player only moves a little. If it's been longer, the player moves farther. The net result is that the user moves at a constant speed.

As far as the collision issues go, I'm not completely sure, but I think that it is probably because you're measuring in pixels instead of some other unit. What I mean is that (X, Y) in your game world is relative to the upper-left corner of your screen, instead of some point in space. A better way to handle this is to establish your own unit of distance (lets say meters). If you measure everything in meters, you can preserve relative distances, even when the number of pixels in a meter changes. You can also have fractions of a meter, whereas pixels are discrete values.

I believe the answer in SFML is to use Views.

*whew* That was a lot of text. Sorry about that. Does it help at all? Perhaps you could post some more details of how you're implementing this.

20
General / Trouble getting rid of console in windows
« on: January 19, 2012, 11:01:56 pm »
VC2010. And I'm pretty sure that I started with an empty project. However, in order to make sure, I deleted the whole solution and recreated it using an empty project. Same error.

21
General / Trouble getting rid of console in windows
« on: January 19, 2012, 10:36:50 pm »
Hey fellas, I've been following SFMLCoder's youtube tutorials, and things were going just fine, but I seem to have run into a bit of a snag. I'm working with SFML 2.0 in VC++ 2010 on Windows 7.1.

I want to get rid of the console in the release build, so I went to Project > Configuration Properties > Linker > System and changed SubSystem to Windows (/SUBSYSTEM:WINDOWS). Next, I went to Input and added sfml-main.lib as one of the additional dependencies. However, that doesn't seem to be enough. When I compile my program in the release configuration I get this error:

1>------ Build started: Project: ProjectSnuff, Configuration: Release Win32 ------
1>libcmt.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in MSVCRT.lib(MSVCR100.dll)
1>libcmt.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRT.lib(MSVCR100.dll)
1>libcmt.lib(crt0dat.obj) : error LNK2005: __exit already defined in MSVCRT.lib(MSVCR100.dll)
1>libcmt.lib(crt0dat.obj) : error LNK2005: __cexit already defined in MSVCRT.lib(MSVCR100.dll)
1>libcmt.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in MSVCRT.lib(MSVCR100.dll)
1>libcmt.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRT.lib(MSVCR100.dll)
1>libcmt.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in MSVCRT.lib(MSVCR100.dll)
1>libcmt.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in MSVCRT.lib(cinitexe.obj)
1>libcmt.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in MSVCRT.lib(cinitexe.obj)
1>libcmt.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in MSVCRT.lib(cinitexe.obj)
1>libcmt.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in MSVCRT.lib(cinitexe.obj)
1>libcmt.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in MSVCRT.lib(MSVCR100.dll)
1>libcmt.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRT.lib(MSVCR100.dll)
1>libcmt.lib(mlock.obj) : error LNK2005: __lock already defined in MSVCRT.lib(MSVCR100.dll)
1>libcmt.lib(errmode.obj) : error LNK2005: ___set_app_type already defined in MSVCRT.lib(MSVCR100.dll)
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>MSVCRT.lib(cinitexe.obj) : warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
1>C:\Philadelphia\ProjectSnuff\Release\ProjectSnuff.exe : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I was wondering if you guys have any idea what might be going on? The debug configuration (with the console) works perfectly fine.

I'm also including sfml-graphics.lib, sfml-window.lib, and sfml-system. My code should be right, but it is:
Code: [Select]

#include <SFML/Graphics.hpp>

int main()
{
sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "SFML Sample Application");

while (Window.IsOpen())
{
sf::Event e;
while (Window.PollEvent(e))
{
switch (e.Type)
{
case sf::Event::Closed:
Window.Close();
break;
default:
break;
}
}

Window.Clear(sf::Color(0, 255, 255));
Window.Display();
}
return 0;
}


Thanks for your time!

22
General / Issue with building a window
« on: July 19, 2011, 04:02:24 pm »
Under Properties > Configuration Properties > C/C++ > Preprocessor > Preprocessor Definitions I put:
SFML_DYNAMIC
WIN32
_DEBUG
_CONSOLE

23
General / Issue with building a window
« on: July 19, 2011, 05:20:53 am »
I've been having a similar issue, so I figured I'd post here instead of making a new thread:

I'm going through the tutorials, and I got the first one to work, but when I tried to open up a window, I get a complaint from the linker:
Quote
1>BasicGraphics.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Window::Window(class sf::VideoMode,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned long,struct sf::WindowSettings const &)" (__imp_??0Window@sf@@QAE@VVideoMode@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@KABUWindowSettings@1@@Z) referenced in function "public: virtual int __thiscall BasicGraphics::run(void)" (?run@BasicGraphics@@UAEHXZ)
1>C:\Users\...\Documents\Visual Studio 2010\Projects\DDD\Debug\DDD.exe : fatal error LNK1120: 1 unresolved externals


The weird thing is that I was able to use the Clock class successfully, so I'm pretty sure that my include/lib directories are configured correctly... Also under Properties... > Linker > Input > Additional Dependencies I put sfml-system-d.lib and sfml-window-d.lib. Any idea what I could have missed? I'm not very experienced with linking to other libraries.[/quote]

Pages: 1 [2]
anything