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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Jan666

Pages: [1] 2 3 ... 5
1
Graphics / Re: RenderTexture Canvas Touch Offset Problem
« on: January 12, 2023, 12:28:45 pm »
I just want to paint on the canvas(RenderTexture, Sprite). I need a offest Frame to position Buttons around the canvas, to controll brushsize etc. But when i want to change the Position from the Canvas by the Sprite -> sprite.setPosition, i have a offset position between the direct fingertouch and the brush

2
Graphics / Re: RenderTexture Canvas Touch Offset Problem
« on: January 12, 2023, 09:06:09 am »
Okay i fix it, the following line was the problem
sprite.setPosition(50, 300);
 
But now i have to know how i change the Position of the canvas?

3
Graphics / RenderTexture Canvas Touch Offset Problem
« on: January 12, 2023, 08:51:29 am »
Hello, i try to make a little paint programm on mobilephone. You paint with the finger on a canvas(sf::RenderTexture). But the touch coordinates are not right on the canvas, there is a offset between the touch point and the draw point, i cant find the mistake, someone get an idea? I think there ist something wrong with the mapPixelToCoords between the window and canvas, here is the Code:

int main(int argc, char *argv[])
{
        const int xScreen = 1200;
        const int yScreen = 2600;
        const int borderScreen = 100;
       
        RenderWindow window(VideoMode(xScreen, yScreen), "Hello SFML");

   
 sf::RenderTexture canvas;
canvas.create(1100, 2000);
canvas.clear(sf::Color::White);

sf::Sprite sprite;
 sprite.setTexture(canvas.getTexture());sprite.setPosition(50, 300);   
View view(canvas.getView());
       
        vector<sf::Shape* > shapes;


        while (window.isOpen())
        {
               
                sf::Event event;
                while (window.pollEvent(event));
               
Vector2i touchy =  Touch::getPosition(0, window);
Vector2f touch = window.mapPixelToCoords(touchy);

CircleShape *shape = new CircleShape(10);
shape->setPosition(touch.x, touch.y);
shape->setOrigin(shape->getRadius(), shape->getRadius());
shape->setFillColor(sf::Color::Black);
               

FloatRect canvasRect = sprite.getGlobalBounds();

window.clear(sf::Color(80, 80, 80));
               
               
if(canvasRect.contains(touch)){
        shapes.push_back(shape);
       
               
for(auto it=shapes.begin(); it!=shapes.end();it++) {

canvas.draw(**it);
}

}
canvas.display();

                window.draw(sprite);
               
                window.display();
       
        }
        return 0;
}

 

4
Graphics / Sfml C4Droid
« on: January 08, 2023, 12:03:24 am »
Hello,
i am using for my mobile Phone C4Droid, its an IDE for mobile Phone. exist there some code to hide the screen menu symbols (Android) this ->>    |||   []    <    when i run my code? And exist there also any piece of Code that the Screen not rotate when i rotate my mobile Phone?

5
Graphics / Re: Stop looping when touch is holding
« on: October 14, 2022, 12:01:25 am »
Exist there something like this -> window.setKeyRepeatEnabled(false) for Touch?

6
Graphics / Re: Stop looping when touch is holding
« on: October 12, 2022, 02:53:54 pm »
Why is there no Touch examples on the "Events explained" tutorials?

7
Graphics / Re: Stop looping when touch is holding
« on: October 12, 2022, 02:49:34 pm »
I uesed Touch on mobile Phone, is  sf::Event::KeyPressed: equal to Event::TouchBegan? Need one input when press/ touch button, and stop looping when hold button

8
Graphics / Stop looping when touch is holding
« on: October 12, 2022, 12:59:07 pm »
Hello,
I need to fix following:
I have an animation that play when i Touch a Button. But its looping when i hold the touch on my Button. I dont wanna that, the animation should play once and should not depends how long i hold the touch. I find answers with Keys but i need to  know with Touch functions, there are not many to find in the net.
Here is my code piece:
if(animation == true){
if(animationClock.getElapsedTime().asSeconds() > 0.1)
{
animRec.x ++;
if(animRec.x * 103 >= animationTexture.getSize().x)
animRec.x = 0;

animationClock.restart();
}
}

FloatRect buttonRect = animationSprite.getGlobalBounds();




// the Touch is pressed the button
if(buttonRect.contains(worldPos)){

        animation = true;      
       

}
else
{

if(animRec.x * 412<= animationTexture.getSize().x)
{
        animation = false;     
}
}
 

9
Graphics / Re: Change drawable objects hierarchy ?
« on: October 06, 2022, 08:08:10 am »
For better understanding i post the following code, what i mean, i

if(playerPos.y > enemyPos.y){
                window.draw(player);
                window.draw(enemy);}
                else{
                        window.draw(enemy);
                        window.draw(player);
                }

 

10
Graphics / Change drawable objects hierarchy ?
« on: October 06, 2022, 12:07:10 am »
So i wanna make a beat em up game, you see the player from the side but you can also walk up an down. So i need to fix following: When the player is on the y axis higher than another object, the player have to be behind it and when the player's y axis is lower than the object , he is in front of it. Exist there something like to change the drawable objects hierarchy while the game i running and compare the y- axis of the booth?

