mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
[sfml] Added testbed
# Conflicts: # CMakeLists.txt # spine-sfml/cpp/CMakeLists.txt
This commit is contained in:
parent
38ae6f886c
commit
6e4c9517bc
@ -62,7 +62,11 @@ install(FILES ${INCLUDES} DESTINATION dist/include)
|
|||||||
|
|
||||||
# Define spine-sfml example executable
|
# Define spine-sfml example executable
|
||||||
add_executable(spine-sfml-cpp-example example/main.cpp)
|
add_executable(spine-sfml-cpp-example example/main.cpp)
|
||||||
add_executable(spine-sfml-cpp-test example/test.cpp)
|
target_link_libraries(spine-sfml-cpp-example spine-cpp spine-sfml-cpp)
|
||||||
|
|
||||||
|
# Define spine-sfml testbed executable
|
||||||
|
add_executable(spine-sfml-cpp-testbed example/testbed.cpp)
|
||||||
|
target_link_libraries(spine-sfml-cpp-testbed spine-cpp spine-sfml-cpp)
|
||||||
|
|
||||||
# Link in SFML libraries and OS dependencies like OpenGL
|
# Link in SFML libraries and OS dependencies like OpenGL
|
||||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
@ -71,10 +75,10 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|||||||
find_library(SFML_WINDOW sfml-window PATHS ${SFML_DIR}/Frameworks)
|
find_library(SFML_WINDOW sfml-window PATHS ${SFML_DIR}/Frameworks)
|
||||||
find_library(SFML_GRAPHICS sfml-graphics PATHS ${SFML_DIR}/Frameworks)
|
find_library(SFML_GRAPHICS sfml-graphics PATHS ${SFML_DIR}/Frameworks)
|
||||||
target_link_libraries(spine-sfml-cpp-example ${SFML} ${SFML_SYSTEM} ${SFML_WINDOW} ${SFML_GRAPHICS})
|
target_link_libraries(spine-sfml-cpp-example ${SFML} ${SFML_SYSTEM} ${SFML_WINDOW} ${SFML_GRAPHICS})
|
||||||
target_link_libraries(spine-sfml-cpp-test ${SFML} ${SFML_SYSTEM} ${SFML_WINDOW} ${SFML_GRAPHICS})
|
target_link_libraries(spine-sfml-cpp-testbed ${SFML} ${SFML_SYSTEM} ${SFML_WINDOW} ${SFML_GRAPHICS})
|
||||||
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||||
target_link_libraries(spine-sfml-cpp-example sfml-graphics sfml-window sfml-system)
|
target_link_libraries(spine-sfml-cpp-example sfml-graphics sfml-window sfml-system)
|
||||||
target_link_libraries(spine-sfml-cpp-test sfml-graphics sfml-window sfml-system)
|
target_link_libraries(spine-sfml-cpp-testbed sfml-graphics sfml-window sfml-system)
|
||||||
else()
|
else()
|
||||||
set(SFML_LIBS ${SFML_DIR}/lib)
|
set(SFML_LIBS ${SFML_DIR}/lib)
|
||||||
target_link_libraries(spine-sfml-cpp-example ${SFML_LIBS}/sfml-main-d.lib)
|
target_link_libraries(spine-sfml-cpp-example ${SFML_LIBS}/sfml-main-d.lib)
|
||||||
@ -86,28 +90,23 @@ else()
|
|||||||
target_link_libraries(spine-sfml-cpp-example opengl32)
|
target_link_libraries(spine-sfml-cpp-example opengl32)
|
||||||
target_link_libraries(spine-sfml-cpp-example gdi32)
|
target_link_libraries(spine-sfml-cpp-example gdi32)
|
||||||
target_link_libraries(spine-sfml-cpp-example winmm)
|
target_link_libraries(spine-sfml-cpp-example winmm)
|
||||||
target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/sfml-main-d.lib)
|
target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/sfml-main-d.lib)
|
||||||
target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/sfml-graphics-s-d.lib)
|
target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/sfml-graphics-s-d.lib)
|
||||||
target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/sfml-window-s-d.lib)
|
target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/sfml-window-s-d.lib)
|
||||||
target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/sfml-system-s-d.lib)
|
target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/sfml-system-s-d.lib)
|
||||||
target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/freetype.lib)
|
target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/freetype.lib)
|
||||||
target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/jpeg.lib)
|
target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/jpeg.lib)
|
||||||
target_link_libraries(spine-sfml-cpp-test opengl32)
|
target_link_libraries(spine-sfml-cpp-testbed opengl32)
|
||||||
target_link_libraries(spine-sfml-cpp-test gdi32)
|
target_link_libraries(spine-sfml-cpp-testbed gdi32)
|
||||||
target_link_libraries(spine-sfml-cpp-test winmm)
|
target_link_libraries(spine-sfml-cpp-testbed winmm)
|
||||||
add_definitions(-DSFML_STATIC)
|
add_definitions(-DSFML_STATIC)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# copy data to build directory
|
# copy data to build directory
|
||||||
add_custom_command(TARGET spine-sfml-cpp-example PRE_BUILD
|
add_custom_command(TARGET spine-sfml-cpp-example
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/data $<TARGET_FILE_DIR:spine-sfml-cpp-example>/data)
|
|
||||||
add_custom_command(TARGET spine-sfml-cpp-test PRE_BUILD
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
${CMAKE_CURRENT_LIST_DIR}/data $<TARGET_FILE_DIR:spine-sfml-cpp-example>/data)
|
${CMAKE_CURRENT_LIST_DIR}/data $<TARGET_FILE_DIR:spine-sfml-cpp-example>/data)
|
||||||
|
|
||||||
target_link_libraries(spine-sfml-cpp-example spine-cpp)
|
add_custom_command(TARGET spine-sfml-cpp-testbed
|
||||||
target_link_libraries(spine-sfml-cpp-example spine-sfml-cpp)
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/data $<TARGET_FILE_DIR:spine-sfml-cpp-example>/data)
|
||||||
target_link_libraries(spine-sfml-cpp-test spine-cpp)
|
|
||||||
target_link_libraries(spine-sfml-cpp-test spine-sfml-cpp)
|
|
||||||
|
|||||||
75
spine-sfml/cpp/example/testbed.cpp
Normal file
75
spine-sfml/cpp/example/testbed.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Spine Runtimes License Agreement
|
||||||
|
* Last updated January 1, 2020. Replaces all prior versions.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2020, Esoteric Software LLC
|
||||||
|
*
|
||||||
|
* Integration of the Spine Runtimes into software or otherwise creating
|
||||||
|
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||||
|
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||||
|
* http://esotericsoftware.com/spine-editor-license
|
||||||
|
*
|
||||||
|
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||||
|
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||||
|
* "Products"), provided that each user of the Products must obtain their own
|
||||||
|
* Spine Editor license and redistribution of the Products in any form must
|
||||||
|
* include this license and copyright notice.
|
||||||
|
*
|
||||||
|
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
||||||
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
||||||
|
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
#include <spine/Log.h>
|
||||||
|
#include <spine/spine-sfml.h>
|
||||||
|
|
||||||
|
using namespace spine;
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
String atlasFile("data/spineboy-pma.atlas");
|
||||||
|
String skeletonFile("data/spineboy-pro.skel");
|
||||||
|
float scale = 0.6f;
|
||||||
|
SFMLTextureLoader textureLoader;
|
||||||
|
Atlas *atlas = new Atlas(atlasFile, &textureLoader);
|
||||||
|
SkeletonData *skeletonData = nullptr;
|
||||||
|
if (strncmp(skeletonFile.buffer(), ".skel", skeletonFile.length()) > 0) {
|
||||||
|
SkeletonBinary binary(atlas);
|
||||||
|
binary.setScale(scale);
|
||||||
|
skeletonData = binary.readSkeletonDataFile(skeletonFile);
|
||||||
|
} else {
|
||||||
|
SkeletonJson json(atlas);
|
||||||
|
json.setScale(scale);
|
||||||
|
skeletonData = json.readSkeletonDataFile(skeletonFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
AnimationStateData stateData(skeletonData);
|
||||||
|
SkeletonDrawable drawable(skeletonData, &stateData);
|
||||||
|
drawable.skeleton->setPosition(320, 590);
|
||||||
|
drawable.state->setAnimation(0, "walk", true);
|
||||||
|
|
||||||
|
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - testbed");
|
||||||
|
window.setFramerateLimit(60);
|
||||||
|
sf::Event event;
|
||||||
|
sf::Clock deltaClock;
|
||||||
|
while (window.isOpen()) {
|
||||||
|
while (window.pollEvent(event))
|
||||||
|
if (event.type == sf::Event::Closed) window.close();
|
||||||
|
|
||||||
|
float delta = deltaClock.getElapsedTime().asSeconds();
|
||||||
|
deltaClock.restart();
|
||||||
|
drawable.update(delta);
|
||||||
|
window.clear();
|
||||||
|
window.draw(drawable);
|
||||||
|
window.display();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user