agmcleod

  • 2022年4月29日
  • 注册于 2013年8月18日
  • I apologize. I did find a solution. I couldnt figure out how to flip the character properly though. I did have the animation render and such. Problem is I since deleted my code, so I don't recall what it was. I have a feeling it has to do with a call order on the update world transform or something like that.

  • 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); }
  • I wish the error message would tell me that 😃. Calling c_str() on the std::string values, and it's compiling. Thanks a bunch nate!

  • Here's the header file for my player class where I include SFML. I'm using the same include code you posted.

    //
    //  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:
        SkeletonBounds* bounds;
        SkeletonData* data;
        spine::SkeletonDrawable* drawable;
        Skeleton* skeleton;
    public:
        Player() {
            Atlas* atlas = Atlas_readAtlasFile(resourcePath() + "data/spineboy.atlas");
            SkeletonJson* json = SkeletonJson_create(atlas);
            SkeletonData *data = SkeletonJson_readSkeletonDataFile(json, resourcePath() + "data/spineboy.json");
            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); } ~Player() { SkeletonData_dispose(data); SkeletonBounds_dispose(bounds); Atlas_dispose(atlas); } void draw(sf::RenderWindow& window); void update(float delta); }; #endif /* defined(__sfmltest__Player__) */

    Line 25, that contains the code:

    Atlas* atlas = Atlas_readAtlasFile(resourcePath() + "data/spineboy.atlas");
    

    Throws the error: "No matching function for call to 'Atlas_readAtlasFile'"

  • Been messing around with C++ lately, and decided to start doing some basic stuff with spine. What i've done so far is created a lib directory in my project. I copied the header & source files from spine-c, as well as the two files from spine sfml, and put them all in lib/spine. I then added the lib directory to my Headers path in the project build settings. However, when i try to use functions like:

    Atlas_readAtlasFile

    it cannot resolve it. I tried including the Atlas.h directly, but no go. I don't have that much experience with C++ or C coding, so it would not surprise me if I am missing something simple. Anyone else try setting up spine with a project in xcode and can give me some tips?

  • Sorry to bump the thread, but did you figure this out? Having the same problem.

  • Ah I figured. Wouldn't be the first time I've used the cutting edge 🙂.

  • Maybe this is because I am just using the stable 0.9.8, but for example the line here:

    https://github.com/EsotericSoftware/spi ... .java#L450

    Throws an error because color#add doesn't except 4 floats, but another color object.

    Other examples would be with com.badlogic.gdx.utils.JsonValue. That class does not resolve. The JsonReader in the same package does for example, but that does not.

    Just trying to find out if I am missing something key here. Thanks!