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

Pages: [1] 2
1
Graphics / Re: RectangleShape vs Sprite?
« on: April 27, 2012, 05:49:24 pm »
Ah, I see. I think I'll switch them to sprites now then.

2
Graphics / RectangleShape vs Sprite?
« on: April 27, 2012, 05:55:59 am »
I have used Sprites as my goto for drawing things for a while now, but haven't updated SFML much. Since the release candidate things like textures got added, and it got me thinking about what would be better to use; rectangleshapes or sprites? Are there any performance differences?

And another quick question, is there a way to get the point positions of a rotated rectangleshape? Global positions, so I don't have to calculate them manually but just get them based on how much the shape is rotated. I'm sure there's a way, or else how else are the points stored?

3
Graphics / View problems
« on: April 13, 2011, 04:13:46 am »
Yes thanks! I get it now! I set the viewport to be 0,0,1,0.8333. Thanks man!

4
Graphics / View problems
« on: April 12, 2011, 09:57:30 pm »
That exactly is my problem the green area is 95 pixels high, instead of 80. Measure it yourself if you must. The idea is that it stops moving at 80 pixels, instead of 95.

5
Graphics / View problems
« on: April 12, 2011, 05:14:05 am »
I've done this
Code: [Select]
else if (y > yscreensize - View.GetSize().y / 2  + 80)
sety = yscreensize - View.GetSize().y / 2 + 80;
but now when the sprite is going down, the view only begins going down when the y point is at 240, not 200. So instead of camera moving at 200, it moves at 240. And I don't mean the top of the sprite either, I mean the 20 pixels down point(due to the offset I set). Another thing is that the camera follows it until there is a 95 pixel gap, not an 80 pixel gap. Here is a picture to illustrate what I mean.

The 2 lines represent the center point of the view, the meeting point being 320,200.

6
Graphics / View problems
« on: April 12, 2011, 12:14:49 am »
Basically, I want there to be 80 pixels of room after you can't move anymore, so that the background will be 80 pixels above the edge of the screen after you hit it, which is where the GUI would be.

7
Graphics / View problems
« on: April 11, 2011, 11:00:05 pm »
Ah ok thanks. Let me change the magic numbers (if I understand it correctly)
Code: [Select]
#include <SFML/Graphics.hpp>
#include <iostream>

const int xscreensize = 720;
const int yscreensize = 560;

sf::RenderWindow App(sf::VideoMode(640, 480, 32), "Fail");

sf::View View(sf::FloatRect(0,0,640,400));

void moveview(const sf::Sprite & you){
//fix this
//then remove safety checks on tiles (not needed anymore)

int setx, sety;
int x = you.GetPosition().x + 20;
int y = you.GetPosition().y + 20;

if (x < View.GetSize().x / 2)
setx = View.GetSize().x / 2;

else if (x> xscreensize - View.GetSize().x / 2)
setx = xscreensize - View.GetSize().x / 2;

else
setx = x;

if (y < View.GetSize().y / 2)
sety = View.GetSize().y / 2;

else if (y > yscreensize - View.GetSize().y / 2)
sety = yscreensize - View.GetSize().y / 2;

else
sety = y;

View.SetCenter(setx, sety);
}

int main(){
sf::Image ibackground;
ibackground.LoadFromFile("background.png");
sf::Sprite background;
background.SetImage(ibackground);
sf::Image itest;
itest.LoadFromFile("image.png");
sf::Sprite test;
test.SetImage(itest);
while (App.IsOpened()){
sf::Event Event;
        while (App.GetEvent(Event)){
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }
if (App.GetInput().IsKeyDown(sf::Key::A))
test.Move(-100.f * App.GetFrameTime(), 0);

if (App.GetInput().IsKeyDown(sf::Key::D))
test.Move(100.f * App.GetFrameTime(), 0);

if (App.GetInput().IsKeyDown(sf::Key::W))
test.Move(0, -100.f * App.GetFrameTime());

if (App.GetInput().IsKeyDown(sf::Key::S))
test.Move(0, 100.f * App.GetFrameTime());

if(test.GetPosition().x < 0)
test.SetPosition(0, test.GetPosition().y);

if(test.GetPosition().x + test.GetSize().x >xscreensize)
test.SetPosition(xscreensize - test.GetSize().x, test.GetPosition().y);

if(test.GetPosition().y < 0)
test.SetPosition(test.GetPosition().x, 0);

if(test.GetPosition().y + test.GetSize().y > yscreensize)
test.SetPosition(test.GetPosition().x , yscreensize - test.GetSize().y);

moveview(test);
App.Clear();
App.SetView(View);
App.Draw(background);
App.Draw(test);
App.Display();
}
return 0;
}


Just to make sure I get views, if I draw a sprite with SetView() changed, it will get that view's position and subtract it from the sprite, and then draw it? I'm only talking about the position, not rotation and stuff. Also does a view affect a sprite's origin?

8
Graphics / View problems
« on: April 11, 2011, 10:22:14 pm »
Basically the player overshoots 80 pixels in the Y axis direction (which is where a GUI will reside, basically obscuring the player). So he should stop moving at position x,400 and so should the view, instead of x,480. Also, can you explain what exactly change view does? Does it alter the co ordinates, converts them, or what? My idea is it gets the position of the view, and then subtracts that from the item being drawn.

9
Graphics / View problems
« on: April 11, 2011, 01:32:42 am »
Here, I tried. The problem is that the view stops following you when you get close to the bottom, but you can hit the bottom (where there would be a 80 pixels high GUI)
Code: [Select]
#include <SFML/Graphics.hpp>
#include <iostream>

