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.


Topics - dotty

Pages: [1]
1
Graphics / Sprite layering
« on: March 14, 2012, 09:14:06 pm »
Hay all, I've made a "SpriteManager" class which takes a bunch of "gameObjects" (which is a class which inherits from sf::Sprite) and sorts them by their zIndex. The SpriteManager then draws the gameObjects to the screen based on their zIndex.

This gives me a lot more control over the ordering of the sprites. However there still seems to be an issue where the ordering does sit right. It seems that the only way to do this correct is to sort them by how they appear on the screen. The sprites at the very top of the screen are drawn first and the ones at the bottom are drawn last.

Is this the only way to do this? What other ways are there to tackle this problem

2
Graphics / Collision with FloatRect
« on: February 21, 2012, 01:16:09 pm »
Hello, I need some advice on collisions. I have setup 2 RectangleShapes and setup up 2 FloatRect around them. One of the shapes is moved around using this code

Code: [Select]

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::W )) {
      this->velocity.y -= this->deltatime;
   }

   if (sf::Keyboard::IsKeyPressed( sf::Keyboard::S )) {
      this->velocity.y += this->deltatime;
   }

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::A )) {
      this->velocity.x -= this->deltatime;
   }

   if (sf::Keyboard::IsKeyPressed( sf::Keyboard::D )) {
      this->velocity.x += this->deltatime;
   }


(Thanks Laurent!).

The FloatRect also move with the moveable box. I've modified the code so that when the 2 boxes intersect the movable box is no longer movable in that direction. The problem is that this code is only run once the boxes intersect, meaning I'm already inside the box and cannot get out.

This must be an obvious issue, but how would one go about fixing it?

3
Window / Moving a shape along both axis using sf::Vector2f
« on: February 20, 2012, 05:13:20 pm »
Hello, I read here a couple of days ago about using a Vector2f to process my movement, this seemed an obvious thing once I read it. However, I'm getting a little confused by it.

I have an Update() method which gets run every frame, I also have a ManageInput() method as well, which also get's run every frame.

The Update() method also runs this code

Code: [Select]

this->shape.Move( this->velocity );


this->velocity is obviously the Vector2f in question. The ManageInput() method is just a series of IF statements checking for W,A,S and D keyPresses. Here's a sample of this code

Code: [Select]

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::W )) {
this->velocity = sf::Vector2f(0, -1) * this->deltatime;
}

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::S )) {
this->velocity = sf::Vector2f(0, 1) * this->deltatime;
}

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::A )) {
this->velocity = sf::Vector2f(-1, 0) * this->deltatime;
}

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::D )) {
this->velocity = sf::Vector2f(1, 0) * this->deltatime;
}


However, using this code I can only move along 1 axis at a time.

If I modify this code to look like this

Code: [Select]

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::W )) {
this->shape.Move(sf::Vector2f(0, -1)) * this->deltatime;
}

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::S )) {
this->shape.Move(sf::Vector2f(0, 1)) * this->deltatime;
}

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::A )) {
this->shape.Move(sf::Vector2f(-1, 0)) * this->deltatime;
}

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::D )) {
this->shape.Move(sf::Vector2f(1, 0)) * this->deltatime;
}


It works as expected, allows me to both on both axis. How would I modify the top code to work as I want it to.

4
Window / Can i pass a RenderWindow to another class
« on: February 16, 2012, 02:24:57 pm »
Can I pass a RenderWindow object to another class and use it's method (like .Draw()) inside the other class, rather having to run Draw a million times in my main.cpp file?

5
Graphics / checking circular collisions
« on: February 15, 2012, 08:19:11 pm »
Hello, I know I can use IntRect() which have some decent methods for working out collisions between them. How would I go about doing this with circular shapes?

6
Graphics / What's a decent file size for a single sprite sheet?
« on: February 05, 2012, 12:00:16 am »
As the subject implies, what's a decent file size for single sprite sheet? kbs? mbs? What filesize should I not be exceeding?

7
System / IsKeyPressed seems to not fire all the time.
« on: January 26, 2012, 11:31:08 pm »
Hello, I have a strange thing going on. I've wrote this block of code which monitors the W,A,S and D keys. If the key is up then the state is set to 0, if it's pressed it's 1 and if it's held it's 2. Now, the problem comes if I press all 4 keys at the same time, none of the states change. Also if I hold the keys one by one only 3 of the 4 states change.

