Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem Loading Images on App Bundle on Mac os x  (Read 2551 times)

0 Members and 1 Guest are viewing this topic.

lestroso

  • Newbie
  • *
  • Posts: 9
    • View Profile
Problem Loading Images on App Bundle on Mac os x
« on: April 06, 2020, 07:53:47 pm »
Hi,
i try to play with this code, to make an Arkanoid...in Macosx With Netbeans 13...

#include <SFML/Graphics.hpp>
#include <time.h>
using namespace sf;

int main()
{
    srand(time(0));

    RenderWindow app(VideoMode(520, 450), "Arkanoid!");
    app.setFramerateLimit(60);

    Texture t1,t2,t3,t4;
    t1.loadFromFile("images/block01.png");
    t2.loadFromFile("images/background.jpg");
    t3.loadFromFile("images/ball.png");
    t4.loadFromFile("images/paddle.png");

    Sprite sBackground(t2), sBall(t3), sPaddle(t4);
    sPaddle.setPosition(300,440);

    Sprite block[1000];

    int n=0;
    for (int i=1;i<=10;i++)
    for (int j=1;j<=10;j++)
      {
         block[n].setTexture(t1);
         block[n].setPosition(i*43,j*20);
         n++;
      }

    float dx=6, dy=5;
    float x=300, y=300;

    while (app.isOpen())
    {
       Event e;
       while (app.pollEvent(e))
       {
         if (e.type == Event::Closed)
             app.close();
       }

    x+=dx;
    for (int i=0;i<n;i++)
        if ( FloatRect(x+3,y+3,6,6).intersects(block[i].getGlobalBounds()) )
             {block[i].setPosition(-100,0); dx=-dx;}

    y+=dy;
    for (int i=0;i<n;i++)
        if ( FloatRect(x+3,y+3,6,6).intersects(block[i].getGlobalBounds()) )
             {block[i].setPosition(-100,0); dy=-dy;}

    if (x<0 || x>520)  dx=-dx;
    if (y<0 || y>450)  dy=-dy;

    if (Keyboard::isKeyPressed(Keyboard::Right)) sPaddle.move(6,0);
    if (Keyboard::isKeyPressed(Keyboard::Left)) sPaddle.move(-6,0);

    if ( FloatRect(x,y,12,12).intersects(sPaddle.getGlobalBounds()) ) dy=-(rand()%5+2);

    sBall.setPosition(x,y);

    app.clear();
    app.draw(sBackground);
    app.draw(sBall);
    app.draw(sPaddle);

    for (int i=0;i<n;i++)
     app.draw(block[i]);

    app.display();
    }

  return 0;
}
 

Ok , this code is very good..but when i make the final app bundle...the app starts, the window ok.. but i don't see any images!!!but inside Netbeans this code works fine..

I have tryed anything like this::
Texture t1,t2,t3,t4;
    t1.loadFromFile("./images/block01.png"); <---------
    t2.loadFromFile("../images/background.jpg"); <--------
    t3.loadFromFile("Resource/images/ball.png"); <----------
    t4.loadFromFile("images/paddle.png");
 
it seems dont see where the link is....
Nothing works here???...Can somebody help me please??? Best regards, Lestroso  :) :) :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10820
    • View Profile
    • development blog
    • Email
Re: Problem Loading Images on App Bundle on Mac os x
« Reply #1 on: April 07, 2020, 10:21:36 am »
As far as I understand macOS, you'll have to retrieve the resource path to the bundle, see the obj-c call: https://developer.apple.com/documentation/foundation/nsbundle/1417723-resourcepath?language=objc
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

lestroso

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Problem Loading Images on App Bundle on Mac os x
« Reply #2 on: April 07, 2020, 02:29:26 pm »
Dear eXpl0it3r,

i thank you so much for your answer....but i don't see any solution....there....

i tryed this to link to my bundle...:
 t3.loadFromFile("Resource/images/ball.png"); <----------but nothing works...
 
I have tryed to link to my bundle Resources...but nothing...
Do you have any other idea???

Best regards, Lestroso :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10820
    • View Profile
    • development blog
    • Email
Re: Problem Loading Images on App Bundle on Mac os x
« Reply #3 on: April 07, 2020, 03:00:38 pm »
No idea how you came to the conclusion that adding "Resource" in front of the path will do anything? :D

You need to get the path to the bundle. I've provided the link to the API call that does it. You can also google ResourcePath macOS to get more information on the topic.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

fallahn

  • Sr. Member
  • ****
  • Posts: 492
  • Buns.
    • View Profile
    • Trederia
Re: Problem Loading Images on App Bundle on Mac os x
« Reply #4 on: April 08, 2020, 10:48:51 am »
The SFML xcode templates folder contains source for doing this in ResourcePath.hpp and ResourcePath.mm https://github.com/SFML/SFML/tree/master/tools/xcode/templates/SFML/SFML%20App.xctemplate

This will return a string containing path that you can prepend to the paths of your images and other resources.

lestroso

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Problem Loading Images on App Bundle on Mac os x
« Reply #5 on: April 08, 2020, 06:59:33 pm »
hi...
thank you for your support....but i need in truth an easy way to do that....i tryed to load the a template with xcode...without success.. i dont' use xcode too difficult...i'm working with netbeans to be crossplatform...so...i wonder me if in the bundle do i must customize theplist.file to load that resources.. to tell to the bundle where to fish theresources...

Any other ideas??? Or Help?? best regards, lestroso :)