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

Author Topic: Them GlobalBounds are wrong !  (Read 7941 times)

0 Members and 1 Guest are viewing this topic.

Falke88

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Them GlobalBounds are wrong !
« on: January 11, 2015, 05:10:47 pm »
Heya Sisters and Brothers!

I'm on my little learning project game and therefore was just about to solve a little mind puzzle for shooting a projectile onto an enemy and destroy it so hard!!!

El Problemo appears when my hitBox fields I just created aren't working. Actually I didn't tested them before that's why I came along this semantic error just now :(

I have two Entity Class types - one is called "Mack" and one is called "Mob" - Mack is the player here :D

Both have assigned a hitbox field (hitBox = this.sprite.GlobalBounds()).




Buttttt as you can maybe see in my screenshot - even tho these two entitys wont touch each other in the level scene they still have the same hitbox values. Actually the documentation says the hitbox will be the coordinates of bounds within a 2D Space. But in my example it kinda isn't. Or maybe it is but the 2D Space isn't the same as the Level view and gameplay scene actually.

When I move my character along the hitbox aka GetGlobalBounds() won't change either. It stays with the same values all the time.

I want to show the Class Hierarchy of an Enemy or Player Entity mybe the problem lies within' polymorphy here anyhow:



If I move my Entities they manipulate the Position Property of Transformable. And If I want my sprites GlobalBounds I'll get them within Enemy or Mack. Well Actually there shouldn't be a problem or am I wrong?




eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Them GlobalBounds are wrong !
« Reply #1 on: January 11, 2015, 05:50:12 pm »
Do you copy the GlobalBounds() once or do you actually query it once you want to use the hitbox. If you just create a copy of the bounds, then they obviously won't be updated.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Falke88

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: Them GlobalBounds are wrong !
« Reply #2 on: January 11, 2015, 07:56:46 pm »
hitBox = sprite.GetGlobalBounds();

Well thats how I assign it. Implicit assignment of a reference type always delivers a reference isn't it? Since it isnt a value type I don't need to add anything to make it explicit a ref.

Maybe I miss some core C# syntax here - can you point me to it? Because I feel like I did everything alright.


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Them GlobalBounds are wrong !
« Reply #3 on: January 11, 2015, 08:39:06 pm »
I don't know the C# specifics, but if you look around you'll see other threads stating that you don't get a referenced object.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Falke88

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: Them GlobalBounds are wrong !
« Reply #4 on: January 11, 2015, 09:42:18 pm »
ouhhhh me stupid...

I just realised that FloatRect is a struct == valueType.

Damn therefore I need to make this assignment a reference ...ha funny thing I didn't used valueTypes that much and never needed a reference to it...now its going to be interesting :P

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Them GlobalBounds are wrong !
« Reply #5 on: January 11, 2015, 09:52:22 pm »
I'm not sure if you can just use a reference, since underneath SFML.NET uses CSFML which uses SFML directly and the returned FloatRect from the C++ API is returned by value, so it won't update automatically and you instead have to always query the GlobalBounds.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Falke88

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: Them GlobalBounds are wrong !
« Reply #6 on: January 14, 2015, 09:03:38 am »
Hmm well...

Quering for GlobalBounds all the time makes me change my method to this:


public FloatRect GetHitBox()
        {
            return sprite.GetGlobalBounds();
        }


Still the weird thingie here is:

[FloatRect] Left(-25) Top(-25) Width(50) Height(50)

thats the GlobalBounds Values for my player and the mob I spawned in the level. Both have the same values even tho they both are moving around.

What I'm missing here so badly?

EDIT: One solution might be that I calculate the hitbox Position by calculating it out (Position.x + hitbox.left...etc) But I don't think that's the best approach here.


greets Charlie
« Last Edit: January 14, 2015, 09:48:43 am by Falke88 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Them GlobalBounds are wrong !
« Reply #7 on: January 14, 2015, 10:26:24 am »
Could you please provide a complete and minimal code that reproduces the problem?
Laurent Gomila - SFML developer

Falke88

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: Them GlobalBounds are wrong !
« Reply #8 on: January 15, 2015, 07:52:57 am »
Sorry for that early post - but gladly you slammed in before I made anything redundant.
Here's how I tried to sum it up as short as possible.

GameWorld is actually the level with window, backgrounds etc. As I read through the documentation GetGlobalBounds() will return the Coords within 2D space.
Now actually in the if statement of GameWorld "Touching" is called all the time even tho the two entitys aren't nearby. Printing their GlobalBounds will always show the same values even when they're moving - and they both have the same values aswell.


class Enemy{
  Sprite sprite = new Sprite();
  Utility.CenterOrigin(sprite); // centers the LocalBounds only;

  public FloatRect GetHitbox(){
    return sprite.GetGlobalBounds();
  }
}
 

class Player{
  Sprite sprite = new Sprite();
  Utility.CenterOrigin(sprite); // centers the LocalBounds only;

  public FloatRect GetHitbox(){
    return sprite.GetGlobalBounds();
  }
}
 

class GameLevel{
  RenderWindow window;
  [...etc.]
  Player player = new Player();
  List<Enemy> enemy = new List();
  enemy.Add(new Enemy(), new Enemy());

  if(enemy[0].GetHitBox().Intersects((player.GetHitbox())))
                Console.WriteLine("Touching!");
}
 
« Last Edit: January 15, 2015, 08:23:02 am by Falke88 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Them GlobalBounds are wrong !
« Reply #9 on: January 15, 2015, 08:04:56 am »
We don't care about understanding the design of your game code, we just want some simple, complete and minimal code that only reproduces the problem (and only that). If it's not clear, you have to write this code yourself, don't try to post parts of your original code ;)

http://sscce.org/
Laurent Gomila - SFML developer

Falke88

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: Them GlobalBounds are wrong !
« Reply #10 on: January 15, 2015, 08:23:10 am »
*Changed

Falke88

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: Them GlobalBounds are wrong !
« Reply #11 on: January 15, 2015, 04:00:52 pm »
Did I managed to give you the idea and reproduction of the problem here good enough?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Them GlobalBounds are wrong !
« Reply #12 on: January 15, 2015, 04:04:41 pm »
No. Please read http://sscce.org/ carefully.
Laurent Gomila - SFML developer

Falke88

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: Them GlobalBounds are wrong !
« Reply #13 on: January 15, 2015, 04:08:21 pm »
So...should I post an code example which you guys can actually run ??? ?
« Last Edit: January 15, 2015, 04:10:41 pm by Falke88 »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Them GlobalBounds are wrong !
« Reply #14 on: January 15, 2015, 04:10:44 pm »
Yes. That is the whole point.
A minimal runnable example.
Just a main function with just enough to reproduce the problem.

 

anything