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 cpp
// brickbreaker.cpp : Defines the entry point for the console application. #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
This post has been edited by B0rn2c0de: 29 April 2013 - 08:31 AM
Reason for edit:: fixed botched code tag