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.


Topics - Jan666

Pages: 1 [2]
16
Graphics / Bullet Face direction problem
« on: May 27, 2022, 08:04:33 am »
Hello, i need a solution for a 2d shot game. The player still shot to the right direction, i have no idea how i change the bullet direction when he walk to the left side?


//Touch Shot Button
if(btn.btnRect3.contains(worldPos)){
                                                                       
                           isFiring = true;      
}


//bullet shot details

if(isFiring == true){
       
        bullet newBullet (Vector2f( 20, 20));
        newBullet.bulletSetPos(Vector2f(player.playerSprite.getPosition().x  + 60, player.playerSprite.getPosition().y + 100));
        bulletVec.push_back(newBullet);
        isFiring = false;
   }



 

Any Ideas

17
Graphics / Player View dont stop with the Player
« on: May 23, 2022, 11:50:10 am »
Hi
I have another question about sf::View. It is center to my Player and follow him. But if the Player collide with a wall and stop the view still moves if the move button is pressed. So here is my code when the Player  collide:
...

void player::plrBounce(Vector2f &wallBounce){
       
wallBounce = plrSprite.getPosition();
        plrSprite.setPosition(wallBounce.x, wallBounce.y +5);
       
}

...

if(plr.plrSprite.getGlobalBounds().intersects(WallRect.getGlobalBounds())){
       
                plr.plrBounce(wallBounce);

 

and here is my view setting:

View plrview( FloatRect(0, 0, 1300, 2600));
    plrview.setCenter(plr.plrSprite.getPosition());

 

So what could i do that the playerview is parenting to the player and stops when he stops??

18
Graphics / Sf::View and How can i fix things on display?
« on: May 22, 2022, 08:06:09 am »
Hi,
I try to make 2d sidescroller with Touch on mobilephone. I used sf::View to follow my Player, and it works. But i have also 3 Buttons on display they move away. How can i fix them on display?

19
Graphics / Not walk trough th Rect?
« on: May 20, 2022, 01:49:34 pm »
Hello again,
Sry i dont want annoying to fill this Forum with newbie questions, but this Forum give me the best answers.

So i am working on a sidescroller, in the middle of the Screen is a RectangleShape, and if i collide it with my playerSprite, the Background Moves. Now i want that the Player not go through the Rectangle, ho can i fix it, here is my codepart:


if(playerSprite.getGlobalBounds().intersects(rect.getGlobalBounds())){
               
        backgroundSprite.move( 0, -3);
        // playerSprite dont walk trough rect???
               
}

 

20
Graphics / Flip Sprite setScale problem
« on: May 20, 2022, 06:52:54 am »
Hello,
Maybe someone knows a solution. I have setScale(3 ,3.5) my Sprite coz its too small. But when i used setScale again to flip my sprite with (-1 ,1) when it move to left, the Sprite get small. Is there any way to safe the first setScale values for the Sprite? I dont wanna use other ways like for example IntRect(0,0,-weight, height) coz i used a Spritesheet and its getting to complicated with the animation.

21
Graphics / Sprite in multiple cpp files
« on: May 15, 2022, 11:45:04 pm »
Hi, i got a question. I have a Sprite call "plrSprite" in the player.h file and player.cpp file, but i need to use it in my button.cpp.file to move it, know someone a solution?
Player.h file:
...
private:
       
        Sprite plrSprite; //i need this sprite
        Texture plrText;
        Image plrImage;
...
 

Player.cpp file:

...
void player::plrMove(){
               
        plrSprite.move(3, 0);   // with this function
}
...
 

Button.cpp file:
void buttons::btnTouch(RenderWindow &window){
                               
sf::Vector2i pixelPos = sf::Touch::getPosition(0, window);
sf::Vector2f worldPos = window.mapPixelToCoords(pixelPos);

btnRect1 = btnSprite1.getGlobalBounds();
       
        if(btnRect1.contains(worldPos)){
               
        btnSprite1.setTexture(btnText2);       

                            // i need it here !!!!!!!!!!!!!!!!!!!!
        }
        else{          
                btnSprite1.setTexture(btnText);        
        }  
       


 

22
Window / How to Convert Touch Sprite to world coordinates
« on: May 13, 2022, 12:13:31 am »
Hi, i need Help, by the following problem:
I have a Sprite who present a touch Button. when i touch it, the color change. The problem is, that the full touch contact not on the Sprite is just next to it. I need to implement mapToPixelCoordinate to convert the Touch to world coordinates. Here is my code


int main(int argc, char *argv[])
{
        sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "Hello SFML");

        sf::Sprite sprite;
        sf::Texture tex;
        sf::Texture tex2;
        tex.loadFromFile("red.png");
        tex2.loadFromFile("green.png");
        sprite.setPosition(300, 700);
                       
        while (window.isOpen())
        {

                sf::Event event;
                while (window.pollEvent(event));
               

                                                               
                sf::FloatRect frec = sprite.getGlobalBounds();
               
                               
if(frec.contains(sf::Touch::getPosition(0).x, sf::Touch::getPosition(0).y)){
                               
                        sprite.setTexture(tex);                
                }
                else
                {                      
                        sprite.setTexture(tex2);
                }
                               
                window.clear(sf::Color(0, 0, 0));      
                window.draw(sprite);
                window.display();
               
        }
        return 0;
}

 

Someone know how i do this? Maybe put this code insdie it? I
sf::Vector2i pixelPos = sf::Touch::getPosition(0, window);
sf::Vector2f worldPos = window.mapPixelToCoords(pixelPos);
 

dont know how to fix it in the right way

23
Graphics / Touch Button position Problem
« on: May 11, 2022, 12:57:02 pm »
Hi, i search a solution maybe someone can help. I have three Buttons for a Controller on mobile phone. They turn the Color when i touch them(2 changing Sprites). The Problem is that the Touch not directly React on the Sprite just next to it or just on the half Sprite, how can i change this. Here is my Code. They are 3 Files main.cpp, buttons.h. buttons.cpp:

I think Buttons.cpp is just important fot the problem:


using namespace sf;
using namespace std;

float btnScaleX = 3.0f;
float btnScaleY = 2.6f;
float btnPosX = 100;
float btnLeftPosY = 200;
float btnRightPosY = 500;
float btnFirePosY =1300;
Vector2f btnScaler (btnScaleX, btnScaleY);
Vector2f btnPosLeft(btnPosX, btnLeftPosY);
Vector2f btnPosRight(btnPosX, btnRightPosY);
Vector2f btnPosFire(btnPosX, btnFirePosY);
FloatRect btnRect1;
FloatRect btnRect2;
FloatRect btnRect3;



buttons::buttons()
{
       
}

buttons::buttons(string btnPng, string btnPng2)

{
       
        btnText.loadFromFile(btnPng);
        btnText2.loadFromFile(btnPng2);

       
       
}

 void buttons::btnInit()
 
 {
 
        btnSprite1.setScale(btnScaler);
        btnSprite2.setScale(btnScaler);
        btnSprite3.setScale(btnScaler);
       
       
       
       
        btnSprite1.setPosition(btnPosLeft);
        btnSprite2.setPosition(btnPosRight);   
     btnSprite3.setPosition(btnPosFire);
     
     btnSprite3.getTextureRect(btnPosFire);
                       
 }
 
 void buttons::btnTouch(){
                       
btnRect1 = btnSprite1.getGlobalBounds();
                               
if(btnRect1.contains(::sf::Touch::getPosition(0).x, ::sf::Touch::getPosition(0).y)){


        btnSprite1.setTexture(btnText2);       
        }
        else{          
                btnSprite1.setTexture(btnText);
        }  
   
btnRect2 = btnSprite2.getGlobalBounds();
                       
if(btnRect2.contains(::sf::Touch::getPosition(0).x, ::sf::Touch::getPosition(0).y)){


        btnSprite2.setTexture(btnText2);       
        }
        else{          
                btnSprite2.setTexture(btnText);
        }  
       
btnRect3 = btnSprite3.getGlobalBounds();

                       
if(btnRect3.contains(::sf::Touch::getPosition(0).x, ::sf::Touch::getPosition(0).y)){


        btnSprite3.setTexture(btnText2);       
        }
        else{          
                btnSprite3.setTexture(btnText);
        }  
 
   
}
       
 
 void buttons::btnDraw(RenderWindow &window)
 
 {
       
        window.draw(btnSprite1);
        window.draw(btnSprite2);
        window.draw(btnSprite3);
       
 }

 


24
Graphics / Constructor problem, need help
« on: May 09, 2022, 09:32:18 pm »
Hi, can someone help me with this following Problem, i wanna make a touch game on android, so i beginn with three touch buttons. I dont know why its not working, any Construcor problem

main.cpp:

#include <SFML/Graphics.hpp>
#include "buttons.h"
#include <iostream>

using namespace sf;
using namespace std;

int main(int argc, char *argv[])
{
        sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "Hello SFML");
       
        buttons btn("buttons.png");
        btn.btnInit (3.0, 3.0, 300.0, 250.0, 500.0, 700.0);
       
       
       
        while (window.isOpen())
        {
               
                sf::Event event;
                while (window.pollEvent(event));
               
                window.clear(sf::Color(0, 0, 0));
               
                btn.btnDraw(window);
                window.display();

                       
        }
        return 0;
}
 