sf::RenderWindow App(sf::VideoMode(640, 480, 32), "Fail");

sf::View View(sf::FloatRect(0,0,640,400));

void moveview(const sf::Sprite & you){
//fix this
//then remove safety checks on tiles (not needed anymore)

int setx, sety;
int x = you.GetPosition().x + 20;
int y = you.GetPosition().y + 20;

if (x < 320)
setx = 320;

else if (x> 18 * 40 - 320)
setx = 18 * 40 - 320;

else
setx = x;

if (y < 200)
sety = 200;

else if (y > 14 * 40 - 200)
sety = 14 * 40 - 200;

else
sety = y;

View.SetCenter(setx, sety);
}

int main(){
sf::Image ibackground;
ibackground.LoadFromFile("background.png");
sf::Sprite background;
background.SetImage(ibackground);
sf::Image itest;
itest.LoadFromFile("image.png");
sf::Sprite test;
test.SetImage(itest);
while (App.IsOpened()){
sf::Event Event;
        while (App.GetEvent(Event)){
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }
if (App.GetInput().IsKeyDown(sf::Key::A))
test.Move(-100.f * App.GetFrameTime(), 0);

if (App.GetInput().IsKeyDown(sf::Key::D))
test.Move(100.f * App.GetFrameTime(), 0);

if (App.GetInput().IsKeyDown(sf::Key::W))
test.Move(0, -100.f * App.GetFrameTime());

if (App.GetInput().IsKeyDown(sf::Key::S))
test.Move(0, 100.f * App.GetFrameTime());

if(test.GetPosition().x < 0)
test.SetPosition(0, test.GetPosition().y);

if(test.GetPosition().x + test.GetSize().x >18 *40)
test.SetPosition(18 * 40  - test.GetSize().x, test.GetPosition().y);

if(test.GetPosition().y < 0)
test.SetPosition(test.GetPosition().x, 0);

if(test.GetPosition().y + test.GetSize().y >14 *40)
test.SetPosition(test.GetPosition().x , 14 * 40 - test.GetSize().y);

moveview(test);
App.Clear();
App.SetView(View);
App.Draw(background);
App.Draw(test);
App.Display();
}
return 0;
}

10
Graphics / View problems
« on: April 10, 2011, 09:00:31 pm »
Yeah sorry about that, it was pretty stupid to ask without any info. Here is the move view code
Code: [Select]
void cmainchar::moveview(cmap * maps){
//fix this
//then remove safety checks on tiles (not needed anymore)
if(teleport){
spawn = true;
fall = 0.f;
jump = 0.f;
maps->changemap(this, spawn);
teleport = false;
}
int setx, sety;
int x = you.GetPosition().x + 20;
int y = you.GetPosition().y + 20;
//posx and posy is the size of the map. it is multiplied by 40 due to the size of the tiles (40 by 40)
if (x < 320)
setx = 320;

else if (x> maps->posx * 40 - 320)
setx = maps->posx *40 - 320;

else
setx = x;

if (y < 200)
sety = 200;

else if (y > maps->posy * 40 - 200)
sety = maps->posy * 40 - 200;

else
sety = y;

View.SetCenter(setx, sety);
std::cout << you.GetPosition().y << " " << View.GetCenter().y - 200 << " " << View.GetSize().y << std::endl;
}

The character is 40 by 60 pixels, and the view is 640 by 400 on the coordinates 0,0. I use App.SetView(View) before drawing the character, although I am unsure of what that does exactly(this is probably the error, but I am unsure, so if you can explain what exactly it does, I would appreciate it). The cout gives this information:Ypostion 460 YviewTop 120 YviewSize 400. So there is no reason why the character isn't in view. There is a GUI obscuring the bottom of the screen that is 80 pixels high and 640 long. The character resides on the bottom of the screen, his feet touching the bottom. So the character's actual position is 580.

11
Graphics / View problems
« on: April 10, 2011, 02:32:21 am »
Ok, I have run into even more troubles. I have a view that is meant to follow the character and stop when it hits the edge of the map. The character is set to the position 320, 460 and the camera's center is 320, 360. Why doesn't the camera/view display the character? I used setview() before drawing the character.

12
Graphics / View problems
« on: April 09, 2011, 06:32:00 pm »
Oh ok thanks I get it now.

13
Graphics / View problems
« on: April 09, 2011, 05:06:55 am »
I have been using a view to display the screen of my game, and then there would be a GUI at the bottom. My problem right now is actually grasping what the view functions do. Does setcenter() move the view itself i.e. move the screen inside the actual window, or move everything in the screen but the window stays? Basically, imagine a window on a computer monitor. Does set center move the window, or the monitor itself? (monitor = view, window = things in view).

Also, how can I go about making a camera that follows the player? Do I use set center, or what? I have one that isn't working very well, but the character is able to be rendered outside of the view's co ordinates. This might be because I am using setcenter() and if it is, what should I use instead.

Thanks in advance, and if you need clarifications, I will try as hard as I can.

14
Graphics / SFML2 Exception while drawing sf::Text
« on: December 30, 2010, 11:33:34 pm »
Thanks Laurent.

15
Graphics / SFML2 Exception while drawing sf::Text
« on: December 30, 2010, 11:11:31 pm »
Same problem for me. Oh and do the latest ATi drivers work with SFML 2 yet?

Pages: [1] 2