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

Pages: [1] 2
1
Thanks for the tip about it not being about the view but was just trying it to test it it worked, currently I have:

Quote
      
for(int i = 0; i < bomb.size(); i++)
   {
        sf::Vector2f playerPos = playSprite.getPosition();
             bomb->getBullet().setPosition(playerPos.x, playerPos.y);
    }

Which works fine but like I said only at 0,0 and then gets offset.


EDIT: Fixed, it was a problem with the movement of the sprite after it's position was set. Thanks for your tips.

2
When the player moves from 0,0 the placed sprites appear on an offset between 0,0 and the playerSprite's position.

I figured this was due to the view changing?

The function gets the sprites ready for a projectile move function that moves all bomb's and works perfectly when the player is at 0,0.

//maybe I should add my view stops moving when a player is beyond a given range(so that it isnt always centered)

3
Graphics / Cant get Sprite position relative to view [solved]
« on: September 23, 2013, 11:22:30 am »
Here's what I have so far, I can get it working perfectly fine if the object to set the position on is the mouse but cant seem to work out how to do it with a sf::Sprite:

Quote
for(int i = 0; i < bomb.size(); i++)
      sf::Vector2f playerPos = playSprite.getPosition();
      int playX = playerPos.x;
      int playY = playerPos.y;
      sf::Vector2i convertedPos;
      convertedPos.x = playX;
      convertedPos.y = playY;
      sf::Vector2f worldPos = win.mapPixelToCoords(convertedPos);
      bomb[ i ]->getBullet().setPosition(worldPos.x, worldPos.y);
I didnt use win.getView() in the mapPixelToCoords function for my mouse but saw it in the documentation so giving it a shot during my debugging :P

Any help much appreciated

edit: removed irrelevant function

4
I don't think a function like that exists, but it's so simple you can just write it yourself.  It might look something like this:

angle_dist(int d1, int d2) {
    if(abs(d2 - d1) > 180)
        if(d2 > d1)
            return (360-d2) + d1;
        else
            return (360-d1) + d2;
    else
        return abs(d2 - d1)
}
(I'll leave the signs for you to figure out)

Thanks I was going to write something similar but wanted to make sure thats how it's normally done in game development(as in for top down rpg's or shooters with 360* rotation).

Edit: Wooo got it!!, even with your help that felt like a minor win hehe :D

int Player::findRotation(int rotation)
{
   int currentRot = playSprite.getRotation();
   int desiredRot = rotation;
   if((desiredRot - currentRot) > 180)
   {
      return -rotation;
   }
}

5
General / Help with proper 360 sprite rotation on keypress... [SOLVED]
« on: September 17, 2013, 12:10:14 pm »
Remember the first/second Grand Theft Auto's? A top down car game with 360* rotation is what im trying to achieve.

Currently my sprite changes direction with .setRotation, but i'd like to implement something fancier(ie: that rotates to that degree rather than jumping straight to it).

I currently have movement setup like:

Quote
if key = w //forward
    if key = d //right
    playSprite.setRotation(315);  //face north east
    if key = a //left
   playSprite.setRotation(225); //face north west
else
   playSprite.setRotation(270); //face north
end if

if key = s //down
    if key = d //right
    playSprite.setRotation(45);  //face south east
    if key = a //left
   playSprite.setRotation(135); //face south west
else
   playSprite.setRotation(360); //face south
end if

So if I were to do something like:

Quote
if key = w && key = d   //north east
   if(playSprite.getRotation > 315)
   playsprite.rotate(100*dt);
   end if

I run into the probably obvious problem of if your facing north west and you want to now face north east your going to rotate on a clockwise angle to the other side while facing the opposite direction to what you wanted.

So im *guessing* I should call a function that finds the shortest distance between the degrees whether it be clockwise or anticlockwise and then apply that?






   

6
Silly me was madly looking into virtual functions and polymorphism and it was just an issue with having to pass pointers :P

No need to go beyond 'thank you'; a comment like this only leaves you looking like a fool.

Harsh! I was reading what I was recommend to read regarding the issue in previous posts... :P

ps: I dig the EverQuest avatar(pretty sure thats it, hard to tell at that size lol)...but no need to be rude!

7
Yay Third times the charm ;)

Silly me was madly looking into virtual functions and polymorphism and it was just an issue with having to pass pointers :P

I did hear yall say it thrice but I thought it was nitpicking rather than a solution(until that final comment where I got yelled at for good reason) my humble apology and thankyou!!

8
If anyone else cares to share some help knowing that I've looked over virtual docs including:

http://stackoverflow.com/questions/4586744/why-is-the-following-code-giving-me-an-error-about-an-abstract-class

and can provide some help or a link in the right direction I'd love to learn from you.

9
Please read a good C++ book, these are really basics. The error message clearly states what's wrong -- but you lack the background knowledge.

And Laurent already told you not to store copies in the container.

Well i've made, thermonuclear war, space invaders and almost finished Geometry Wars all in c++..

I've read books and im almost in my 2nd year at Uni in a programming degree so although I dont understand why my virtual function is abstract when it takes the same amount of arguments in inherited classes im not a total noob :P

I have read up on virtual class documentation online and am unable to find the problem considering the arguments it takes are all the same, if you have the knowledge to share some light on this I'd appreciate it...

edit: for instance http://stackoverflow.com/questions/4586744/why-is-the-following-code-giving-me-an-error-about-an-abstract-class does not apply here even though its a very similar problem.

10
Haha guessing Slicing = hacky memory but yea ill look into it :)

Also if you can point me in the right direction with this error thats now occuring:


1>  collision.cpp   //and a few other cpp files
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(869): error C2259: 'NPC' : cannot instantiate abstract class
1>          due to following members:
1>          'void NPC::move(float,sf::Sprite &,sf::RenderWindow &)' : is abstract
1>          c:\users\public\videos\geowars v2\geometry wars\dev\include\hayleigh\npcs.h(18) : see declaration of 'NPC::move'
1>          c:\users\public\videos\geowars v2\geometry wars\dev\include\hayleigh\npcmanager.h(18) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
1>          with
1>          [
1>              _Ty=NPC
1>          ]

I'd be most thankful!

aka what does abstract mean in this situation so I can fix it ;) -- for reference each base class like in the code above takes the same amount of arguments as the virtual so im stumped..


Edit: Perhaps it has to do with me creating the vector like this(as it seems to refer to this in the error)     
std::vector<NPC> npcVec;   //Vector of NPC's
for(int i = 0; i < maxNPC; i++)
   {
      npcVec.push_back(blueNPC());
      npcVec.push_back(purpleNPC());
      npcVec.push_back(greenNPC());
      npcVec.push_back(snakeNPC());
   }   

11
Awesome I knew I tuned out at Uni when we were learning virtual's but had a inkling that it had something to do with that, will get on it now!

Thanks again! :D

12
Ahh shame about not being able to repeat a subRect but ill give it it's own image file which should solve the issue unless my negative placement gets me into trouble.

Thanks for pointing me in the right direction anyhow.

13
Ok so the idea is to have a NPC class that has all the variables to work from, other NPC's will inherient from it. Inherited NPC's then get placed into a 'NPC' vector.

ie:

 class NPC
 {
public:
   sf::Sprite npcSprite;
   sf::Sprite& getNPC() {return npcSprite;};
   kf::Vector2f moveDir; //Movement Direction towards player
   sf::Vector2f startPos; //Starting position
   float moveSpeed; //Movement velocity
   bool alive; //Check if alive/dead
   float getRotation(sf::RenderWindow &win, sf::Sprite &npc, sf::Sprite &player);
};

class blueNPC : public NPC
{
public:
   blueNPC();
   void move(float deltaT, sf::Sprite &player, sf::RenderWindow &win);
private:
   sf::Texture blueNPC_tex;
   float scale; //Animate by resizing sprite on x axis
   bool goWide; //set sprite X scale outwards
};


BUT

My problem is how do I access blueNPC's move function within the vector as 'npc' doesnt have a move function ? ie:


npcVec[1].move(deltaT, player, win);   //as 'npc' does not have a move function

And my vector was setup like this:

for(int i = 0; i < maxNPC; i++)
   {
      npcVec.push_back(blueNPC());
      npcVec.push_back(purpleNPC());
      npcVec.push_back(greenNPC());
      npcVec.push_back(snakeNPC());
   }   

//Also im aware I could make a vector of each kind of NPC, I'd just rather not as it seems really un-intuitive.

14
Here's the code I've tried:

level_Fill.setRepeated(true);
level_Fill.setSmooth(true);
level_Fill.loadFromFile("data/GeoWarsSprites.png");
background.setTexture(&level_Fill);
background.setTextureRect(sf::IntRect(205, 13, 35, 35));
background.setSize(sf::Vector2f(-1100,1100));
background.setPosition(sf::Vector2f(1100,-200));

Im *guessing* the problem is with setSize, what is the proper way to create a square set to a size much bigger than the texture and have the texture repeated? I have followed tutorials no no avail :(

edit: background is defined as a RectangleShape & level_fill as a texture.

15
Aren't you supposed to use mapPixelToCoords? (see last paragraph of the view tutorial)

That was the exact problem, working perfectly now. I had an inkling that it would be something about calling the rotation in relative to the window and not the 'view' but your awesome for being able to spot it from what little I gave you and point out the code fix to boot!

Thanks heaps :)

Pages: [1] 2
anything