i've an issue , im writing a menu to the maze game using SFML lib but something went wrong i wrote a code to redner a window and make a menu code. whem im clicking "Local windows debbuger" in vs2017 proggam opens a white window which shoud not suposed to happen. im pretty new at programing and i dont see all mistakes i made in this code but for me it's written right.
#pragma once
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;
using namespace sf;
#define Max_main_menu 4
class Menu
{
public:
Menu(float width, float height);
void draw(RenderWindow& window);
void MoveUp();
void MoveDown();
int MenuPressed()
{
return MenuSelected;
}
~Menu();
private:
int MenuSelected;
Text menu[Max_main_menu];
};
menu.h
_____________________________
#include "Menu.h"
Menu::Menu(float widht, float height)
{
//Graj
menu[0].setFillColor(Color::White);
menu[0].setString("Graj");
menu[0].setCharacterSize(70);
menu[0].setPosition(600, 300);
menu[1].setFillColor(Color::White);
menu[1].setString("Opcje");
menu[1].setCharacterSize(60);
menu[1].setPosition(500, 300);
menu[2].setFillColor(Color::White);
menu[2].setString("Autorzy");
menu[2].setCharacterSize(60);
menu[2].setPosition(400, 300);
menu[3].setFillColor(Color::White);
menu[3].setString("Najlepszy Csas");
menu[3].setCharacterSize(60);
menu[3].setPosition(300, 300);
MenuSelected = -1;
}
Menu::~Menu()
{
}
void Menu::draw(RenderWindow& window) {
for (int i = 0; i < Max_main_menu; i++) {
window.draw(menu[i]);
}
}
void Menu::MoveUp() {
if (MenuSelected - 1 >= 0) {
menu[MenuSelected].setFillColor(Color::White);
MenuSelected--;
if (MenuSelected == -1) {
MenuSelected = 2;
}
menu[MenuSelected].setFillColor(Color::Blue);
}
}
void Menu::MoveDown()
{
if (MenuSelected + 1 <= Max_main_menu)
{
menu[MenuSelected].setFillColor(Color::White);
MenuSelected++;
if (MenuSelected == 4)
{
MenuSelected = 0;
}
menu[MenuSelected].setFillColor(Color::Blue);
}
}
menu.cpp
______________________________________________________
#include <SFML/Graphics.hpp>
#include "D:\Proejkt\Menu.h"
int main()
{
RenderWindow MENU(VideoMode(1280, 720), "Labirynt", Style::Default);
Menu menu(MENU.getSize().x, MENU.getSize().y);
while (MENU.isOpen())
{
Event event;
while (MENU.pollEvent(event))
{
if (event.type == Event::Closed)
{
MENU.close();
}
if (event.type == Event::KeyReleased)
{
if (event.key.code == Keyboard::Up)
{
menu.MoveUp();
break;
}
if (event.key.code == Keyboard::Down)
{
menu.MoveDown();
break;
}
if (event.key.code == Keyboard::Return)
{
RenderWindow Graj(VideoMode(1280, 720), "Labirynt");
RenderWindow Opcje(VideoMode(1280, 720), "Opcje");
RenderWindow Autorzy(VideoMode(1280, 720), "Autorzy");
RenderWindow NajlepszyCzas(VideoMode(1280, 720), "Najlepszy Czas");
int x = menu.MenuPressed();
if (x == 0)
{
while (Graj.isOpen())
{
Event aevent;
while (Graj.pollEvent(aevent))
{
if (aevent.type == Event::Closed)
{
Graj.close();
}
if (aevent.type == Event::KeyPressed)
{
if (aevent.key.code == Keyboard::Escape)
{
Graj.close();
}
}
}
}
Opcje.close();
Autorzy.close();
NajlepszyCzas.close();
Graj.clear();
Graj.display();
}
if (x == 1)
{
while (Opcje.isOpen())
{
Event aevent;
while (Opcje.pollEvent(aevent))
{
if (aevent.type == Event::Closed)
{
Opcje.close();
}
if (aevent.type == Event::KeyPressed)
{
if (aevent.key.code == Keyboard::Escape)
{
Opcje.close();
}
}
}
}
Graj.close();
Autorzy.close();
NajlepszyCzas.close();
Opcje.clear();
Opcje.display();
}
}
}
}
}
MENU.clear();
menu.draw(MENU);
MENU.display();
}
project.cpp
Your Main.clear(), Main.draw() and Main.display() is not in a while loop. Pls put them in a while loop.
Related
I'm Getting a Segmentation fault here
if((cur->block)!=(cur->next)->block)
I Tried to fix Some on my own but didn't got it correct.
this Program is used to implement Control Flow Analysis it was having some more Segmentation faults which were identified and fixed ,but now. I don't have any alternative to try and edit this code.
struct Listnode
{
char data[50];
int leader,block,u_goto,c_goto;
struct Listnode *next;
char label[10],target[10];
}*temp,*cur,*first=NULL,*last=NULL,*cur1;
FILE *fpr;
void createnode(char code[50])
{
temp=(struct Listnode*) malloc(sizeof(struct Listnode));
strcpy(temp->data,code);
strcpy(temp->label,"\0");
strcpy(temp->target,"\0");
temp->leader=0;
temp->block=0;
temp->u_goto=0;
temp->c_goto=0;
temp->next=NULL;
if(first==NULL)
{
first=temp;
last=temp;
}
else
{
last->next=temp;
last=temp;
}
}
void main()
{
char codeline[50];
char c,dup[50],target[10];
char *substring,*token;
int i=0,j=0,block,block1;
fpr= fopen("P10-CFA.txt","r");
while((c=getc(fpr))!=EOF)
{
if(c!='\n')
{
codeline[i]=c;
i++;
}
else
{
codeline[i]='\0';
createnode(codeline);
i=0;
}
}
//create last node
codeline[i]='\0';
createnode(codeline);
fclose(fpr);
// find out leaders,conditional stmts
cur=first;
cur->leader=1;
while(cur!=NULL)
{
substring=strstr((cur->data),"if");
if(substring==NULL)
{
if((strstr((cur->data),"goto"))!=NULL)
{
cur->u_goto=1;
(cur->next)->leader=1;
}
}
else
{
cur->c_goto=1;
(cur->next)->leader=1;
}
substring=strstr((cur->data),":");
if(substring!=NULL)
{
cur->leader=1;
}
substring=strstr((cur->data),"call");
if(substring!=NULL)
{
cur->leader=1;
}
if(strstr(cur->data,"return")!=NULL)
{
cur->leader=1;
(cur->next)->leader=1;
}
cur=cur->next;
//to find labels and targets
cur=first;
while(cur!=NULL)
{
if((cur->u_goto==1)||(cur->c_goto==1))
{
substring=strstr(cur->data,":");
if(substring!=NULL)
{
token=strstr(substring,"L" );
if(token!=NULL)
strcpy(cur->target,token);
else
{
substring=strstr(cur->data,"L");
if(substring!=NULL)
strcpy(cur->target,substring);
}
}
if(strstr(cur->data,":")!=NULL)
{
strcpy(dup,cur->data);
token=strtok(dup,":");
//printf("\ntoken:%s",token);
if(token!=NULL)
strcpy(cur->label,token);
}
cur=cur->next;
//to identify blocks
cur=first;
while(cur!= NULL)
{
cur=cur->next;
if((cur->leader)==1)
{
j++;
cur->block=j;
}
else
cur->block=j;
}
printf("\n\n.....Basic Blocks \n");
cur=first;
j=0;
printf("\nBlock %d:",j);
while(cur!=NULL)
{
if ((cur->block)==j)
{
printf("%s",cur->data);
printf("\n\t");
cur=cur->next;
}
else
j++;
printf("\nBlock %d:",j);
}
}
//to output the control flow from each block
printf ("\t\t.......Control Flow.........\n\n");
cur=first;
i=0;
while(cur!=NULL)
{
if((cur->block)!=(cur->next)->block)
{
block=cur->block;
if(cur->u_goto==1)
{
strcpy(target,cur->target);
cur1=first;
while(cur1!=NULL)
{
if(strcmp(cur1->label,target)==0)
{
block1=cur1->block;
printf("\t\tBlock%d---->Block%dln",block,block1);
}
cur1=cur1->next;
}
}
else if(cur->c_goto==1)
{
strcpy(target,cur->target);
cur1=first;
while(cur1!=NULL)
{
if(strcmp(cur1->label,target)==0)
{
block1=cur1->block;
printf("lt\1Block%d---TRUE--->Block%d---FALSE--->Block%d\n",block,block1,(block+1));
}
cur1=cur1->next;
}
}
else if(strstr(cur->data,"return")==NULL)
{
printf("\t\tBlock%d--->Block%d\n",block,(block+1));
}
else
printf("lt\tBlock%d--->NULL\n",block);
}
cur=cur->next;
}
cur=last;
block= cur->block;
printf("\t\tBlock%d--->NULL",block);
}
}
}
I'm very new to coding and was wondering how I could make this image move to the right. I added all of my code so that it would be a bit more understandable for what's going on. The moveRight command will not actually move the png to the right which is why I need help fixing and understanding why it won't work. If someone can please help me it would be greatly appreciated.
PImage background, backgroundGameState1, headbasketballbackground, player1, player2;
boolean moveRight, moveLeft;
int canvasSizeX= 1000;
int canvasSizeY = 600;
int mainBackgroundX = 1000;
int mainBackgroundY = 600;
int gameState1 = 1;
int player1X = 100;
int player1Y = 200;
int player2X = 100;
int player2Y = 200;
int backgroundGameState1X= 1000;
int backgroundGameState1Y=600;
int time;
int player1MovmentX = 100;
int player2MovmentX = 700;
void setup() {
//size of canvas
size(1000, 600);
//Loaded images and called them, also made sure to resize them in order to match the canvas size or to make program more asthetically pleasing
background = loadImage("headbasketballbackground.png");
background.resize(mainBackgroundX, mainBackgroundY);
backgroundGameState1 = loadImage("backgroundgamestate1.png");
backgroundGameState1.resize(backgroundGameState1X, backgroundGameState1Y);
player1 = loadImage("steph.png");
player1.resize(player1X, player1Y);
player2 = loadImage("paul.png");
player2.resize(player2X, player2Y);
time=millis();
}
void draw() {
if (gameState1 == 1) {
background(backgroundGameState1);
if (millis() > time + 1000) {
text("Click On Space To Enter The Game!", 100, 100);
textSize(50);
// delay(3000);
}
drawGameState1();
}
if (gameState1 == 2) {
background(background);
image(player1, player1MovmentX, 300);
image(player2, player2MovmentX, 300);
}
// if (gameState2 == 3) {
// text("Congrats you won!");
//}
}
void drawGameState1() {
}
void drawGameState2() {
drawPlayer1Movment();
}
void drawPlayer1Movment(){
if(moveRight){
player1MovmentX += 25;
}
}
void drawGameState3() {
}
void keyPressed() {
if (gameState1 == 1) {
if (keyCode == 32) {
gameState1 = 2;
}
}
else if(gameState1 == 2){
if(keyCode == RIGHT){
moveRight = true;
}
}
}
void keyReleased(){
if(keyCode == RIGHT){
moveRight = false;
}
}
I don't think you ever called drawPlayer1Movement(). Add it to keyPressed() and player1 should move to the right when you hit the right arrow.
void keyPressed() {
if (gameState1 == 1) {
if (keyCode == 32) {
gameState1 = 2;
}
} else if (gameState1 == 2) {
if (keyCode == RIGHT) {
moveRight = true;
drawPlayer1Movment();
}
}
}
I am going to deploy the QT creator project. But I discovered that some functions of deployment .exe are missing. However, it originally works inside the QT creator. I have no idea about how to solve the current problem, like using what tools to help. The missing function is that the program doesn't show the thumbnails about the video files, where I have assigned the relative images to that.
filemodel.h
#ifndef FILEMODEL_H
#define FILEMODEL_H
#include <QAbstractListModel>
#include <QDirIterator>
#include <QUrl>
#include <QMetaType>
#include <QFuture>
#include <QtConcurrent/QtConcurrent>
#include <iostream>
#include <QImage>
#include <iostream>
#include <fstream>
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
struct File
{
Q_GADGET
Q_PROPERTY(QString name MEMBER name)
Q_PROPERTY(QUrl url MEMBER url)
Q_PROPERTY(QImage iconImg MEMBER iconImg)
Q_PROPERTY(QUrl urlicon MEMBER urlicon)
public:
QString name;
QUrl url;
QImage iconImg;
QUrl urlicon;
File(const QString& name=""){
//cout<<name.toStdString();
this->name = QFileInfo(name).fileName();
this->url = QUrl::fromLocalFile(name);
int i = name.toStdString().find(".mp4");
if(i<0)
{
this->urlicon = QUrl::fromLocalFile(name);
}
else{
string temp = QFileInfo(name).fileName().toStdString();
int j = temp.find(".mp4");
//string str = "C:\\Video\\"+ temp.replace(j,4,".jpg");
string str = "C:\\Video\\"+ temp.replace(j,4,".jpg");
this->urlicon = QUrl::fromLocalFile(QString::fromStdString(str));
}
}
};
Q_DECLARE_METATYPE(File)
class FileModel : public QAbstractListModel
{
enum dashBoardRoles {
NameRole=Qt::UserRole+1,
URLRole,
ICONRole,
URLICONRole
};
Q_OBJECT
Q_PROPERTY(QString folder READ folder WRITE setFolder NOTIFY folderChanged)
Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters NOTIFY nameFiltersChanged)
public:
FileModel(QObject *parent=Q_NULLPTR):QAbstractListModel(parent){
}
Q_INVOKABLE QVariant get(int index){
return QVariant::fromValue(m_all_dirs[index]);
}
int rowCount(const QModelIndex &parent=QModelIndex()) const{
Q_UNUSED(parent)
return m_all_dirs.count();
}
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const{
if(index.row()<0 && index.row()>= rowCount())
return QVariant();
File file = m_all_dirs[index.row()];
if(role == NameRole)
return file.name;
else if(role == URLRole)
return file.url;
else if(role == ICONRole)
return file.iconImg;
else if(role == URLICONRole)
return file.urlicon;
return QVariant();
}
QHash<int, QByteArray> roleNames() const {
QHash <int,QByteArray> roles;
roles [NameRole]="fileName";
roles [URLRole]="url";
roles [ICONRole]="icon";
roles [URLICONRole]="urlicon";
return roles;
}
QString folder() const{
return mFolder;
}
void setFolder(const QString &folder)
{
if(mFolder == folder)
return;
mFolder = folder;
emit folderChanged();
findFiles();
}
QStringList nameFilters() const{
return mNameFilters;
}
void setNameFilters(const QStringList &nameFilters){
if(mNameFilters == nameFilters)
return;
mNameFilters = nameFilters;
emit nameFiltersChanged();
findFiles();
}
signals:
void folderChanged();
void nameFiltersChanged();
private:
void findFiles(){
beginResetModel();
m_all_dirs.clear();
if(QDir(mFolder).exists()){
QFuture<QStringList> future = QtConcurrent::run([=]() {
QStringList files;
QDirIterator it(mFolder, mNameFilters, QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()){
files<<it.next();
}
ofstream myfile;
myfile.open (mFolder.toStdString()+"\\example.xml");
myfile <<"<files>"<<"\n";
for (int i = 0; i < files.size(); ++i)
myfile << "<"+ std::to_string(i) + ">"<< files.at(i).toStdString()<< "</"+ std::to_string(i) + ">" <<"\n";
//
myfile <<"</files>"<<"\n";
myfile.close();
for (int i = 0; i < files.size(); ++i){
int j = files.at(i).toStdString().find(".mp4");
if(j>0)
{
VideoCapture cap(files.at(i).toStdString());
Mat frame;
cap >> frame;
string str = QFileInfo(files.at(i)).fileName().toStdString();
int k = str.find(".mp4");
str = "C:\\Video\\"+ str.replace(k,4,".jpg");
imwrite(str,frame);
}
}
return files;
});
QStringList fullNames = future.result();
for(const QString& fullName: fullNames){
File file{fullName};
m_all_dirs << file;
}
//return 0;
}
endResetModel();
}
QString mFolder;
QList<File> m_all_dirs;
QStringList mNameFilters;
};
#endif // FILEMODEL_H
main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "filemodel.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
qmlRegisterType<FileModel>("com.contentplayermod.filemodel", 1,0, "FileModel");
QQmlApplicationEngine engine;
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
main.qml
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtMultimedia 5.8
import QtQuick.Layouts 1.3
import com.contentplayermod.filemodel 1.0
import QtQuick.Window 2.2
ApplicationWindow {
id:main_win
visible: true
width: 640
height: 480
title: qsTr("Tabs")
property int idx: 0
property bool isActive: true
Component.onCompleted: {
playTimer.start()
subWindow.show();
subWindow.requestActivate();
main_win.hide();
playMusic(grid_main.currentIndex)
}
GridView {
id:grid_main
anchors.fill: parent
cellWidth: 100; cellHeight: 100
focus: true
currentIndex: 0
model: FileModel{
id: myModel
folder: "c:\\test2"//"/mnt/sdcard/app_pictureFrameImage"//
nameFilters: ["*.jpg" ,"*.mp4"] //"*.mp4",
}
highlight: Rectangle { width: 80; height: 80; color: "lightsteelblue" }
delegate: Item {
width: 100; height: 100
Image {
id: myIcon
width: 30
height: 30
y: 20; anchors.horizontalCenter: parent.horizontalCenter
source: urlicon
}
Text {
anchors { top: myIcon.bottom; horizontalCenter: parent.horizontalCenter }
text: fileName
}
MouseArea {
anchors.fill: parent
onClicked: {
parent.GridView.view.currentIndex = index
}
}
}
Keys.onReturnPressed:{
playTimer.start()
subWindow.show();
subWindow.requestActivate();
playMusic(grid_main.currentIndex)
//subWindow.forceActiveFocus();
//event.accepted = true;
grid_main.focus = false;
}
/*
Keys.onPressed: {
if (event.key == 16777220) {//enter
playTimer.start()
subWindow.show();
subWindow.requestActivate();
playMusic(grid_main.currentIndex)
//subWindow.forceActiveFocus();
event.accepted = true;
grid_main.focus = false;
//main_win.hide();
}
}*/
}
Window {
id: subWindow
visible: true
width: 640
height: 480
MediaPlayer {
id: player
}
VideoOutput {
id: video
anchors.fill: parent
source: player
}
Item {
focus: true
Keys.onReturnPressed:{
subWindow.close()
grid_main.forceActiveFocus();
main_win.show();
}
}
}
function playMusic(index){
idx = index
//player.stop()
player.source = myModel.get(index).url
player.play()
}
Timer {
id: playTimer
interval: 2000
repeat: true
running: true
onTriggered: {
var source_name = player.source;
if(source_name.toString().indexOf(".jpg")>0 || source_name.toString().indexOf(".bmp")>0 || source_name.toString().indexOf(".png")>0){ //processing .jpg
if (idx + 1 < grid_main.count){
playMusic(idx + 1);
}else{
idx = 0;
playMusic(idx);
}
}
else if(source_name.toString().indexOf(".mp4")>0){ //processing .mp4
if (player.status == MediaPlayer.EndOfMedia){
if (idx + 1 < grid_main.count){
playMusic(idx + 1);
}else{
idx = 0;
playMusic(idx);
}
}
}
}
}
}
Why does the following code crash under Windows 10? It gets stuck in yield() in the setjmp() call. What rules did I violate? I think I never return from functions where setjmp() is called. The code works perfectly under linux/amd64.
class coroutine
{
jmp_buf env_in_;
jmp_buf env_out_;
::std::function<void()> f_;
bool running_;
bool terminated_;
::std::unique_ptr<char[]> stack_;
char* const stack_top_;
public:
explicit coroutine(::std::size_t const N = 128 * 1024) :
running_{false},
terminated_{true},
stack_(new char[N]),
stack_top_(stack_.get() + N)
{
}
template <typename F>
explicit coroutine(::std::size_t const N, F&& f) :
coroutine(N)
{
assign(::std::forward<F>(f));
}
auto terminated() const noexcept
{
return terminated_;
}
template <typename F>
void assign(F&& f)
{
running_ = terminated_ = false;
f_ = [this, f = ::std::forward<F>(f)]() mutable
{
// stack switch
#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64)
asm volatile(
"movq %%rsp, %0"
:
: "rm" (stack_top_)
: "rsp"
);
#elif defined(i386) || defined(__i386) || defined(__i386__)
asm volatile(
"movl %%esp, %0"
:
: "rm" (stack_top_)
: "esp"
);
#else
#error "can't switch stack frame"
#endif
f(*this);
running_ = false;
terminated_ = true;
yield();
};
}
void yield() noexcept
{
if (setjmp(env_out_))
{
return;
}
else
{
longjmp(env_in_, 1);
}
}
void resume() noexcept
{
if (setjmp(env_in_))
{
return;
}
else if (running_)
{
longjmp(env_out_, 1);
}
else
{
running_ = true;
f_();
}
}
};
Here is the test program:
#include <iostream>
#include "coroutine.hpp"
struct A
{
~A()
{
::std::cout << "destroyed" << ::std::endl;
}
};
int main()
{
coroutine c(1024 * 1024);
c.assign([](coroutine& c)
{
A a;
for (int i{}; i != 3; ++i)
{
::std::cout << i << ::std::endl;
c.yield();
}
}
);
while (!c.terminated())
{
c.resume();
}
return 0;
}
I wrote two classes; Animation, and Actor. For some reason, the sprite image doesn't change. It stays the first frame the entire time. The code is fine I have no issues compiling, my logic is just wrong somewhere and it isn't acting how I expected it to.
Animation class declaration:
class Animation
{
public:
Animation(std::string path, int frames);
~Animation();
void nextFrame();
void gotoStart();
bool loadFrames();
sf::Texture& getActiveFrame();
private:
int frameCount;
std::string pathToAnimation;
int currentFrame;
sf::Texture frame[];
};
Animation class implementation:
Animation::Animation(std::string path, int frames)
{
pathToAnimation = path;
frameCount = frames;
}
Animation::~Animation()
{
// destructor
}
void Animation::nextFrame()
{
if(currentFrame < frameCount)
{
currentFrame = 1;
}
else
currentFrame += 1;
}
void Animation::gotoStart()
{
currentFrame = 1;
}
bool Animation::loadFrames()
{
for(int i = 01; i < frameCount; i++)
{
if(!frame[i].loadFromFile(pathToAnimation + std::to_string(i) + ".jpg")) return false;
}
return true;
}
sf::Texture& Animation::getActiveFrame()
{
return frame[currentFrame];
}
Actor class declaration:
class Actor
{
public:
Actor();
~Actor();
void setActiveAnimation(std::shared_ptr<MaJR::Animation> anim);
void draw(sf::RenderWindow& win);
private:
sf::Sprite sprite;
std::shared_ptr<MaJR::Animation> activeAnimation;
};
Actor class implementation:
Actor::Actor()
{
// constructor
}
Actor::~Actor()
{
// destructor
}
void Actor::setActiveAnimation(std::shared_ptr<MaJR::Animation> anim)
{
activeAnimation = anim;
activeAnimation->gotoStart();
}
void Actor::draw(sf::RenderWindow& win)
{
sprite.setTexture(activeAnimation->getActiveFrame());
win.draw(sprite);
activeAnimation->nextFrame();
}
Here's the code to test it:
int main()
{
sf::RenderWindow Window(sf::VideoMode(800, 600), "MaJR Game Engine Sandbox");
std::shared_ptr<MaJR::Animation> DroneStandNorth = std::make_shared<MaJR::Animation>("./Assets/Sprites/Zerg/Units/Drone/Stand/North/", 61);
if(!DroneStandNorth->loadFrames()) return EXIT_FAILURE;
MaJR::Actor Drone;
Drone.setActiveAnimation(DroneStandNorth);
while(Window.isOpen())
{
sf::Event Event;
while(Window.pollEvent(Event))
{
if(Event.type == sf::Event::Closed)
Window.close();
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
Window.close();
Window.clear();
Drone.draw(Window);
Window.display();
}
return 0;
}
I'm at a complete loss as to what's wrong here. If you want to compile everything yourself, here's the original files: http://www.filedropper.com/animationtesttar be sure to use -std=c++0x or whatever you have to do to use C++11 with your compiler.
In your animation implementation, you have:
void Animation::nextFrame()
{
if(currentFrame < frameCount)
{
currentFrame = 1;
}
else
currentFrame += 1;
}
Since the currentFrame starts at 1, it will always be less than frameCount, so it will always be set to 1. Change to:
void Animation::nextFrame()
{
if(currentFrame >= frameCount)
{
currentFrame = 1;
}
else
currentFrame += 1;
}
This way, when the currentFrame equals frameCount (in your test case 61), it will be reset. Since nextFrame() gets called after the Actor's Draw(), the last frame will be drawn and then the currentFrame will be reset back to 1.