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

Pages: 1 ... 7 8 [9]
121
General discussions / SFML Scaling
« on: December 10, 2009, 04:56:13 am »
Thanks i will try

122
General discussions / SFML Scaling
« on: December 09, 2009, 04:52:53 pm »
Thanks for replying. I did try it, but the character was just going crazy, i guess i didn't think it through enough. I will try it again soon and see if i can get it to work, otherwise i will post you the code.

123
General discussions / SFML Scaling
« on: December 09, 2009, 03:30:00 am »
hm, so what i will do is instead of changing X and Y i say to it that it should move the Center position towards the target? I will experiment a bit and get back to you.

edit: I will show you what i think will happen though.

[/img]

It only does math at the time that i press the mouse button. So it would move the characters feet to that point, but the feet will not be where it thinks they are since they have moved due to scaling?

Now if i update the path all the time (hold mouse button) It will look something like this with the current code. Maybe not as extreme but very very noticable. (Moving a bit curved)



I would buy your argument about the center thing if the scaling would not be done from below aswell. It seems that it moves the characters feet upwards because it's scaling. I believe i already do it your way. I use the center thing, but with my own code not the function, if i am wrong and you can show me an example what would be changed in the code that would be great because i don't understand.


To further demonstrate what i mean i will show you 2 examples. One where it scales as i would like it to, and the other one that scales in some other way.



Left side is good. Right side is bad.

124
General discussions / SFML Scaling
« on: December 08, 2009, 08:54:05 pm »
I really don't understand what you are getting at. I already have a center, why would it matter if i use the function for center or not? It will still calculate the path based on what the center is when i press, and then start moving, but since the character size changes upwards etc it will not end up in the right position. I don't see how what you are saying would solve anything. The only possible solution how i see it would be to move the characters actual CENTER both x and y center to a position instead of the feet because then it wouldn't matter how much every side scales. But i would like his feet to end up where i press. Or do something like i have been trying, but i have been unsuccesful at it for some reason.

I have tried to calculate how much it moves too much and remove that extra movement (made by scaling the char). This is how i tried it but it's not working:

Code: [Select]
characterXBeforeMovement = Character.GetPosition().x;
characterYBeforeMovement = Character.GetPosition().y;
//Move Char
   if (moveLeft == true)
      character.x -= character.stepX;
   else if (moveRight == true)
        character.x += character.stepX;
   if (moveUp == true)
      character.y -= character.stepY;
   else if (moveDown == true)
        character.y += character.stepY;


}
else
animation = Standing;


//Set Scale
Character.SetScale(character.y / screenHeight, character.y / screenHeight);

characterWidth = Character.GetSize().x;
characterHeight = Character.GetSize().y;

//From struct to drawable
Character.SetPosition(character.x, character.y);

if (characterYBeforeMovement > Character.GetPosition().y)
character.y -= characterYBeforeMovement - Character.GetPosition().y - character.stepY;

else if (Character.GetPosition().y > characterYBeforeMovement)
character.y += Character.GetPosition().y - characterYBeforeMovement - character.stepY;

if (characterXBeforeMovement > Character.GetPosition().x)
character.x -= characterXBeforeMovement - Character.GetPosition().x - character.stepX;

else if (Character.GetPosition().x > characterXBeforeMovement)
character.x += Character.GetPosition().x - characterXBeforeMovement - character.stepX;

//From struct to drawable
Character.SetPosition(character.x, character.y);


If you still believe that the character center thing will work please explain it better to me so even i can understand

125
General discussions / SFML Scaling
« on: December 08, 2009, 06:59:45 pm »
I believe that wont make any differance since it calculates where to move when i press the mouse button, and then the "center" is at the feet at they are at the time, but as it moves it scales in all kinds of directions and the feet will no longer end up at the end position (unless i hold the mouse button down, although then it will move in sort of a curve since the end pos changes all the time), but thanks for posting.

126
General discussions / SFML Scaling
« on: December 07, 2009, 04:44:04 am »
I've been trying a bit more. Atm i do this

Code: [Select]
//Adjustment for scaling
if (moveUp == true){
character.y += (characterHeightLastFrame - characterHeight) * 0.57;
character.x += (characterWidthLastFrame - characterWidth) * 0.13;
}
else if (moveDown == true){
character.y -= (characterHeight - characterHeightLastFrame) * 0.57;
character.x -= (characterWidth - characterWidthLastFrame) * 0.13;
}


