diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake
index 25467cd2..f92cf796 100644
--- a/cmake/Macros.cmake
+++ b/cmake/Macros.cmake
@@ -223,7 +223,18 @@ macro(sfml_add_example target)
add_executable(${target} WIN32 ${target_input})
target_link_libraries(${target} PRIVATE sfml-main)
elseif(THIS_GUI_APP AND SFML_OS_IOS)
- add_executable(${target} MACOSX_BUNDLE ${target_input})
+
+ # For iOS apps we need the launch screen storyboard,
+ # and a custom info.plist to use it
+ SET(LAUNCH_SCREEN "${CMAKE_SOURCE_DIR}/examples/assets/LaunchScreen.storyboard")
+ SET(LOGO "${CMAKE_SOURCE_DIR}/examples/assets/logo.png")
+ SET(INFO_PLIST "${CMAKE_SOURCE_DIR}/examples/assets/info.plist")
+ SET(ICONS "${CMAKE_SOURCE_DIR}/examples/assets/icon.icns")
+ add_executable(${target} MACOSX_BUNDLE ${target_input} ${LAUNCH_SCREEN} ${LOGO} ${ICONS})
+ set(RESOURCES ${LAUNCH_SCREEN} ${LOGO} ${ICONS})
+ set_target_properties(${target} PROPERTIES RESOURCE "${RESOURCES}"
+ MACOSX_BUNDLE_INFO_PLIST ${INFO_PLIST}
+ MACOSX_BUNDLE_ICON_FILE icon.icns)
target_link_libraries(${target} PRIVATE sfml-main)
else()
add_executable(${target} ${target_input})
@@ -264,7 +275,8 @@ macro(sfml_add_example target)
# add the install rule
install(TARGETS ${target}
RUNTIME DESTINATION ${target_install_dir} COMPONENT examples
- BUNDLE DESTINATION ${target_install_dir} COMPONENT examples)
+ BUNDLE DESTINATION ${target_install_dir} COMPONENT examples
+ RESOURCE DESTINATION ${target_install_dir} COMPONENT examples)
# install the example's source code
install(FILES ${THIS_SOURCES}
diff --git a/examples/assets/LaunchScreen.storyboard b/examples/assets/LaunchScreen.storyboard
new file mode 100644
index 00000000..e2c2d2c3
--- /dev/null
+++ b/examples/assets/LaunchScreen.storyboard
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/assets/icon.icns b/examples/assets/icon.icns
new file mode 100644
index 00000000..cb95460b
Binary files /dev/null and b/examples/assets/icon.icns differ
diff --git a/examples/assets/info.plist b/examples/assets/info.plist
new file mode 100644
index 00000000..910ff4c2
--- /dev/null
+++ b/examples/assets/info.plist
@@ -0,0 +1,36 @@
+
+
+
+
+ CFBundleIconFile
+ icon.icns
+ UILaunchStoryboardName
+ LaunchScreen
+ CFBundleDevelopmentRegion
+ English
+ CFBundleExecutable
+ $(EXECUTABLE_NAME)
+ CFBundleGetInfoString
+
+ CFBundleIdentifier
+ org.sfml-dev.$(EXECUTABLE_NAME)
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundleLongVersionString
+ 2.5.1
+ CFBundleName
+ $(EXECUTABLE_NAME)
+ CFBundlePackageType
+ APPL
+ CFBundleShortVersionString
+
+ CFBundleSignature
+ ????
+ CFBundleVersion
+
+ CSResourcesFileMapped
+
+ NSHumanReadableCopyright
+
+
+
diff --git a/examples/assets/logo.png b/examples/assets/logo.png
new file mode 100644
index 00000000..7b04c41a
Binary files /dev/null and b/examples/assets/logo.png differ
diff --git a/examples/iOS/resources/canary.wav b/examples/iOS/resources/canary.wav
deleted file mode 100644
index a0f3aecc..00000000
Binary files a/examples/iOS/resources/canary.wav and /dev/null differ
diff --git a/examples/iOS/resources/image.png b/examples/iOS/resources/image.png
deleted file mode 100644
index 29ba0102..00000000
Binary files a/examples/iOS/resources/image.png and /dev/null differ
diff --git a/examples/iOS/resources/orchestral.ogg b/examples/iOS/resources/orchestral.ogg
deleted file mode 100644
index f764d61d..00000000
Binary files a/examples/iOS/resources/orchestral.ogg and /dev/null differ
diff --git a/examples/iOS/resources/sansation.ttf b/examples/iOS/resources/sansation.ttf
deleted file mode 100644
index d85fbc81..00000000
Binary files a/examples/iOS/resources/sansation.ttf and /dev/null differ
diff --git a/examples/opengl/OpenGL.cpp b/examples/opengl/OpenGL.cpp
index bcafba0b..37942ff7 100644
--- a/examples/opengl/OpenGL.cpp
+++ b/examples/opengl/OpenGL.cpp
@@ -220,13 +220,24 @@ int main()
// Adjust the viewport when the window is resized
if (event.type == sf::Event::Resized)
{
+ sf::Vector2u textureSize = backgroundTexture.getSize();
+
// Make the window the active window for OpenGL calls
window.setActive(true);
glViewport(0, 0, event.size.width, event.size.height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ GLfloat ratio = static_cast(event.size.width) / event.size.height;
+ glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
// Make the window no longer the active window for OpenGL calls
window.setActive(false);
+
+ sf::View view;
+ view.setSize(textureSize.x, textureSize.y);
+ view.setCenter(textureSize.x/2.f, textureSize.y/2.f);
+ window.setView(view);
}
}
@@ -241,9 +252,17 @@ int main()
// Clear the depth buffer
glClear(GL_DEPTH_BUFFER_BIT);
- // We get the position of the mouse cursor, so that we can move the box accordingly
- float x = sf::Mouse::getPosition(window).x * 200.f / window.getSize().x - 100.f;
- float y = -sf::Mouse::getPosition(window).y * 200.f / window.getSize().y + 100.f;
+ // We get the position of the mouse cursor (or touch), so that we can move the box accordingly
+ sf::Vector2i pos;
+
+ #ifdef SFML_SYSTEM_IOS
+ pos = sf::Touch::getPosition(0);
+ #else
+ pos = sf::Mouse::getPosition();
+ #endif
+
+ float x = pos.x * 200.f / window.getSize().x - 100.f;
+ float y = -pos.y * 200.f / window.getSize().y + 100.f;
// Apply some transformations
glMatrixMode(GL_MODELVIEW);
diff --git a/examples/pong/Pong.cpp b/examples/pong/Pong.cpp
index 5cd4afa6..796d2ab2 100644
--- a/examples/pong/Pong.cpp
+++ b/examples/pong/Pong.cpp
@@ -84,7 +84,12 @@ int main()
pauseMessage.setCharacterSize(40);
pauseMessage.setPosition(170.f, 150.f);
pauseMessage.setFillColor(sf::Color::White);
+
+ #ifdef SFML_SYSTEM_IOS
+ pauseMessage.setString("Welcome to SFML pong!\nTouch the screen to start the game");
+ #else
pauseMessage.setString("Welcome to SFML pong!\nPress space to start the game");
+ #endif
// Define the paddles properties
sf::Clock AITimer;
@@ -134,6 +139,15 @@ int main()
while (std::abs(std::cos(ballAngle)) < 0.7f);
}
}
+
+ // Window size changed, adjust view appropriately
+ if (event.type == sf::Event::Resized)
+ {
+ sf::View view;
+ view.setSize(gameWidth, gameHeight);
+ view.setCenter(gameWidth/2.f, gameHeight/2.f);
+ window.setView(view);
+ }
}
if (isPlaying)
@@ -154,8 +168,9 @@ int main()
if (sf::Touch::isDown(0))
{
- sf::Vector2i pos = sf::Touch::getPosition(0, window);
- leftPaddle.setPosition(0.f, pos.y);
+ sf::Vector2i pos = sf::Touch::getPosition(0);
+ sf::Vector2f mappedPos = window.mapPixelToCoords(pos);
+ leftPaddle.setPosition(leftPaddle.getPosition().x, mappedPos.y);
}
// Move the computer's paddle
@@ -181,16 +196,22 @@ int main()
float factor = ballSpeed * deltaTime;
ball.move(std::cos(ballAngle) * factor, std::sin(ballAngle) * factor);
+ #ifdef SFML_SYSTEM_IOS
+ const std::string inputString = "Touch the screen to restart";
+ #else
+ const std::string inputString = "Press space to restart or\nescape to exit";
+ #endif
+
// Check collisions between the ball and the screen
if (ball.getPosition().x - ballRadius < 0.f)
{
isPlaying = false;
- pauseMessage.setString("You lost!\nPress space to restart or\nescape to exit");
+ pauseMessage.setString("You Lost!\n" + inputString);
}
if (ball.getPosition().x + ballRadius > gameWidth)
{
isPlaying = false;
- pauseMessage.setString("You won!\nPress space to restart or\nescape to exit");
+ pauseMessage.setString("You Won!\n" + inputString);
}
if (ball.getPosition().y - ballRadius < 0.f)
{
diff --git a/examples/window/Window.cpp b/examples/window/Window.cpp
index c90f9676..c6a8c907 100644
--- a/examples/window/Window.cpp
+++ b/examples/window/Window.cpp
@@ -129,7 +129,13 @@ int main()
// Resize event: adjust the viewport
if (event.type == sf::Event::Resized)
+ {
glViewport(0, 0, event.size.width, event.size.height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ GLfloat ratio = static_cast(event.size.width) / event.size.height;
+ glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
+ }
}
// Clear the color and depth buffers