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 / Scrolling Methods

Author
Message
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 9th Apr 2011 01:25
Sprite is tricky because it is somewhat of an automatic process. I don't use the sprite statement the way it may probably be intended for and sometimes I don't use it at all as long as I can get away with a simple paste image.

Once the sprite statement is called it will automatically activate every sync so that renders your AreaCheck useless because the last coordinates you set for that sprite when it was determined to be inside the screen will remain the same whether you call the sprite statement or not. This is why after scrolling and the mob is outside the AreaCheck the mob sprite still lingers in the screen. If you're using something automatic like sprite then there's no point in using an AreaCheck but you will need one if you manually paste the mob sprite.

Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 9th Apr 2011 02:43
This is an example of an alternative pasting method. It has some other element in there like AI and use of Bitmaps (refering to drawing surfaces, not the .bmp).


Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 9th Apr 2011 12:54 Edited at: 9th Apr 2011 13:07
So do i now have to scrap the pasting method i have used so far for the players character?
Because that looks like a player character control and not a mob control system. I see the different way of pasting down but its a whole new concept that i will have to learn now and just looking at the code it looks too difficult i dont know what is meant to be what.
What i was stuck with initially is the mob seems to be pasting down fine but moves along with the screen wrong. Now checkx and checky are working in the intial paste down but they are no world co-ordinates, i cant see how you can paste down the mob at -1000, -400 as this would be off the screen. It kind of works but doesnt work and shouldnt work. So where are the world co ordinates. If i cant paste these down i wont be able to paste a rock down, or a tree, let alone start working on collision. i am getting as frustrated with the concepts of this as much as people have grown frustrated with me (i am sure everyone is screaming into their monitors "its because of X you stupid C' how can you not see that". Are there videos of things like what im asking for (or does someone want to help make one, to demonstrate what is happening, because i respond very well to audio and visual but cant read at all. Hence why fiction books are useless to me, if you describe a tree no matter how good you describe it i only get a limited image in my head (that part of my brain is knackered) or you describe a main character in detail i just dont see what other people see, show me in a film though and all the work is done so i immediately see everything that needs to be seen, even though i could not describe it myself afterwards in any detail.) Pictures are very good too.

Unfortunatley i think from the amount of people who have stopped helping on this thread means i have worn everybodys patience thin in my quest for understanding so i am going to leave this for now. It seems that even DB pro is a little too complex for me but what annoys me is its not meant to be and i absolutely flew through the first month only to find there are a hundred ways of doing anything above the absolute beginner stuff in dbpro but none of them work for the absolute beginner who wont have the advanced knowlegde taken from other languages to help them overcome a problem and create a solution.
I will concentrate on other small things for now but will be very disappointed if all DB is good for is small demos. Thanks everyone for your help and hopefully i can revisit this once i get some more experience but i really dont know where else to go from here as everything below it is just too easy for me, everything above i just dont seem to get.
Lost Dragon
14
Years of Service
User Offline
Joined: 22nd Aug 2010
Location:
Posted: 9th Apr 2011 23:01
You got to the hard part but you're still about a third of the way there. Don't give up now!

Make a post with everything you've got so far (graphics, etc.) zipped up and I'll have a look too.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 10th Apr 2011 01:21
@Somarl
Didn't mean to confuse you, I was just showing your a different approach with some new elements. You dont necessarily have to swap over to it. That method was to grab the images individually and use it manually without the sprite statement. Also wanted to show that you can make mobs out of the same arrays as the character. See how aside from the "Player" controlled one the others act as npcs.


Aside from that alternative method what you can use are these statements:
DRAW SPRITES MANUAL stops sprites from being drawn automatically so when you gain more control over when you want to draw it.
DRAW SPRITES. This force a manual drawing of sprites place it right before a Sync statement, this is used in conjunction with the above statement.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 10th Apr 2011 14:26
Thanks for the support guys. my posts might come across as being a little ungrateful sometimes but nothing is farther from the truth, i just get very frustrated with myself for not understanding things when i have put so much work and effort into trying.
@Ashingda, no worries about the confusion, i just thought i was doing it wrong somehow and went on a bit of a mad one wondering what i had done wrong because i couldnt get the mob to show up properly. The draw sprites manual command is something i dont think i have encountered in any tutorials i have come across yet, or the 'hands on' book that i bought so i will look into that.

Here is everything i have so far :




All i am trying to acheive at the moment is the following.

1) Make mobs appear wherever i place them using some sort of world co ordinate system so that i can just say 'Place an ogre at 1350, 200, place a dragon at 1800, 550' etc.

2) Then make them move or take a path that will determine where they end up on the map and when the player sees them it will be wherever the mob is on the path at the time and not have them only start their path once the player gets there.

3) Have some sort of collision worked out so i can place down rocks and trees as sprites and possibly create some sort of attack system when it comes to enemies or an interaction system when it comes to npcs and world placed objects.

