Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / 2d Terrain???

Author
Message
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 19th Apr 2010 19:05
This thing about terrains is new to me, so im not pretty sure about how to make it.

I've seen some 3d terrains examples, but, the problem is that my game is in 2d, so i have no idea of how to make it work...

I want my main character or hero to follow the terrain and change its height with it... someone can give me an idea of how to make this? Thx
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 19th Apr 2010 19:17
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 24th Apr 2010 04:35 Edited at: 24th Apr 2010 05:09
Ok, very useful example, just a question...

When i add it to my game, do i have to change something depending on my game? or is it like all done there?

like, idk, the sprites sizes, images, that kind of things.
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 24th Apr 2010 05:16
The collision function works off transparency. So just make sure that the ground is a seperate sprite from any background effects, and that the "sky" is transparent for that sprite.

Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 24th Apr 2010 05:36
mmm... What do u mean with, "and that the "Sky" is transparent for that sprite"?

If it helps, there r 3 "Backgrounds" in my "Level", the blue background, the mountains, and the beach, and terrain which is the sand of the beach, they r all in different sprite priorities, those that affect something?
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 24th Apr 2010 05:45
Argh, this is surprisingly hard to explain . The terrain image, the sand in your case, cannot be completely opaque, otherwise the character would just walk on top of it like a box. Anything above the contour of the sand needs to be transparent for that one sprite. You can have as many background sprites behind it as you want.

Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 24th Apr 2010 05:56
How would u make to choose which images u want to use in the function
for the collision from outside of the function, like... without having to change the function itself?
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 24th Apr 2010 06:08
If you look at the code, you can see that when you call pixelcol, you put in two sprites. Put the sprites for the player and the terrain you want him to walk on in there. Easy as that .

Basically all that code is doing is making the player fall unless he's in contact with the ground image.

Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 24th Apr 2010 06:19
This is weird, the code seems like it should work... but it isnt for me, hey, do u think u could make a short example of how to put it and use it in a game, that would be great!

(As u can see, i give a good use to the "Noob" part of the forum XD"
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 24th Apr 2010 06:30
It's actually really simple, you just have to know how it works.

The pixelcol function is just a collision function. It returns 1 if any part of the two sprites you specify is touching the other.

It can't get much simpler, but check this out:


Really, you can just copy-paste that into your loop, add the function to the end, and replace sprites 1 and 2 with your own sprites.

Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 25th Apr 2010 21:55
Ok, im working on it.

But I have a question, if one of my sprites is making collision with the terrain, and i "hide" the sprite, is it still in collision with it? or do i have to "Delete" the sprite to stop its collision with the terrain? ty
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 25th Apr 2010 22:33
Hiding will not stop the pixel-perfect collision from detecting hits.

Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 25th Apr 2010 22:42
ohhhh.... that explains allot XD
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 26th Apr 2010 01:41
mmm... the function loads a little, is there anything i can do to make it work faster???
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 26th Apr 2010 02:16
I'm sure Cloggy optomised it as much as he could.

Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 26th Apr 2010 03:18
Ok... ill try to put it in a way it doesnt seem to load
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 26th Apr 2010 07:45
This is the image im using as the terrain, does Coggly's collision function is made for this kind of platform???

Attachments

Login to view attachments
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 26th Apr 2010 16:50
Yep, that's exactly what you want.

Login to post a reply

Server time is: 2024-11-23 17:03:41
Your offset time is: 2024-11-23 17:03:41