Button.h:
#ifndef BUTTONS_H
#define BUTTONS_H

#include <SFML/Graphics.hpp>

using namespace sf;
using namespace std;

class buttons {
       
       
       
       
   public :
       
       
        buttons(string btnPng);
       
        void btnInit(float btnScaleX, float btnScaleY, float btnPosX, float btnLeftPosY, float btnRightPosY, float btnFirePosY);
       
         void btnDraw(RenderWindow &window);

         
        private:
       
        Sprite btnSprite;
        Texture btnText;
         
   
       
};

#endif
 

and Buttons.cpp:
#include <SFML/Graphics.hpp>
#include <iostream>
#include "buttons.h"


using namespace sf;
using namespace std;

buttons::buttons()
{
       
}


buttons::buttons(string btnPng){
       
        btnText.loadFromFile(btnPng);
        btnSprite.setTexture(btnText);
       
}

 void buttons::btnInit(float btnScaleX, float btnScaleY, float btnPosX, float btnLeftPosY, float btnRightPosY, float btnFirePosY){
       
        btnSprite.setScale(btnScaleX, btnScaleY);
        btnSprite.setPosition(btnPosX, btnLeftPosY);
        btnSprite.setPosition(btnPosX, btnRightPosY);
        btnSprite.setPosition(btnPosX, btnFirePosY);
       
       
       
 }
 
 void buttons::btnDraw(RenderWindow &window){
       
        window.draw(btnSprite);
        window.draw(btnSprite);
        window.draw(btnSprite);
       
 }

25
Graphics / Touch Button
« on: March 22, 2022, 01:23:05 pm »
Hi i am searching the Code for a simple Exercise, maybe someone can help me. I work with  sf::Touch, let me explain what i need:
I have 2 RectableShapes  and now i want to use one for a button. If i touch the ButtonRectable the Color change by Rectable Nr.2?


Pages: 1 [2]
anything