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

Pages: [1]
1
Graphics / ship sprite not displayed
« on: April 29, 2013, 06:36:39 pm »
hey guyz i started creating a space shooter type game and ran into an error
i currently have a ship class and a main file cpp .. the problem is that my ship wont draw on the screen plzz take a look at the code
here are the files

ship.h
#pragma once
#include<iostream>
#include<SFML\graphics.hpp>

class ship{
   private:
           sf::Texture st;
           sf::Sprite ss;
           int frame ;
   public:
           int xvel;
       int yvel;
           int life;
           ship(float x,float y);
           void move(sf::RenderWindow &name);
           };
ship::ship(float x ,float y)
{
        life=100;
        if(!st.loadFromFile("bul1.png")){std::cout<<"error";}
        ss.setTexture(st);
        ss.setPosition(x,y);
        frame = 2;
}
void ship::move(sf::RenderWindow &name)
{
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){ yvel-=0.8;}    
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){ yvel+=0.8;}
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
         { xvel-=0.8;
          --frame;}
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
         { xvel+=0.8;
          ++frame;}
        else if(!sf::Keyboard::isKeyPressed(sf::Keyboard::Left)&& !sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){frame=2;}

        if(frame>4){frame=4;}
         else if(frame<0){frame=0;}

        if(frame==0){ss.setTextureRect(sf::IntRect(0,0,22,43));}
        else if(frame==1){std::cout<<"f2";
                ss.setTextureRect(sf::IntRect(42,0,33,43));}
        else if(frame==2){ss.setTextureRect(sf::IntRect(86,0,43,43));}
        else if(frame==3){ss.setTextureRect(sf::IntRect(140,0,33,43));}
        else if(frame==4){ss.setTextureRect(sf::IntRect(194,0,22,43));}
        ss.move(xvel,yvel);
        name.draw(ss);
        std::cout<<"draw";
}
 
 

and main file

#include "stdafx.h"
#include <SFML\graphics.hpp>
#include "ship.h"


int main()
{sf::RenderWindow app(sf::VideoMode(800,600),"test");
sf::Texture bt;
bt.loadFromFile("spw.jpg");
sf::Sprite background(bt);
ship player(400,300);
while(app.isOpen())
{       app.clear();
    app.draw(background);
        sf::Event x;
        while(app.pollEvent(x))
                {if(x.type==sf::Event::Closed){app.close();}}
        player.move(app);
        app.display();
}
        return 0;
}
 

please help guyz

2
Graphics / Re: sprites are white rectangles
« on: April 25, 2013, 02:41:35 pm »
You also might want to look into sf::Mouse::getPosition(window);
Thanks i will definitely try it   :)
To get the time i thought about starting a timer as soon as the collision occurs , get the mouse position
After 5 mili sec or so get the mouse position again , get the distance and divide by the elapsed time .. But wont it pause my game for the elapsed time ??
Or is there a better way of doing so ??

3
Graphics / Re: sprites are white rectangles
« on: April 25, 2013, 01:51:05 pm »
thanx guys it worked :) .. i have 1 more question .. i was making a air hockey type game in which the puck was controlled by the mouse somewhat like this
if(event.type==sf::event::mousemoved)
{puck.setpositon(mousex,mousey})
is there some way to get the velocity of the puck ??

4
Graphics / sprites are white rectangles
« on: April 24, 2013, 08:50:54 pm »
okay .. iknow that this question has been asked many times and i have even checked out the topics but i just cant seem to get my head around this problem
#include <SFML\graphics.hpp>
#include "stdafx.h"

int main()
{
        sf::Texture img;
        if(!img.loadFromFile("bg.png"))
        {std::cout<<"load error";}
        sf::Sprite bg(img,sf::Rect<int>(10,12,30,23));
        sf::RenderWindow app(sf::VideoMode(640,480),"test");
        while(app.isOpen())
        { sf::Event x;
        while(app.pollEvent(x))
        {if(x.type==sf::Event::Closed){app.close();}}
        app.clear(sf::Color(0,0,0,0));
        app.draw(bg);
        app.display();
        }
return 0;
}

my texture could not have gone out of scope as there is only a main function and even the image is getting loaded as it does not show any error
plzz help

Pages: [1]