Compiling fine as I said, but i'm not seeing anything. Draw is being called, i can see the callback output, but im just not seeing stuff on screen. Probably missing something silly, but i wouldn't mind another pair of eyes.
//
// Disclamer:
//
---
//
// This code will work only if you selected window, graphics and audio.
//
// Note that the "Run Script" build phase will copy the required frameworks
// or dylibs to your application bundle so you can execute it on any OS X
// computer.
//
// Your resource files (images, sounds, fonts, ...) are also copied to your
// application bundle. To get the path to these resource, use the helper
// method resourcePath() from ResourcePath.hpp
//
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
// Here is a small helper for you ! Have a look.
#include "ResourcePath.hpp"
#include <iostream>
#include "Player.h"
int main(int, char const**)
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
//sf::View view(sf::Vector2f(400, 300), sf::Vector2f(800, 600));
//window.setView(view);
// Set the Icon
window.setFramerateLimit(60);
sf::Image icon;
if (!icon.loadFromFile(resourcePath() + "icon.png")) {
return EXIT_FAILURE;
}
window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr());
Player player;
sf::Clock deltaClock;
// Start the game loop
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.pollEvent(event))
{
// Close window : exit
if (event.type == sf::Event::Closed) {
window.close();
}
// Espace pressed : exit
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
window.close();
}
}
float delta = deltaClock.getElapsedTime().asSeconds();
deltaClock.restart();
player.update(delta);
/* if(player.getPosition().x > 400) {
view.setCenter(player.getPosition().x, view.getCenter().y);
window.setView(view);
} */
// Clear screen
window.clear();
// Draw the sprite
player.draw(window);
// Update the window
window.display();
}
return EXIT_SUCCESS;
}
//
// Player.h
// sfmltest
//
// Created by Aaron McLeod on 2013-09-14.
// Copyright (c) 2013 Aaron McLeod. All rights reserved.
//
#ifndef __sfmltest__Player__
#define __sfmltest__Player__
#include <SFML/Graphics.hpp>
#include <iostream>
#include <spine/spine-sfml.h>
#include "ResourcePath.hpp"
class Player {
private:
Atlas* atlas;
SkeletonBounds* bounds;
SkeletonData* data;
spine::SkeletonDrawable* drawable;
Skeleton* skeleton;
public:
Player() {
atlas = Atlas_readAtlasFile((resourcePath() + "spineboy.atlas").c_str());
SkeletonJson* json = SkeletonJson_create(atlas);
SkeletonData *data = SkeletonJson_readSkeletonDataFile(json, (resourcePath() + "spineboy.json").c_str());
if(!data) {
std::cout << "Error: " << json->error;
exit(0);
}
SkeletonJson_dispose(json);
bounds = SkeletonBounds_create();
AnimationStateData* stateData = AnimationStateData_create(data);
AnimationStateData_setMixByName(stateData, "walk", "jump", 0.2f);
AnimationStateData_setMixByName(stateData, "jump", "walk", 0.4f);
drawable = new spine::SkeletonDrawable(data, stateData);
drawable->timeScale = 1;
skeleton = drawable->skeleton;
skeleton->flipX = false;
skeleton->flipY = false;
Skeleton_setToSetupPose(skeleton);
skeleton->root->x = 320;
skeleton->root->x = 420;
Skeleton_updateWorldTransform(skeleton);
drawable->state->listener = callback;
AnimationState_setAnimationByName(drawable->state, 0, "walk", true);
}
~Player() {
delete drawable;
SkeletonBounds_dispose(bounds);
SkeletonData_dispose(data);
Atlas_dispose(atlas);
}
static void callback(AnimationState* state, int trackIndex, EventType type, Event* event, int loopCount) {
TrackEntry* entry = AnimationState_getCurrent(state, trackIndex);
const char* animationName = (entry && entry->animation) ? entry->animation->name : 0;
switch (type) {
case ANIMATION_START:
printf("%d start: %s\n", trackIndex, animationName);
break;
case ANIMATION_END:
printf("%d end: %s\n", trackIndex, animationName);
break;
case ANIMATION_COMPLETE:
printf("%d complete: %s, %d\n", trackIndex, animationName, loopCount);
break;
case ANIMATION_EVENT:
printf("%d event: %s, %s: %d, %f, %s\n", trackIndex, animationName, event->data->name, event->intValue, event->floatValue,
event->stringValue);
break;
}
fflush(stdout);
}
void draw(sf::RenderWindow& window);
void update(float delta);
};
#endif /* defined(__sfmltest__Player__) */
//
// Player.cpp
// sfmltest
//
// Created by Aaron McLeod on 2013-09-14.
// Copyright (c) 2013 Aaron McLeod. All rights reserved.
//
#include "Player.h"
void Player::draw(sf::RenderWindow& window) {
window.draw(*drawable);
}
void Player::update(float delta) {
SkeletonBounds_update(bounds, skeleton, true);
drawable->update(delta);
}