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

Login with username, password and session length

 
Advanced search

1055643 Posts in 42869 Topics- by 34800 Members - Latest Member: reinfeldx

October 21, 2014, 05:35:28 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Android platformer help
Pages: [1]
Print
Author Topic: Android platformer help  (Read 410 times)
cubertron
Level 0
***


View Profile Email
« on: February 01, 2013, 09:32:05 AM »

I am making a platformer game for android using ANDEngine. The engine only provides hitbox collision and the method returns true/false in case of collision/no collision.

My questions:
1) How can I implement the basic character physics without using Box2D. Should I use some trigger points(left/right top/bottom) around the player to manage vertical and horizontal movement?

2) If I have like 100 tiles, should I iterate through all the list to check if player collided with anyone of them? Won't this be super slow?Is there a way to optimize this?

Thanks!
Logged
randomnine
Level 1
*


View Profile WWW
« Reply #1 on: February 02, 2013, 06:50:37 AM »

Hey.

1) This thread ought to give you some ideas.

2) Assuming your tiles are snapped to a grid, put them in a 2D array such that their position in the array corresponds to their position in the world. The character's X/Y location at any given time will then map to a certain position in that array. You'll be able to test the character against just the tiles immediately around them.
Logged

Aloshi
Level 2
**



View Profile
« Reply #2 on: February 02, 2013, 07:57:07 PM »

Regarding your second question, this explains it quite nicely.
Logged
Vadinci
Level 0
**



View Profile
« Reply #3 on: February 03, 2013, 09:22:15 AM »

How I usually handle this is to give the player a xspeed and an yspeed variable. In the update loop you move the player over the x-axis by the amount of xspeed. once you have done that , you check for collision; if there is none, continue. if there is a collision however, move the player in the opposite direction 1 pixel at a time, until there is no more collision. Then set the x-speed to 0. now do the same for the yspeed.

I don't usually work with hitboxes for my tiles though, instead I have a 2d dimensional array which holds a boolean for each tile, stating if they are solid or not.

I hope you can do something with this Smiley good luck
Logged
cubertron
Level 0
***


View Profile Email
« Reply #4 on: February 03, 2013, 08:24:36 PM »

Regarding your second question, this explains it quite nicely.

Thanks for it :D , I was actually thinking something like this but was not sure if it is a good method or not.

How I usually handle this is to give the player a xspeed and an yspeed variable. In the update loop you move the player over the x-axis by the amount of xspeed. once you have done that , you check for collision; if there is none, continue. if there is a collision however, move the player in the opposite direction 1 pixel at a time, until there is no more collision. Then set the x-speed to 0. now do the same for the yspeed.

I don't usually work with hitboxes for my tiles though, instead I have a 2d dimensional array which holds a boolean for each tile, stating if they are solid or not.

I hope you can do something with this Smiley good luck

So if you use 2d arrays, then how do you handle the collision?I mean the boolean array is good enough to know if the tiles are solid are not, but what for the positioning?If you use move the player 1 pixel at a time until the collision is over, doesn't this looks a bit weird(considering in terms of visual, like if the player is in half of the tile)
Logged
Vadinci
Level 0
**



View Profile
« Reply #5 on: February 04, 2013, 04:20:33 AM »

So if you use 2d arrays, then how do you handle the collision?I mean the boolean array is good enough to know if the tiles are solid are not, but what for the positioning?If you use move the player 1 pixel at a time until the collision is over, doesn't this looks a bit weird(considering in terms of visual, like if the player is in half of the tile)

It's not moving 1 pixel per frame, it's moving by 1 pixel until there is no collision anymore, so
Code:
while(collision)
{
 //move by 1 pixel
}
xspeed = 0;

so what will happen is, say the player has a xspeed of 10, and there is a tile 4 pixels to the right of the player. The player will move by 10 pixels, and register a collision, now it starts moving 1 pixel to the left in a loop, until there is no more collision; this will happen after 6 loops. At the end of the game tick, the player has effectively moved 4 pixels to the right, and touches the tile.

regarding the boolean array, I made my own hitbox-ish system, and I check for important points within the hitbox. Each of these points I translate to a point in the boolean array (which is simply dividing the coordinate by the Tile width and/or height, and then flooring it). It's just a different way of checking for collision.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic