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

Login with username, password and session length

 
Advanced search

878106 Posts in 32905 Topics- by 24327 Members - Latest Member: MasterFenrir

May 21, 2013, 06:44:12 AM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)More work than needed?
Pages: [1]
Print
Author Topic: More work than needed?  (Read 1323 times)
roboprez
Level 1
*


Got to love them pixels


View Profile WWW Email
« on: October 24, 2009, 10:19:34 PM »

I'm working on a game in Flash with a small group of people. I'm currently programing the engine using As3 in Flah sh Develop.
What I'm focussing on right now is getting collision working. Now what I've currently done is have the games levels as two external images. One as the actual level art and the other is a black and White collision map. Now I've currently got a little guy being able to jump around on the ground but no Walls. I'm at a loss to how to do this but I thought of something. Is there something that I can use to do this for me without coading a whole engine from scratch. Am I just doing extra work for what someone has Already done for me? How would I encorporate this into my project?
I might post some links to current versions later (posting on my iPod) and maybe make a dev log
Logged

EchoP
Level 0
**


View Profile Email
« Reply #1 on: October 24, 2009, 11:30:29 PM »

Flixel!
Logged
bateleur
Level 10
*****



View Profile
« Reply #2 on: October 25, 2009, 12:17:55 AM »

One trick that it sometimes useful with collision maps is to replace the black and white with colour, where the colour of each pixel describes what kind of thing it is. So the floor could be red and the walls green in the collision map, allowing you to handle them differently.
Logged

roboprez
Level 1
*


Got to love them pixels


View Profile WWW Email
« Reply #3 on: October 25, 2009, 12:55:25 AM »

Wrong URL and i'll need some help on how it's useful. Does it have the ability to have a collision map?

One trick that it sometimes useful with collision maps is to replace the black and white with colour, where the colour of each pixel describes what kind of thing it is. So the floor could be red and the walls green in the collision map, allowing you to handle them differently.
I may try this but I really do want the solidness to be one mass. I know it's possible and it will make it much easier for others to make levels.
Logged

Sam
Level 3
***



View Profile WWW
« Reply #4 on: October 25, 2009, 11:05:33 AM »

Afraid I can't offer much help, but I made a very simple platformer using a similar system to you.

I fed it a collision map like this:


and it used a tileset:


to produce a finished map you could jump around on.

I didn't do anything very clever to do it, just looping through the collision map using getPixel and populating a 2D array (I'd use a Vector instead now I know of them) to use for collision checking.  The tile to use at each location was determined by a simple examination of its neighbours.  Then a very ugly platformer physics engine stuck over the top.

Unfortunately it was one of the first things I made in Actionscript, and reading my source wouldn't help anyone.  Best of luck though Smiley
Logged
st33d
Guest
« Reply #5 on: October 25, 2009, 01:26:06 PM »

Creating a tile based engine and level editor is really crucial to speeding up game development. Otherwise, you get one little bug in a level and you have to redraw the whole thing.

You can get quite far using Box2D for collision, but it does get chuggy really quickly. I'm afraid that collision is a really deep subject that will haunt you for all of your time making games. Get it wrong and you could have a very unplayable game on your hands.
Logged
Drew
Level 0
***


Hooray


View Profile
« Reply #6 on: October 25, 2009, 09:36:30 PM »

I was using bitmask collision on my current flash/as3 game for a while and it wasn't too slow.  I was using a very low-res collision map, however.

You can use BitmapData.getColorBoundsRect.  Determine which area of the map the player might collide with, copy that portion of the collision map into a separate bitmapdata, and call getColorBoundsRect to see if any of the affected area is black or white or whatever.

Be sure to leave a 1px border around the bitmapdata object that you are calling getColorBoundsRect on, because there's a bug in Flash where it won't return a rectangle if the topleft corner is the only pixel that is the chosen color.

Here's a stripped down version of the code I was using. colTester is the BitmapData object that is used as the staging area, and caveMap is the collision map.

Code:
public function collide(rect:Rectangle) {
// convert the rectangle's extents to collision map coordinates
var startx = int(Math.max(rect.left/32, 0))
var starty = int(Math.max(rect.top/32, 0))
var endx = int(Math.min(rect.right/32, 256))
var endy = int(Math.min(rect.bottom/32, 256))

if(startx == endx && starty == endy) {
// No need to be fancy if it's a single pixel
var m = caveMap.getPixel(startx, starty);
if(m  == 0x00000000)
return true;
return false;
}

var src = new Rectangle(startx, starty, endx-startx+1, endy-starty+1);

colTester.fillRect(new Rectangle(0,0, 12, 12), 0xFFFFFFFF);

// Blit it at (1, 1), not (0,0) because of the bug
colTester.copyPixels(caveMap, src, new Point(1,1));

var r : Rectangle;

// Test for collision
r = colTester.getColorBoundsRect(0x00FFFFFF, 0x00000000);
if(r.width != 0) return true;

return false;
}
Logged
roboprez
Level 1
*


Got to love them pixels


View Profile WWW Email
« Reply #7 on: October 27, 2009, 01:43:54 AM »

@Drew
I'm not really quite sure what your doing with all the Rectangles...

Take Knytt as an example as to what I'm aiming for. If you've played around with the editor you'll obviously see that all solidness is just one clump of pixles. It can work out what's a wall or a floor/roof depending on the incline of pixels. Can someone point me to a tutorial/example of a platformer engine that can do this?
Logged

JLJac
Level 10
*****



View Profile
« Reply #8 on: October 27, 2009, 02:44:55 AM »

Are you going to want to have diagonal surfaces or just horizontal/vertical ones? In the latter case you could do like this:

Determine the smallest possible rectangle that contains both the last position and the current position of the object.

Repeat through all squares/pixels/tiles in this rectangle. If the square is not solid, do nothing, otherwise...

Determine the point where the straight line from the last position to the new position is crossing each of the four surfaces of the square, using the linear equation. If this point is on the surface of the square, then add it to an array. If it is hanging in the air outside of the square, do not add it to the array. When you save it to the array, remember to both save the coordinates and also which surface it is("left", "top" etc)

After doing this for all the positions in your check-rectangle, sort the array after the instances' distance to the last position of the object.

The instance that is closest to the last position is where the object has first hit the terrain, so make this coordinate its position. You can also know what kind of surface it is, because you saved that into each instance earlier. This is handy when flipping velocity vectors to make things bounce, or if you want to make a player object change some kind of mode parameter to "standing" if he is colliding with a "top" surface.

This is basically a simple raytracing, and it's bulletproof in the way that the object can move extremely fast, it will still collide with the thinnest walls instead of going through them. Doesn't support diagonal surfaces though.
Logged
roboprez
Level 1
*


Got to love them pixels


View Profile WWW Email
« Reply #9 on: October 27, 2009, 03:18:19 AM »

@JLJac
Unfortunately the Game NEEDS diagonal pixels. Prettly cool though, I might try implementing this another time another place...
Logged

dustin
Level 6
*


View Profile Email
« Reply #10 on: October 27, 2009, 08:15:20 AM »

If you don't want some of the more complicated things (like sliding down diagonal surfaces) this is what I'd do.  Pick four points on your charector then every frame test these four points with the scene.  If the bottom one hits move the charector up  until it stops hitting if the left one hits move it right etc.  It works pretty well.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic