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

Pages: 1 [2]
16
Graphics / Re: Texture won't display when loaded from within a class?
« on: July 07, 2012, 07:48:02 pm »
Thanks guys, actually gameObj inherits from sf::sprite...it's just used for the collisions really (some code I borrowed from someone else!). I'm really confused lol  :o
I do normally have the if(!loadfromfile) exit_result type stuff to check for the result, but would that make a difference here or is that just for good practice?

gameObj is just like this, and it all compiles with no errors...just doesn't display the bomb though it's certainly there...

class gameObj : public sf::Sprite {
private:
  sf::FloatRect colliderResult;
  sf::IntRect relativeCollider;
  sf::FloatRect getCollider();

public:
  gameObj();

  bool isCollidingWith( gameObj object );
  void setRelativeCollider( sf::IntRect collider );
  void collide( gameObj collidingObject );
 
  bool operator< (const gameObj &other ) const {
    return getPosition().y < other.getPosition().y;
  }
 
  void update();
 
  int objectId;
  bool isDestructable;
 
};
 

17
Graphics / Re: Check to show sprite function
« on: July 07, 2012, 07:27:11 pm »
Clever stuff! As a noobie can I ask when you use blocks.at(i) instead of
Code: [Select]
blocks[i] which is what I was using with vectors?  :)

18
Graphics / Re: Texture won't display when loaded from within a class?
« on: July 07, 2012, 07:24:37 pm »
Thanks again for the reply, I cannot get it working quite, it's not white now it seems to just be invisible! I know it is there as after a few seconds it is set to destroy some blocks around it...which still works... I sort of need inheritance as it shares a gameObj class which handles collisions and stuff like that, my code looks like this now, but its just invisble. I did start reading c++ books and tutorials but I tend to learn better by just jumping in the deep end and playing around with things I find :) (and by asking for help when I get stuck  :P :) ) Its a bit if a mess right now as I play around with stuff but I just need to iron out a few things and then I can get it tidied up...so any idea why its invisible?

class Bomb : public gameObj {
private:
    sf::Sprite mySprite;
    sf::Texture myTexture;
public:
        Bomb(int texureRectX, int textureRectY, int textureRectSizeX, int textureRectSizeY, int collisionRectX, int collisionRectY, int collisionRectSizeX, int collisionRectSizeY, int posX, int posY )
  {
         myTexture.loadFromFile("images/bomb.png");
         mySprite.setTexture(myTexture);
         this->setTextureRect(sf::IntRect(0,0,32,32));
         this->setRelativeCollider(sf::IntRect(collisionRectX,collisionRectY,collisionRectSizeX,collisionRectSizeY));
         mySprite.setPosition(160, 160);
  };
  ~Bomb()
          {
                  cout<<"Destroyed!";
  };
};
 

in Main:

Bomb bomb(0,0,32,32,-1,-1,34,34,160,160); // -1 and 34 so collision rect overlaps/collides with blocks next to bomb

and later in main a "window.draw(bomb)";

19
Graphics / Re: Texture won't display when loaded from within a class?
« on: July 07, 2012, 06:55:34 pm »
Hi I see (i think), yes it is a spritem, and thank you very much for replying...so I have to make the bomb and then apply the texture in main I suppose? or make the texture in main then pass it to the class, I think it means that should work??
Thanks again!!

20
Graphics / Re: Check to show sprite function
« on: July 07, 2012, 06:49:49 pm »
Hey you should post the code for us fellow noobies :) Did you use the "window view" part of sfml as I was browsing over that last night and was going to suggest it?

21
Graphics / Texture won't display when loaded from within a class?
« on: July 07, 2012, 06:05:48 pm »
Hello all,  :)

Total noobie here but Im trying to create a simple game. I want to create a bomb object and everything is fine if I set the bomb up from within the main() loop, but if I try to make a bomb class then create a new bomb from this class, the texture no longer loads, I just get a white square instead. Can anyone help see why please?
Also can I pass a sf::IntRect() over the the class instead of having to pass over 4 individual ints? I tried changing the bomb class to get sf::IntRect textureRect and passing sf::IntRect(0,0,32,32) in the call but I just could not get it to work, so I am not sure if this is possible?

Main worry is the lack of texture anyway, like I say if I have the bomb created in main it shows the png bomb just fine, any suggestions most appreciated thanks.  :)

Code so far:

call top create new bomb instance in main()
Bomb bomb(0,0,32,32,0,0,64,64,160,160); // would rather pass some IntRects so neaten this up!
 


In bomb class (bomb.h):
public:
  Bomb(int texureRectX, int textureRectY, int textureRectSizeX, int textureRectSizeY, int collisionRectX, int collisionRectY, int collisionRectSizeX, int collisionRectSizeY, int posX, int posY )
  {
         this->setTextureRect(sf::IntRect(0,0,32,32));
         this->setRelativeCollider(sf::IntRect(0,0,64,64));
         this->setPosition(160, 160);
         sf::Texture bombChar;
         bombChar.loadFromFile("images/bomb.png");
         this->setTexture(bombChar);
  };
 

Pages: 1 [2]