If you run the code below and open up your console it logs the keys every frame, then try pressing the keys and you'll notice the issues.

Code: [Select]

#include <SFML/Graphics.hpp>

int main () {

sf::RenderWindow window(sf::VideoMode(640, 480, 32), "SFML Key Test");
window.SetFramerateLimit(60);

bool wKey;
bool aKey;
bool sKey;
bool dKey;

bool wHeld;
bool aHeld;
bool sHeld;
bool dHeld;

int wState;
int aState;
int sState;
int dState;


while (window.IsOpened()){
sf::Event event;
        while (window.PollEvent(event)){
            if (event.Type == sf::Event::Closed){
                window.Close();
}


}


window.Clear();

wKey = sf::Keyboard::IsKeyPressed(sf::Keyboard::W);

if (wKey) {
if (!wHeld) {
wState = 1;
wHeld=true;
}else {
wState = 2;
}
}else {
wHeld = false;
wState = 0;
}

dKey = sf::Keyboard::IsKeyPressed(sf::Keyboard::D);

if (dKey) {
if (!dHeld) {
dState = 1;
dHeld=true;
}else {
dState = 2;
}
}else {
dHeld = false;
dState = 0;
}

sKey = sf::Keyboard::IsKeyPressed(sf::Keyboard::S);

if (sKey) {
if (!sHeld) {
sState = 1;
sHeld=true;
}else {
sState = 2;
}
}else {
sHeld = false;
sState = 0;
}

aKey = sf::Keyboard::IsKeyPressed(sf::Keyboard::A);

if (aKey) {
if (!aHeld) {
aState = 1;
aHeld=true;
}else {
aState = 2;
}
}else {
aHeld = false;
aState = 0;
}

printf("W:%i A:%i S:%i D:%i\n", wState, aState, sState, dState);

window.Display();

}

return EXIT_SUCCESS;

}


8
Window / logging a series of key presses
« on: January 25, 2012, 05:37:39 pm »
Hay, I'm wondering what peoples thoughts are solving my problem.
 I want to develop a system that records a series of button presses.
These act like a "combo" on many platform games.
Say i press the keys L,O,P very quickly, that would preform a certain action.
 These 'combos' are going to be stored in an array like int[LKEYCODE, OKEYCODE, PKEYCODE].
However I want to these to only match if the time between each key press is < 0.5 seconds.

How would one go about creating something like this?

9
System / Only want a function to get called once on a keyDown.
« on: January 23, 2012, 11:23:15 pm »
Hello, I'm using AniSprite to animate my sprites, this works well and I can play animation with ease.

When I press D on my keyboard I'm adding some velocity to move my sprite, but at the same time I'm calling AniSprite.Play(0,5); to play the animation. The obvious issue here is that Play(0,5) is called every frame, so that the animation never actually starts.

How do people get around this?

10
System / Do something every 10 frames
« on: January 22, 2012, 11:03:30 pm »
Hay, I'm using window.GetElapsedTime() to keep my framerate consistent across multiple computers.

How would I use this to see if 10 frames have passed? So every 10 frames do something?

11
Graphics / Is it possible to draw FloatRects to the screen?
« on: January 22, 2012, 07:34:31 pm »
As the title suggests, I'm using FloatRects for some collision detection. Is it possible to draw these to the screen so I can see their positions? I know I could simple copy the attributes of said FlaotRect then create a Shape, but I'm wondering if it's possible without the need of using Shape.

Thanks!

12
Graphics / Jump doesn't realistically
« on: January 20, 2012, 08:40:27 pm »
Hay I have a simple script which makes my sprite jump.

I have this line being fired every frame

Quote
   this->sprite.Move( (this->deltaTime * this->xVelocity), (this->jumpSpeed * this->deltaTime) * this->yVelocity);


And when my jump button is pressed this code gets run

Quote
this->yVelocity = -this->weight;
      if (this->sprite.GetPosition().y < apex) {
         this->isJumping = false;
      }


This works well. I hit jump, my character jumps, reaches a peak then drops down. However, my movement is more like an upside down V rather than an arch. How would I accomplish a more "real" jump effect?

13
Graphics / Is it possible to rotate a FloatRect to detect collisions?
« on: January 15, 2012, 07:15:14 pm »
Hay, I've been playing with FloatRect and some collisions and it's going well.  This is a simple sample I have made which draws 2 boxes, one of which is movable. It logs whether or not they are colliding. How would I edit this so that I can detect if a rotated Rect is colliding? I see that FloatRect cannot be rotated.

Code: [Select]
#include <SFML/Graphics.hpp>

int main () {

// Setup a window and limit the framerate
sf::RenderWindow window(sf::VideoMode(640, 480, 32), "SFML Graphics");
window.SetFramerateLimit(60);

// Set up a Vector2 to hold the colliders size (this will also be the box size)
sf::Vector2f colliderSize(50.0f, 50.0f);

// Set up a Vector2 to hold boxA and boxB's positions
sf::Vector2f boxAPosition(0.0f, 0.0f);
sf::Vector2f boxBPosition(200.0f, 200.0f);

// Setup box A
sf::RectangleShape boxA;
boxA.SetSize(colliderSize);
boxA.SetPosition(boxAPosition);
boxA.SetFillColor(sf::Color::Red);

// Setup box B
sf::RectangleShape boxB;
boxB.SetSize(colliderSize);
boxB.SetPosition(boxBPosition);
boxB.SetFillColor(sf::Color::Green);

// Box B will never move in this demo, so we'll set the IntRect outside the game loop
sf::FloatRect rectB(boxBPosition, colliderSize);



// Main Loop
while (window.IsOpened()){

sf::Event event;
        while (window.PollEvent(event)){
            if (event.Type == sf::Event::Closed){
                window.Close();
}
        }

// Setup buttons
bool leftBtn = sf::Keyboard::IsKeyPressed(sf::Keyboard::Left);
bool rightBtn = sf::Keyboard::IsKeyPressed(sf::Keyboard::Right);
bool downBtn = sf::Keyboard::IsKeyPressed(sf::Keyboard::Down);
bool upBtn = sf::Keyboard::IsKeyPressed(sf::Keyboard::Up);

// Setup deltaTime and the speed in wich the boxes will move
float deltaTime = window.GetFrameTime();
float moveSpeed = 0.1f;

// Movement
if (leftBtn) {
boxA.Move(-moveSpeed * deltaTime, 0);
}

if (rightBtn) {
boxA.Move(moveSpeed * deltaTime, 0);
}

if (upBtn) {
boxA.Move(0, -moveSpeed * deltaTime);
}

if (downBtn) {
boxA.Move(0, moveSpeed * deltaTime);
}

// rectA will need to be updated everyframe
sf::FloatRect rectA( sf::Vector2f(boxA.GetPosition().x, boxA.GetPosition().y), colliderSize);

window.Clear();
window.Draw(boxA);
window.Draw(boxB);
window.Display();

if (rectA.Intersects(rectB)) {
printf("intersecting\n");
}else{
printf("not intersecting\n");

}




};


return EXIT_SUCCESS;
}

14
Graphics / Loading an image with OS X
« on: January 15, 2012, 03:42:20 pm »
Hello, this might end up being an embarrassing question. I'm new to XCODE and C++, but I'm learning quickly (I have a programming background, so just learning how c++ does things is the biggest issue I'm having at the moment).

I'm having difficulty using texture.LoadFromFile(). My main main.cpp file is stored under playground/ and under here I have a folder called "assets" and within that I have an image "sprite.png". I'm trying to load this with XCODE, I use texture.LoadFromFile("assets/sprite.png") and return -1 if it fails to load the file. This always exit's the program saying it can't load the file in quesion. Is there anything else I need to do to load this file?

Thanks!

15
General / Uninstalling 2.0 on OS X
« on: January 15, 2012, 12:29:45 pm »
Hay, I'm having difficulties getting 2.0 to work, so I wish to uninsall it and revert back to 1.6 untill 2.0 gets an official released. Can anyone share some information on doing this? Also, when 2.0 get's released we we have templates for XCODE 3 like we did for 1.6?

Pages: [1]
anything