But it's still not good. far from it.

Noone have any suggestions of how else i could do something about the way it scales?

127
General discussions / SFML Scaling
« on: December 06, 2009, 04:49:51 am »
I've made a video clip to show you the differance between when i scale, and when i don't scale. The bottom of the character scales upwards i believe, and the top a bit aswell i think. The bottom center is supposed to end up at the end location, but since it goes upwards it will not, and it will have to adjust the last part. Don't pay too much attention to the character not stopping movement atm, that is a minor issue. I will paste you the link:

128
General discussions / SFML Scaling
« on: December 06, 2009, 12:24:48 am »
Hi. I am making a game in 2d, but will look 3D. So when i'm doing this i want to use the SFML Scale function, but it seems like it shrinks both the bottom and the top, so when i walk inwards or outwards with the character he walks too fast because his feet are moved up / down (inwards / outwards). So i did this:

Code: [Select]
float characterHeightLastFrame = Character.GetSize().y;

//Set Scale
Character.SetScale(character.y / screenHeight, character.y / screenHeight);

characterWidth = Character.GetSize().x;
characterHeight = Character.GetSize().y;

//Adjustment for scaling
if (moveUp == true)
character.y += (characterHeightLastFrame - characterHeight) * 0.5;
else if (moveDown == true)
character.y -= (characterHeight - characterHeightLastFrame) * 0.5;


That was better, but he walks faster down (outwards), than inwards. So i tried this:

Code: [Select]
//Adjustment for scaling
if (moveUp == true)
character.y += (characterHeightLastFrame - characterHeight) * 0.2;
else if (moveDown == true)
character.y -= (characterHeight - characterHeightLastFrame) * 0.8;


Then it looks better, but does anyone have any idea why it is like this, and any exact numbers on how much it scales each direction? (Prefferably math i can understand, like my 0.2 / 0.8), and maybe the X axis aswell.

Thanks for your time.

Edit: the more i think about this the less i understand it and i probably did it the wrong way trying to solve it, i hope you can help me with it. Also i guess this line is important since it sets the speed.

Code: [Select]
//Speed of character
character.speed = 1 * Character.GetPosition().y / screenHeight;


Full code:

Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>



struct sSlot{
       int xMin;
       int xMax;
       int yMin;
       int yMax;
       int itemNumber;
       };

struct sCharacter{
       float x;
       float y;
       int xCenter;
       int yCenter;
       float stepX;
       float stepY;
       float speed;
       };


sCharacter character;

void moveIconsInSlots(int a, int bX, int bY,
     sf::Sprite *inventoryIcon){
     for (int d = 0; d<=15; d++){
        if (a == d)
            inventoryIcon[d].SetPosition(bX, bY);
     }
}