11
Graphics / How animation with touch button
« on: September 22, 2022, 09:40:43 pm »
Hello,
i have a Spritesheet (the animation is in 24 Frames), now it only plays when my finger is on the touch Button (RectangleShape button). But i need to change this, i want that the SpriteSheet animation still plays automaticly one time when i touched the Button, without hold the finger on and without repeating the animation, how can i fix it? Here is the part if the code:


...

//init  Sprite( its a SpriteSheet)
sf::Texture texture;
texture.loadFromFile("test1.png");
sf::Sprite sprite;
sprite.setPosition(300, 500);
sprite.setScale(5, 5);
sprite.setTexture(texture);

//init Button
sf::RectangleShape button;
button.setSize(sf::Vector2f(600, 200));
button.setPosition( sf::Vector2f(500, 1900));
button.setFillColor(sf::Color::Red);

sf::Clock clock;
sf::Vector2f animRect;
       
        while (window.isOpen())
        {                                                      
       
       
                sf::Event event;

//Set Touch Coordinates to Screen
sf::Vector2i pixelPos = sf::Touch::getPosition(0, window);
sf::Vector2f worldPos = window.mapPixelToCoords(pixelPos);


//Set the Rect for the part of the SpriteSheet
sprite.setTextureRect(sf::IntRect (animRect.x * 101, animRect.y * 232, 101, 232));
               
                while (window.pollEvent(event))
                {                                              
                       
                if (event.type == sf::Event::Closed)
                                window.close();
                        }                      
//FloatRect fot the button Sprite              
sf::FloatRect btnRect = button.getGlobalBounds();
               
                //if touch the Button
                if(btnRect.contains(worldPos)){
                       
                        if(clock.getElapsedTime().asSeconds() >= 0.2){
                animRect.x++;
                if(animRect.x * 101 >= texture.getSize().x)
        animRect.x = 0;
           animRect.y = 0;
                clock.restart();
                        }                              
                }                      
 


12
Graphics / Manage different screens with touch button
« on: September 15, 2022, 08:48:47 pm »
Hello, i have a question i follow the Tutorial "manage for different Screens" on github. Now i wanna i build in a RectangleShape (btn1), who will used for a touch button to cgange on another screen, how i can handld this, here is my code:
class screen_1: public cscreen {
       
        public:        
         screen_1(void);        
        virtual int Run(sf::RenderWindow &App);
        void btn(sf::RenderWindow &App);
       
        private:
        sf::RectangleShape btn1;
        sf::FloatRect btn1Rect;
};

screen_1::screen_1(void){
       
        btn1.setSize(sf::Vector2f(500, 100));
        btn1.setPosition(sf::Vector2f(400, 500));
        btn1.setFillColor(sf::Color::Red);
       
}

void screen_1::btn(sf::RenderWindow &App){
       
        sf::Vector2i pixelPos = sf::Touch::getPosition(0, App);
                sf::Vector2f worldPos = App.mapPixelToCoords(pixelPos);
               
                btn1Rect = btn1.getGlobalBounds();
       
        if(btn1Rect.contains(worldPos)){
               
                screen_2::Run(); //dont work :(
               
}

int screen_1::Run(sf::RenderWindow &App){
       
        sf::Event event;        
        bool Running = true;
       
        while (Running) {              
       
        while (App.pollEvent(event))
        {                              
        if (event.type == sf::Event::Closed)                    {                      
                        return (-1);                   
                        }
                       
                               
                               
                               
                        }
        }
        App.clear(sf::Color(25, 200, 30));
        App.draw(btn1);
        App.display();
       
        }
        return (-1);
}



 


13
Graphics / If function for collision not working together
« on: August 15, 2022, 10:23:08 am »
Can someone Tell me why these four if functions not working together and how to fix it?

(playerBounds.intersects(wallBounds)){

if(wallBounds.left < playerBounds.left + playerBounds.width )

player.setPosition(wallBounds.left + wallBounds.width, playerBounds.top);


 if(playerBounds.left < wallBounds.left)

  player.setPosition(wallBounds.left - playerBounds.width, playerBounds.top);

if(wallBounds.top < playerBounds.top + playerBounds.height )

player.setPosition(playerBounds.left,  wallBounds.top + wallBounds.height);


 if(playerBounds.top < wallBounds.top)

  player.setPosition(playerBounds.left  , wallBounds.top - playerBounds.height);
   
}
 

14
Graphics / Collision Opposite Side
« on: August 09, 2022, 12:26:15 am »
Hey,
I have a question, the collision  between playerBounds and WallBounds works very good, but on the opposite Side not,  can somebody Tell me why?
 if(playerBounds.intersects(wallBounds)){
                       
        // Left Collision
 if (playerBounds.left < wallBounds.left + wallBounds.width && playerBounds.left + playerBounds.width > wallBounds.left)
         {
         
          player.setPosition(playerBounds.left, wallBounds.top - playerBounds.height);
          }
         
 
          // Boton Collision not working yet
 if( playerBounds.left >wallBounds.left + wallBounds.width && playerBounds.left + playerBounds.width > wallBounds.left)
          {
               
                player.setPosition(playerBounds.left, wallBounds.top - wallBounds.height);
            }  

 

15
Graphics / Re: Erase only one rectangleShape
« on: July 23, 2022, 10:08:40 pm »
I dont understand all parts of your code, but is it right, that you put multiple FloatRects in a Vector for the doors instead of shapes?

Pages: [1] 2 3 ... 5