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 - gop_t3r

Pages: 1 [2] 3
16
Graphics / Re: Help with Tile collisions
« on: February 10, 2014, 10:18:54 pm »
I've just implemented a bounding box collision test from another class I use for it; it appears the issue hasn't been resolved and am convinced that this has definitely something to do with the way tileNo is calculated. Just out of curiosity, what data type do you expect from pTiles or tileNumber? You haven't defined any data types in your example, and I'd like your input as to which data types you expect. Just so you know, pTiles is a vector array of integers.

17
Graphics / Re: Help with Tile collisions
« on: February 10, 2014, 09:42:52 pm »
The collision check only couts "collision" if and only if a collision has occurred, which should return true WHEN the tile 2 is collided with. The interesting part is this: look back at tests 1-4 in my other post and follow this:

Do you not see? The computer thinks the tiles that are meant to be 0, are in fact 2. By the way, when I say 'think', it is euphemism for whatever the computer assumes to be right or wrong. (I know the computer doesn't think)

What's funny is that even if I'm not at tile 2, it still returns true for collision IF I AM ON THE SAME HORIZONTAL AXIS as tile 2 or any other tile I want to collide with. So long as I am colliding with the tile, then it will continue to cout << "collision" until I leave the vicinity. Have you tested the code to see if you can detect the issue?

18
Graphics / Re: Help with Tile collisions
« on: February 10, 2014, 07:39:58 pm »
Do you only have one tile that would be tested for collision? Could it be "colliding" with a different tile that should be collided with?

That code is fine as long as your tile data is an array which goes through each x before y (i.e. like the tutorial tilemap does). It also relies on the fact that your tile map is located at the top-right corner, the tile size you use to calculate the grid sizes is correct, and the grid size is correct.

How are you testing this? Are you placing a sprite in one place explicitly, running the code, checking to see if text is output, and then ending the code. Or, are you moving the sprite without closing the program?

My tile-map is located at the top-left hand corner. I am testing this program by having my player moving without closing the program. If it moves to the aforementioned coordinates, the results thereof appear.

19
Graphics / Re: [SOLVED] Help with Tile collisions
« on: February 10, 2014, 06:48:53 pm »
it still returns true and thinks that it's on the same tile as the player was on (400, 300).
How do you know it thinks that? How are you testing to see if it's still true?

I'm using the same information you have given me regarding this collision.
The information I gave you was to detect which tile the origin of the sprite was in (so you could work out whether it was supposed to collide or not). For the actual collision detection, you would need to test the boundary boxes for the sprite against the tiles' boundary boxes.

The only way for it to return true is through the if statement provided; I have run the program and even though the player is not at the tile BUT is on the same horizontal axis as the tile, it returns true.

This is what I've concluded from testing, using the coordinates of the player:

Test 1: Where x = 168, y = 228 --> NO collision;
Test 2: Where x = 100, y = 332 --> collision; (this co-ordinate is located to the LEFT of the tile, outside thereof)
Test 3: Where x = 374, y = 320 --> collision; (this co-ordinate is located within the tile)
Test  4: Where x = 740, y = 308 --> collision; (this co-ordinate is located to the RIGHT of the tile, outside thereof)

As you can see, the outlier y value concludes that there is something wrong with the y value in collision detection. I have used the information you gave me to work out which tile the sprite was in, but what's interesting is that in all those three collision detections, REGARDLESS of what's being shown on screen; the tileNumber returns 2. In collision tests 2, 3 and 4: tileNumber returns 2, even though in collision tests 2 and 4 were OUTSIDE the tile. I don't think this is a problem with the actual collisions detection, but rather in how the program is interpreting which tile is which. So far, it only happens to tile numbers 2 and 3 and a collision test on both tiles returns true regardless of where we are on the horizontal axis.

I think a problem lies in this line of code:

float tileNo = (gridPosition.y * gridSize.x) + gridPosition.x;
 

20
Graphics / Re: [SOLVED] Help with Tile collisions
« on: February 10, 2014, 04:13:28 pm »
Hi, I am reopening this thread as an issue has arisen which I have not noticed until today:

The tile collision works, but appears the program thinks there's a collision when I am on the same x-axis as the specified tiles. Say a player collides with a tile at (400, 300), it returns true (there is a collision), but if I move along the x-axis outside the tile to somewhere like (300, 300), it still returns true and thinks that it's on the same tile as the player was on (400, 300).

21
Graphics / Re: Help with Tile collisions
« on: February 09, 2014, 05:35:55 am »
At least I have tile-collisions, what happens as a result thereof varies; indeed this thread's purpose has thus been satisfied and I hereby declare this issue resolved.

Thanks for your help!

22
Graphics / Re: Help with Tile collisions
« on: February 09, 2014, 12:08:56 am »
You just need to decide which tiles should collide and which ones shouldn't. Then test for those values.

For example, if the player shouldn't collide with tiles 0 or 1 but should collide with 2 or 3, then it would be:
if ((map.pTiles[tileNo] == 2) || (map.pTiles[tileNo] == 3))
{
  // player has collided with something it shouldn't have so move/stop/alter player accordingly.
}

Thanks, the collision test works! What I'm planning to do is simply have platforms 2 and 3 solid, such that the player can't move through them. How can I prevent a player from moving 'through' tiles? I tried a premature method of just subtracting 40 from the position thereof, but it doesn't do what I really want.

23
Graphics / Re: Help with Tile collisions
« on: February 08, 2014, 06:06:57 am »
You lost me now; where am I supposed to be implementing this? I'm assuming it's in the class implementation file, hence I created a function. My tilemap is actually stored in a file, and I modified my tile loader function to read from it. My tileset is actually 40 x 40; and yes, the origin is in the top-left corner of the window, and it does fit into the window as well.

I think some code could help out here, please; doesn't have to be accurate but I need an idea as to what you're getting at. If it's in main.cpp, then I'm happy to comply. In which case, there should be something like this:

float result = (player.sprite.getPosition().x - map.getPosition().x) / 40;
 

So far so good.

24
Graphics / Re: Help with Tile collisions
« on: February 08, 2014, 05:15:30 am »
Okay, I think I understand. You mean I need to create a getTileSize() function wherein I just get the size of the tile and test whether it's been collided with or not?

25
Graphics / Re: Help with Tile collisions
« on: February 08, 2014, 04:02:17 am »
I am no philosopher to be pragmatic as to know what we're supposed to do with tileSize. Right now, am clueless what you're asking for here, and I'd understand better if you elaborated how I'm supposed to use tileSize in order to get a tile collision through code rather than describing what's supposed to happen. I'm following what you're doing but I have no idea where I'm supposed to implement and how it's all coming together; everything's just fragmented.

26
Graphics / Re: Help with Tile collisions
« on: February 08, 2014, 01:27:55 am »
Do you know which position in the grid that your sprite is in? (i.e. in tile coordinates rather than pixel coordinates)
No, I don't know; how do I find out where my sprite is in tile coordinates?
Starting at the position that you display your tilemap, you just need to work out how many times tileSize has been passed - in both x and y. e.g. (sprite.x - tilemapOrigin.x) / tileSize.x
That is assuming that your tilemap's origin is still located at the top-left corner of the map.
You might also want to round it down to get the exact grid position.
The results will be where in the grid the sprite is and you can then know which tile values (in the array) you need to be checking.

When you refer to sprite.x, do you mean the player's sprite? How do I get the tilemap origin? There's no get origin function for Vertex Arrays.

27
Graphics / Re: Help with Tile collisions
« on: February 08, 2014, 12:36:03 am »
Using the code above...what must I modify in order to make tiles 2 and 3 collidable?
You wouldn't be modifying the code in the TileMap class. That just creates the actual image to display the map. You would be testing again the values in the array that holds the data on which tile should be shown at the tile position.

Do you know which position in the grid that your sprite is in? (i.e. in tile coordinates rather than pixel coordinates)

No, I don't know; how do I find out where my sprite is in tile coordinates?

28
Graphics / Re: Help with Tile collisions
« on: February 07, 2014, 08:23:14 pm »
Thanks for your responses, I know which tiles I want collidable but I need to know how it can be implemented. Using the code above as to loading a tile, what must I modify in order to make tiles 2 and 3 collidable? Using a finite state in order to control this would be very helpful but I'm open to other ideas. So far I've been able to grep all the tile numbers according to their value using an iterator, but I figure that may not be enough since those are just numbers, not the tiles themselves. Suffice it to say I don't know how I can check if it's a collidable type since it's just a number, unless I say: if the number is 2 or 3, then the tile is collidable. It's the latter that I don't know how to implement. Sorry for the confusion!

29
Graphics / Re: Help with Tile collisions
« on: February 06, 2014, 04:52:42 pm »
That could work, but again, it will always return true because the player is in the tile map to begin with. How can I discriminate so that only some of the tiles are collidable and others aren't?

30
Graphics / Help with Tile collisions
« on: February 06, 2014, 04:13:47 pm »
So far I got collisions between sprites that are of type sf::Sprite; but my tiles are not of type sf::Sprite so the collisions do not work. My tiles are of sf::VertexArray type, and I used the tile-map as a base from

http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php

I can get my player to check for collisions with the tile-map, but the only problem is that because all the numbers represent a tile the collision check returns true.

Using the code from the tutorial above, how can I implement a simple tile collision with a player that has a type sf::Sprite? Thanks for reading.

Pages: 1 [2] 3