Attachments

Login to view attachments
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 10th Apr 2011 16:52 Edited at: 10th Apr 2011 16:52
You can disable the AreaCheck for the Mob sprite. It's mainly used to control a manually drawn process like PASTE SPRITE or PASTE IMAGE so unless you're using those, You may try to REM the AreaCheck out for now, it should immediately fix your mob sprite being drawn in the wrong spot.


This is the paste sprite method used with the AreaCheck. The trick is you place the actual sprite outside the screen so you do not see it. Then you paste it to the screen when ever you want it drawn.


To get rid of the "white" background on the mob sprite there's two ways to go about it.
1) Set your Set Image Colorkey 255, 255, 255 so when loading the sprite image "white" turns transparent.
2) Use the mob sprite version with already transparent background. I'm sure the first one posted for you was a png format with transparent background.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 10th Apr 2011 17:20 Edited at: 10th Apr 2011 17:36
This works great. So basically whats happening is the mob is being set up to be literally just off the screen with Sprite 2, 1024, 768, and because of the checkX (and Y) equation that lets it know its world position, using paste sprite will keep it centered where it is. Thats great. I tested the example by placing multiple mobs all over the place, some of them so that there would be more than one on screen at any one time and it worked perfectly along with the scroll.

Would moving them along a path now just be a case of setting up a seperate function to deal with the path of each mob so they patrol by incrementing there worldx and worldy (may as well just make these x and y actually i just thought i would need a global one to place then a local one when they are pasted) So keep the mobhandle which could actually be changed to checkmobdisplay, and mobhandle should be something that increments and decrements x and y values creating a sort of "path".
I dont really know how to handle AI at the moment as i havent done anything like it.

Also i am not getting any problems displaying the mobs or any white backgrounds so far. The main character at the moment is a transparently drawn png (this was just because i took it from Rich's example) but the other characters are all bmps with a brown background from the reiners tileset site. I will just use all of them for now as i cant draw at all just yet and it would be nice to lay down a simple game using these just for concept. Also i will have to use bmps as mentioned before as there is a problem with pixel perfect sprite collision and pngs using the eXtends plugin so its bmps only (hence i will have to change the main character back to a bmp before long).

Thanks.

Edit: This is how far i got making a path, its not ideal as i am not sure how to control the speed (maybe add more variables?) and not too sure about diagonals or even throwing in some checks for collisions yet(but im not up to that. This works but i cant help thinking better ways can be made.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 10th Apr 2011 18:14 Edited at: 10th Apr 2011 18:23
I wouldn't recommend a pixel perfect sprite collision as it's not very accurate and may be slower. When checking collision you want to use a method that has as few process as you can and still returns a more accurate reading.

I've mention a radius collision, where you check two coordinates to see if they are close enough to be considered colliding or not.
Pros: This works well with checking mobs, npc and other characters. Gives an accurate reading.
Cons: If the amount of mob/npc/character are high it'll slow down because each of these will check the others and vise versa.
Alt: There is a way to speed this up in conjunction with Array collision so you can have lots of mob/npc/character without slowdowns.

Array collision, simply check the terrain data to see if the tile is passable or not. This works well with the terrain because there will be LOTS of rocks/trees/etc and wont slow it down.
Pros: This is a very fast and stable check because you'll check the array one time for every mob/npc/player.
Cons: The collision values are fixed, if you have a tile of a very thin pole or a whole tree, the distance that the player is limited to is the same.
Alt You can use this in conjunction with Pixel collision and/or other collision methods to get a more accurate limit distance.



Attachments

Login to view attachments
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 10th Apr 2011 19:18
You have no idea how much that picture helped me understand the post, as i said i am very visual
Right, initially i was going to go off what i had learned from this thread:

http://forum.thegamecreators.com/?m=forum_view&t=182883&b=7

but this is perhaps not the best way to do it then? Also as i mentioned before what i was planning on doing was making sprites out of rocks and trees, buildings, walls etc, anything static but not passable and only using the map array for the ground textures but this is not the best way. As you said in your post the cons to an array check against the map would be that a small rock on a large tile would return a rather horrible bounding box collision that would be no-where near where the player was in accordance to the object. Same goes for other things.
Looking at the diagram it seems pixel collision could cause problems as although it would be accruate in accrodance to pixels (that demo in the link is spot on) it would not work very well with objects like trees as your diagram suggests (its no good not being able to stand behind it for example), radius collision looks like it could be the best option, so would it be a case of doing an array check first, then followed by a radius check if the player was too close (within that boundary?).
This leads me to another couple of questions. How would i get the player pasted behind something like part of a wall or tree (like in the radius coliison diagram) if the tile is pasted down on the map, i cant think of a way this would be possible at all.
Second how can i tell what tile the character is currently stood on therefore check against being next to (or even on top of) a tile number that would defined somehow as being not passable or interactable.

Or have i misread this a little and you are suggesting a sprite for rocks and trees and pasting them down but not using pixel perfect sprite collision, instead only array checking then radius (because this way i could see how the player might be able to go "behind" a tree).
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 10th Apr 2011 21:04 Edited at: 10th Apr 2011 21:04
Quote: "so would it be a case of doing an array check first, then followed by a radius check if the player was too close (within that boundary?)"

You caught on surprisingly fast on this one, you really are a visual type. Yes it will be a two step precess, check the array to see if anything is there, if it's a mob/npc/char then run a radius check. Makes only two checks (2 x MaxChars) as appose to (MaxChars x MaxChars).



Quote: "This leads me to another couple of questions. How would i get the player pasted behind something like part of a wall or tree (like in the radius coliison diagram) if the tile is pasted down on the map, i cant think of a way this would be possible at all. "

You set a priority for what to draw first. If the Character's Y coordinate values are smaller than the tree, you draw the character first. There's a method to queue everything you draw and re-arrange the order that it's drawn in based on it's Y coordinate. It uses a sort algorithm, would be a good time for you to pick up that skill as well because you can use it in many other applications.

Quote: "Also as i mentioned before what i was planning on doing was making sprites out of rocks and trees, buildings, walls etc, anything static but not passable and only using the map array for the ground textures"

That works out much better than you'd think. You can have multiple Map(array) to hold different data. When you dimension the Map(array) you give it 2 dimensions used for coordinates x and y. You can give it a 3rd to be used as different layers of the terrain.


Attachments

Login to view attachments
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 11th Apr 2011 00:31
Interesting. So adding a 3rd dimension to the array i can now create an order in which to draw things. The Z axis so to speak.

Quote: "Makes only two checks (2 x MaxChars) as appose to (MaxChars x MaxChars)."

Could you just explain that a little more. If i am only using a 3d array for x, y co-oridnate and z order, how will i check the array against something pasted on it. What i mean is how does the map know something is there, like a rock.

----------------------------------
An array might go something like this in that above picture:
Map(2,2,2) - Would be grass just drawn on a tile (like Map(0,0,2) for example as well)

Map(3,7,1) which would draw the rock

Map(3,7,0) which would add collision to the rock.
-------------------------------------

I have dealt with sorting algorithms on arrays before but did not fully understand them though i could do with learning them as they will be invaluable in the future as well as for this project but dont know where to start, i read some info on it and did a few small demos to sort averages, and sort large to small but like i say didnt fully get them (though i suppose revisiting them wont hurt).

-------------------------------------

So now using Draw Sprites Manual in conjunction with a check to see if the sprites y co-ordinate is greater than the characters then positions it on top.
I think i am beginning to understand a little but definately need more info on how to put all of this together in code. I am beginning to 'see' what i need to do, but its a little daunting putting it together into either a function or loop.

I know the pics are a pain in the butt but they do help enormously so thanks for taking the time.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 11th Apr 2011 02:15 Edited at: 11th Apr 2011 02:15
Quote: "how will i check the array against something pasted on it. What i mean is how does the map know something is there, like a rock."

The rock data should already be in the array and you just check that. You can draw out the terrain objects like the rocks/trees similar to how you already draw your terrain. Just loop through the Map(array) that stores the object data and paste sprite from there.


How to know which array location to check based on a mob/npc/char you take their coordinates and divide by the tilesize.


Attachments

Login to view attachments
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 11th Apr 2011 02:29 Edited at: 11th Apr 2011 02:30
You also need to start centering your sprite onto it's coordinates.
The character sprite frames are 64x64 so this will offset the center of the coordinates to 32,36 right at the bottom of the character's foot. You can change the y offset to suite your taste.



Attachments

Login to view attachments
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 11th Apr 2011 10:17
Excellent stuff Ashingda. Without this i would never figure it out on my own. Simple things like offsetting the sprite by his feet location, just seeing the image makes it click. I would have just offset it dead centre then started scratching my head as to why it doesnt feel right. This is spot on. Going to have a play after work tonight, see what i can come up with in regards to pasting down some rocks and trees etc.
So basically i should paste down the rocks/trees etc (as transparent pngs) in the same method as i did the tiles from the map array. But this time using that 3rd dimension to make it paste on top of the already existing floor tile.

Using the image, i am still pasting rocks and trees etc as sprites (and some of them may still go over 2 tiles) but creating a "foot" offset for them where the base of them are to be placed, then using an array grid to find the location (and move them along when the player is moving), the 3rd dimension to determine the draw order

Attachments

Login to view attachments
Lost Dragon
14
Years of Service
User Offline
Joined: 22nd Aug 2010
Location:
Posted: 11th Apr 2011 22:49
Wow. I think you guys read the forums more often than I do. Sorry I'm slow, but at least you are not stuck anymore.
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 11th Apr 2011 22:52
Lol im stuck on plenty at the moment trust me
Frank C
14
Years of Service
User Offline
Joined: 3rd Jul 2010
Location: Houston TX
Posted: 11th Apr 2011 23:17
I just started reading into this thread more, been real busy at work. I have also been creating my own tile based RPG.

As far as using muti-dimension arrays for maps what I use is actually multi-layers, I have a map UDT's with multiple variables covering various features


I also use tilefringe, and tileobject, the fringe layer will cover trees, rocks, etc. any landscape items. The object layer will cover treasure chests potions or any other incidentals.
I use the following for my map tiles:

type maptile
baseLayer as tilebase
fringeLayer as tilefringe
objectLayer as tileObject
`enemyLayer as Enemy
endtype

this allows me to do the following when displaying my map:

paste sprite Map(tileX,tileY).baseLayer.tile,xposition,yposition
paste sprite Map(tileX,tileY).fringeLayer.tile,xposition,yposition

I have also created code to spawn random mobs at random locations, what I am currently working on is AI code to get the random mobs to detect the player when within a certain range (LOS) and then follow till it loses player or an attack occurs.

I am currently using simple sprites since I have no Graphics skill. I have picked up some tidbits from this conversation and will try to keep up and provide some rhetoric where I can.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 11th Apr 2011 23:31 Edited at: 11th Apr 2011 23:32
Some people prefer to use UDT while some don't. I personally don't use it because I find it to be too long . I try to shorten down variable names as much as possible, just my preference.

I like to just use a 3rd dimension so I can just run a simple for-next loop for it.


Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 12th Apr 2011 09:35
So how do i use the 3rd dimension. Starting with the read statement.

I cant use:
For y = 0 To MaxmapsizeY - 1
For x = 0 To MaxmapsizeX - 1
Read Map(x,y,z)
Next x
Next y
Or even adding a For z = 0 To 2 or whatever. How do i use this properly, and what is the appropriate data to store in the z axis, how do i find out if i want 0, 1, or 2 stored at that location. Is this info still based on using mappy? Is this based on using just a ground texture and pasting pngs over the top on a new layer?
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 14th Apr 2011 15:54
Going to have to give up on this and take a step back for a while because there is still a little bit too much that i dont understand and i am honestly getting no-where. My first 4 weeks i flew through and now 6 weeks after those first 4 are so slow i dont feel like i am doing anything at all. I need a better core understanding of a few concepts first before trying to learn through making a game, thats obvious in the fact that i ask about 2-6 questions per post and i still dont come up with much new working code. So to save the frustration i am going to take a step back and see if i can get a better grasp on things first before returning and having another go on this 2d business.

Only thing is i dont know where to start. I dont need absolute beginner stuff anymore, yet most of the beginner and beginner to intermediate stuff (tutorials) presumes far too much of me. I still need teaching in the same way as i did the absolute beginner stuff rather than a presumptuous "right youve got this far so you will know how to do this exactly", so its ruling out some of the stuff im finding on the net so far. Does anyone have a place i could go to, to get slightly above beginner tutorials but one that still treats the learner as a complete noob? Because thats what i need to get over this tough spot so i can come back to this renewed and get it working the way i want to.

The hands on books are great but when your finished its nothing more than a reference book at heart and it doesnt leave you with the confidence to make a game, or expand on anything worthwhile in the book.

Thanks for everyones help so far. I hope to revisit this sooner rather than later and actually work on a game which i have plenty of time for at the moment, i just dont know how.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 14th Apr 2011 21:18
From this point on it's really all on you. This is when you figure out how to do things on your own because there are thousands of different ways to do the same thing. Keep in mind that this is a language and you're telling the machine what to do, very similar to telling or teaching another person how or what to do. Take it one step at a time and don't rush.

Frank C
14
Years of Service
User Offline
Joined: 3rd Jul 2010
Location: Houston TX
Posted: 14th Apr 2011 23:26
You will need hands on practice at writing code, doesn't matter if it works, if it doesn't you learned something and when you get it to work you've learned more. Use the search feature in the forums heavily, you can search on something your trying to do like 'sprites', 'tile maps', 'scrolling', etc... Then you read through what others have done and piece together what you need. It can be a slow arduous task but worthwhile in the end.
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 16th Apr 2011 01:58
I agree. I am going to start the second hands on book tomorrow morning and even though its 3d (which i thought i would leave alone for a while) i hope i will learn enough to keep going back to things i previously didnt understand and begin to grasp them.

Keep an eye out for a sequel to this thread

Hopefully.

Login to post a reply

Server time is: 2024-11-22 23:30:29
Your offset time is: 2024-11-22 23:30:29