int main(int argc, char** argv)
{
sf::WindowSettings Settings;
Settings.DepthBits         = 24; // Request a 24 bits depth buffer
Settings.StencilBits       = 8;  // Request a 8 bits stencil buffer
Settings.AntialiasingLevel = 2;  // Request 2 levels of antialiasing

//Create the Window
sf::RenderWindow App(sf::VideoMode(1280, 1024, 32), "SFML Game", sf::Style::Fullscreen, Settings);

// Limit FPS
App.SetFramerateLimit(0);

//Vertical sync
App.UseVerticalSync(true);

//Load Images
sf::Image Image[5];

if (!Image[0].LoadFromFile("Background.png"))
    return 0;
sf::Sprite background;
background.SetImage(Image[0]);

if (!Image[1].LoadFromFile("InventoryBag.png"))
    return 0;
sf::Sprite inventoryBag;
inventoryBag.SetImage(Image[1]);

if (!Image[2].LoadFromFile("character.png"))
    return 0;
sf::Sprite Character;
Character.SetImage(Image[2]);

if (!Image[3].LoadFromFile("InventoryIcons.png"))
    return 0;
sf::Sprite inventoryIcon[16];
for (int i = 0; i<=15; i++){
inventoryIcon[i].SetImage(Image[3]);
}

//Set Rects in inventoryIcon Images
int numItemRows = 4;
int numItemCols = 4;
int iconWidth = 79;
int iconHeight = 79;
int icon = 0;
for (int colk = 0; colk < numItemCols; colk++){
    for (int rowk = 0; rowk < numItemRows; rowk++) {
        int iconLeft = rowk *(iconWidth + 1);
        int iconTop = colk *(iconHeight + 1);
        int iconRight = iconLeft + iconWidth;
        int iconBottom = iconTop + iconHeight;
        inventoryIcon[icon].SetSubRect(sf::IntRect(iconLeft,iconTop,iconRight,iconBottom));
        icon += 1;
    }
}


//Set invisible color
sf::Color ColorKey(255, 0, 255, 255);
for (int i = 0; i<=4; i++){
Image[i].CreateMaskFromColor(ColorKey, 0);
}


// Get the backgrounds dimensions
int screenWidth = background.GetSize().x;
int screenHeight = background.GetSize().y;
// Get the Characters dimensions
int characterWidth = Character.GetSize().x;
int characterHeight = Character.GetSize().y;
//Set Positions
inventoryBag.SetPosition(screenWidth - 521, screenHeight - 431);
character.x = screenWidth / 2 - characterWidth / 2;
character.y = screenHeight - characterHeight;

//Inventory Slots
sSlot Slot[16]=
{
{921, 1000, 673, 752, 0},
{1004, 1083, 673, 752, 1},
{1087, 1166, 673, 752, 2},
{1170, 1249, 673, 752, 3},
{921, 1000, 756, 835, 4},
{1004, 1083, 756, 835, 5},
{1087, 1166, 756, 835, 6},
{1170, 1249, 756, 835, -1},
{921, 1000, 839, 918, -1},
{1004, 1083, 839, 918, -1},
{1087, 1166, 839, 918, -1},
{1170, 1249, 839, 918, -1},
{921, 1000, 922, 1001, -1},
{1004, 1083, 922, 1001, -1},
{1087, 1166, 922, 1001, -1},
{1170, 1249, 922, 1001, -1}
};


bool inventory = false;
int ax;
int ay;
int itemOnMouse = -1;
int mousePos;
int dragFromSlot;
int a = 0;
int bX = 0;
int bY = 0;
bool mouseOnInventory = false;
float moveToX = character.x + characterWidth / 2;
float moveToY = character.y + characterHeight;
bool movement = false;
float rangeX = 1;
float rangeY = 1;
bool animationStanding = true;
bool animationLeft = false;
bool animationRight = false;
bool animationUp = false;
bool animationDown = false;
bool animationUpLeft = false;
bool animationUpRight = false;
bool animationDownLeft = false;
bool animationDownRight = false;
bool moveLeft = false;
bool moveRight = false;
bool moveUp = false;
bool moveDown = false;


while (App.IsOpened())
{
sf::Event Event;
    while (App.GetEvent(Event))
    {
        // Window closed
        if (Event.Type == sf::Event::Closed)
            App.Close();

        // Key Pressed
        if (Event.Type == sf::Event::KeyPressed){
            //Quit
            if (Event.Key.Code == sf::Key::Escape)
            App.Close();
            //Screenshot
            if (Event.Key.Code == sf::Key::F12){
                sf::Image Screen = App.Capture();
                Screen.SaveToFile("screenshot.jpg");
            }
            //Inventory Toggle
            if (Event.Key.Code == sf::Key::I){
                if (inventory == false)
                inventory = true;

                else if (inventory == true)
                inventory = false;
            }
        }
    }
const sf::Input& Input = App.GetInput();
int mouseX = Input.GetMouseX();
int mouseY = Input.GetMouseY();
bool leftButtonDown = Input.IsMouseButtonDown(sf::Mouse::Left);

if (inventory == true){

//Position Determination
mousePos = -1;
    for (int i=0; i<=15; i++){
        if (mouseX >= Slot[i].xMin && mouseX <= Slot[i].xMax && mouseY >= Slot[i].yMin && mouseY <= Slot[i].yMax)
        mousePos = i;
    }
//Item Placing
       //Lift item
    if (leftButtonDown == true && itemOnMouse == -1 && mousePos != -1){
        dragFromSlot = mousePos;
        itemOnMouse = Slot[mousePos].itemNumber;
        Slot[mousePos].itemNumber = -1;
    }
//Item on drop position to start position
    if (leftButtonDown == false && itemOnMouse != -1 && mousePos != -1){
        Slot[dragFromSlot].itemNumber = Slot[mousePos].itemNumber;;
    }
    //Drop item
    if (leftButtonDown == false && itemOnMouse != -1){
        if (mousePos != -1)
            Slot[mousePos].itemNumber = itemOnMouse;

        else if (mousePos == -1)
            Slot[dragFromSlot].itemNumber = itemOnMouse;

itemOnMouse = -1;
    }
}
//Icons Position
for (int i = 0; i<=15; i++){
       moveIconsInSlots(Slot[i].itemNumber, Slot[i].xMin, Slot[i].yMin,
       inventoryIcon);
}


if (itemOnMouse != -1)
    inventoryIcon[itemOnMouse].SetPosition(mouseX, mouseY);


//   ####################   END OF INVENTORY CODE    ####################


//      ####################   MOVEMENT CODE   ####################
//Speed of character
character.speed = 1 * Character.GetPosition().y / screenHeight;

//Mouse on Inventory?
if (inventory == true && mouseX >= inventoryBag.GetPosition().x + 100 &&
   mouseY >= inventoryBag.GetPosition().y)
   mouseOnInventory = true;
   else
   mouseOnInventory = false;

//                    Movement Calculations
//Toggle Movement
if (leftButtonDown == true && mouseOnInventory == false && itemOnMouse == -1){
   moveToX = mouseX;
   moveToY = mouseY;
}

//Set Center of Character
character.xCenter = character.x + characterWidth / 2;
character.yCenter = character.y + characterHeight / 2;

if (character.xCenter != moveToX || (character.y + characterHeight) != moveToY)
   movement = true;
else
    movement = false;

if (movement == true){
   animationStanding = false;

//Movement Direction Left/Right
   if (moveToX < character.xCenter)
      moveLeft = true;
   else
       moveLeft = false;
   if (moveToX > character.xCenter)
      moveRight = true;
   else
       moveRight = false;

//Movement Direction Up/Down
   if (moveToY < (character.y + characterHeight))
      moveUp = true;
   else
       moveUp = false;
   if (moveToY > (character.y + characterHeight))
      moveDown = true;
   else
       moveDown = false;


   if (leftButtonDown == true){
//Range to end Pos
      if (moveLeft == true)
         rangeX = character.xCenter - moveToX;
      else if (moveRight == true)
           rangeX = moveToX - character.xCenter;

      if (moveUp == true)
         rangeY = (character.y + characterHeight) - moveToY;
      else if (moveDown == true)
           rangeY = moveToY - (character.y  + characterHeight);


   }
//Character Step
character.stepX = rangeX / (rangeX + rangeY) * 16 * character.speed;
character.stepY = rangeY / (rangeX + rangeY) * 16 * character.speed;

}
else
animationStanding = true;

float characterHeightLastFrame = Character.GetSize().y;

//Set Scale
Character.SetScale(character.y / screenHeight, character.y / screenHeight);

characterWidth = Character.GetSize().x;
characterHeight = Character.GetSize().y;

//Adjustment for scaling
if (moveUp == true)
character.y += (characterHeightLastFrame - characterHeight) * 0.0;
else if (moveDown == true)
character.y -= (characterHeight - characterHeightLastFrame) * 1.0;

//From struct to drawable
Character.SetPosition(character.x, character.y);

//Background
App.Draw(background);
//Character
App.Draw(Character);
if (inventory == true){
    //Inventory
    App.Draw(inventoryBag);
    //Icons in slots
    for (int i = 0; i<=15; i++){
        if (Slot[0].itemNumber == i || Slot[1].itemNumber == i || Slot[2].itemNumber == i || Slot[3].itemNumber == i ||
            Slot[4].itemNumber == i || Slot[5].itemNumber == i || Slot[6].itemNumber == i || Slot[7].itemNumber == i ||
            Slot[8].itemNumber == i || Slot[9].itemNumber == i || Slot[10].itemNumber == i || Slot[11].itemNumber == i ||
            Slot[12].itemNumber == i || Slot[13].itemNumber == i || Slot[14].itemNumber == i || Slot[15].itemNumber == i)
            App.Draw(inventoryIcon[i]);
    }
}
//Icons on mouse
if (itemOnMouse != -1)
App.Draw(inventoryIcon[itemOnMouse]);

App.Display();
}

return 0;


}

Pages: 1 ... 7 8 [9]
anything