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: 4th Apr 2011 00:45
Quote: "This must slow the game down when it gets much bigger surely? "

Yes drawing too many tile WILL slow the program down but there are techniques that speeds it up greatly. I'm talking if your max fps while doing nothing but displaying the fps rate on the screen is 1000, when drawing out the map alone will only bring it down to about 800~900 or so. Compare to the methods up til now which would probly drop a 1000 to a 150 fps or even worst.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 4th Apr 2011 01:20
Thats why i think i am going to drop the 3d tiling plane. That and the line issue i spoke of earlier. Just trying to figure out a way to block, not even sure if i should leave out trees and rocks and draw them as seperate sprites and have pixel perfect collision on them using that eXtends demo. If i drew the bmps of rocks and trees i think i could do it. So only use the tiles and map array for drawing the floor. All other things such as buildings, rocks, trees, ruins, fences ect would be sprites. Not sure if this is right and i still cant seem to display anything other than the player just yet (no other sprites will show up so i am missing something in the code or not using the co-ordinates properly).
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 4th Apr 2011 01:40
Quote: " I tried checking everything to find out the tile the character is on"


What I did was use the PICK OBJECT command, like this...



That returns the closest object to the location of the player sprite. But, if you are going to change to something besides the 3D planes, this is useless.

I've not played around with pixel collision and eXtends.

Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 4th Apr 2011 01:50
As for sprites, I have a few tricks I use with it to optimize the speed and to get the effect I want. I can show you as we go along.

It seems you are currently aiming for a free movement scrolling method, why didn't you say so from the start? But anyways the previous methods needed to be ran through to better understand this one.

The last example with the smooth scrolling I post can be used for free movement. All we got to do is get rid of the way it is limiting the scrolling and have the arrowkeys control the scrolling values directly.


Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 4th Apr 2011 09:48
Quote: "That returns the closest object to the location of the player sprite. But, if you are going to change to something besides the 3D planes, this is useless. "

I did not even know that command existed. And i wouldnt have thought it did what it sounds like.
I really need to read more of the Hands On Volume 2 as that probably has that command in there.
I am not too sure about the planes idea as i cant get it to stop those fine lines on everything. Its only not noticable where many of the same tile is used. As soon as you paste a tree or rock down its there. I wouldnt know how to fix it.

I asked about sprite collision in this thread http://forum.thegamecreators.com/?m=forum_view&t=182883&b=7 and was going to try and adapt it somehow as im not sure there is a better solution than this.

If i used the 3d plane method, would it be worth creating 3d objects, like houses and placing them on ground tiles? So just using the tiles for things like everything floor based, grass, water. Then building a load of 3d houses (i cant draw 3d models very well but i could do a lot of crappy ones very quickly to at least demo for now) and placing them down on the planes. I still havent found a way to place a second sprite down. what i have tried so far does not show up.

I placed this in the setup gosub.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 4th Apr 2011 14:55 Edited at: 4th Apr 2011 14:58
You should try to keep it simple as this is your first attempt, if you're doing 2d then stick to 2d and if you're going 3d then go full 3d. The two sets of command don't really work well with each other as drawing priority becomes an issue.

This is free movement with the character sprite at the center. When scrolling, the character will turn and face the direction. I rearranged the character sprite so you may want to download it here too. You can animate it by cycling through the frames but I'll leave that part up to you for now.



Attachments

Login to view attachments
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 4th Apr 2011 16:07 Edited at: 4th Apr 2011 16:13
Quote: "You should try to keep it simple as this is your first attempt, if you're doing 2d then stick to 2d and if you're going 3d then go full 3d."


Probably some very good advice!

I'm going to keep playing with the 3D version though, adapting it for a game I'm working on.

I finally figured out how to get rid of those grid lines, just one simple command - SET OBJECT TEXTURE.



Attachments

Login to view attachments
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 4th Apr 2011 18:04
Im torn between the two ideas and not sure about either as i dont know enough about either one to decide what i want to do. I do want to do more 3d stuff down the line, in fact the reason i got into this in the first place is to make 3d fps style rpgs so i dont know if its worth trying to learn that straight out by sticking with 3d for now. Its just the 2d methods are meant to be more simple (but i dont know just yet as i am struggling) and i have more assets for a simple 2d environment. I thought i should be learning 2d first before moving onto 3d to ease myself into it better when i come to doing it but honestly i dont know as i am struggling with pretty much everything 2d and 3d based.
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 4th Apr 2011 18:52
Yah, sticking with 2D for now will let you move forward faster.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 4th Apr 2011 20:25
So you think i should stick with 2D for now and maybe move onto 3D at a later time. Thats what i was thinking. Being that i havent done any programming i need to know how games work in general i think before going on to bigger things. Thanks for the advice.

Is the best way to do collision then, still to do it by tiles? So like the tree tiles and rock tiles all being impassable etc, or is there a better way so the boundaries are less square. If i use a second level in mappy i can place (i think) images that are in a tile but have a mask, over the other tiles like grass. So this would work nice for trees and rocks i guess as they would then have collision set on the object but i would have no idea how it knows that the rock is there and not to go over it.
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 4th Apr 2011 23:16 Edited at: 4th Apr 2011 23:17
If you are going to use pixel perfect sprite collision, then you could make all your trees, rocks, etc. out of sprites. They would all have to scroll with the background, of course, and any mobs would have to move on their own.

But... as I've said before, you REALLY need to make some hard decisions about screen size, viewport size, tile size, etc. BEFORE you start coding, because these things affect the performance of whatever way you decide to do, 2D, 3D, 2.5D.

So... 32x32 tiles? 64x64 tiles? You've mentioned that you might like to use 64x64, as it fits better with the PC and NPC sprites you can find on the interwebs.

Screen size? And how much is going to be GUI vs visible map?

I like the idea of pixel collisions determining if objects block the player, it's probably easier than checking a grid.

Imagine this... for each "area" or "island" or "zone", you have one big sprite that is the "background" image, and one big sprite (the same size) that is the "foreground", composed of trees, rocks, fences, etc. I don't know how big of a sprite you could make that way, but it would be interesting to find out.

Lost Dragon
14
Years of Service
User Offline
Joined: 22nd Aug 2010
Location:
Posted: 4th Apr 2011 23:46 Edited at: 4th Apr 2011 23:48
Rich you mentioned UDT before.

I have a tile engine that I've been working on and one of the problems I have come across in building maps is that I don't have a good way to associate data with tiles.

So in a map data field of:

1,1,1,1,1
2,2,1,1,3
2,1,1,1,1
1,1,3,1,1

Where 1 is grass and 2 is sand and 3 is a signpost, I don't really have a good way to tell one signpost from another.

One sign might say "Bob's Blacksmith" and the other might say "Woody's Carpentry" but all I have is a location and a graphic. It seems really inefficient to search for what text to put on the sign by location and I don't really want to have to draw a different graphic for each sign.

I know there is a way to solve this elegantly and I think that it involves UDT but what I don't know is how to represent that on the map data.

I can read several layers of map data so I guess I could make a layer that had indexes for "object type" and then check against that if a player tried to read a sign...

I have a sort of Ultima 4-ish game if it helps you visualize what I'm doing.
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 5th Apr 2011 01:20
1) I think that adding the objects that cannot be walked on or the objects that can be interacted with (like chests and so on) should be sprites overlaid onto walkable tiles made by the map editor but as i mentioned before this is what i was having trouble with. I cant even paste down the location of a mob, let alone a rock. The mob wasnt there when i posted his world co-ordinates. I wouldnt have a clue how to scroll them along with the map, as i just cant imagine how its done, plus dont they need to be 'not' displayed until the player is close to save on resources in a big game. How does it know the player is close or that the sprite just might cross the players path if its moving.

2) If i wanted to make a game that had the option to let the player change his screen resolution in the menu would this be possible. So to code it to start with a simple screen res but that could be increased or decreased in a menu based on what screen resolutions there are available (using perform checklist command) because i was hoping to give the player a little more freedom but if this would mess around with things like the co-ordinates how would one get around it.

So 2 questions there really. How to do custom screen resolutions without affecting anything in a negative manner. And moving sprites with the map (and displaying them in the first place)
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 5th Apr 2011 01:47 Edited at: 5th Apr 2011 01:47
1) While drawing or handling ALL object, simply make a coordinate check to see if the object is withing the screen resolution. Remember this? "If MapX > 0 And MapX < 31 And MapY > 0 AND MapY < 15" You do the exact same thing but check the object x,y against the screen size 0~800 and 0~600. If it's not within the bounds then just don't draw it.

2) Not really a good idea to customize screen resolution. You can have a set of resolutions for them to pick from but free resolution setting won't work out too well. How many games do you actually see that allows this, is cause it's not practical.

If you change screen size then you can just simply increase the amount needed to draw the map and re-arrange your gui "Which you dont have up yet".

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 5th Apr 2011 02:09 Edited at: 5th Apr 2011 02:14
1) Thanks. I will give that a little test to see if i can get someone to show up. So basically i add a world x and y co-ordinate to an object then a check to see if its within the screen size? The only problem i can see with this is its going to suck bigtime in visualising the map when placing down things like rocks, as most of it will be guesswork followed by lots of tweeking.

2) As far as changing the screen res size this is not advisable then. Thats ok but i still want it fullscreen and my monitor is huge (24" at 16:10), yet most people wouldnt be able to use that so i presumably have to settle on a universal resolution and just make it fullscreen and base everything round that yes? I mean i have seen options for adjusting the screen resolution in near enough every single game i have played in the past 10 years or so but they have been mainly 3d games when i think about it so is it really only a feasable option for 3d games in general or is it a darkbasic limitation.


Edit to point 1)
I am having difficulty even pasting down a sprite full stop here let alone with some sort of boundary check. It just wont paste down with something as simple as

And also not with even bigger co-ordinates which would place it away from the initial starting place.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 5th Apr 2011 02:32
What I mean by free resolution is that the player would be able to choose some crazy number like 1283x298 randomly. You can make any resolution you desire you just have to support it with your codes.

Like I said
Quote: "If you change screen size then you can just simply increase the amount needed to draw the map and re-arrange your gui "Which you dont have up yet"."
Ignore the gui part.


As for collision, I personally don't use "Sprite Collision" or any other auto collision method while doing 2d because it's harder to get an effective result. Different methods of collision works better depending on what kind of game you're making. In your case I'd recommend a radius check collision. This check two coordinates and find out if it's close enough to be considered touching. I didn't have time to put remarks on a lot of things, ask if confused.


Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 5th Apr 2011 02:59
Just want you to note that you only pasted your original comment in the code snipptet section rather than the code

Do you have any idea why i was unable to get a second sprite to show up (the player shows up fine, the mob doesnt). I cant think what i did wrong. I cant seem to make the other mobs have a co-ordinate and then make them show up. Just pasting him at random co-ordinates on or off screen just doesnt matter, it never shows up, yet the player (pasted using the same code just different co-ordinates) shows up (and animates) just fine. Is it pasting it behind the tileset? If so why isnt it doing this with the player, i thought the tileset was the background.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 5th Apr 2011 03:39
Sorry about the blunder LOL, here's the collision codes.


As for the sprites, how are you doing it? If you can get one character onto the screen it's as easy as doing it again to put another. Make sure you add the Scrolling variables to the mob's x,y values.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 5th Apr 2011 09:39
Ill check that code out when i finish work, thanks.

Quote: "Make sure you add the Scrolling variables to the mob's x,y values.
"


1) So by this you mean i need world co ordinates, to fit them in on the map, then another set of x, y's as an offset or something to scroll them against?

2) Also would a UDT work for this as i was thinking, what if i had several maps that i was trying to stitch together to make a large world. On top of the 2 sets of co-ordinates, a mob would also need a map label like Orc(6).MapN = 3 or something to denote what map he was on or what?

3) As for the character, i still cant get him to show up but have used almost the exact same code (except sprite number, image number to load the animated sprite from, and x and y co-ordinates) and hes not showing up so i am definately doing something wrong but cant figure it out.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 5th Apr 2011 10:41
Quote: "I can read several layers of map data so I guess I could make a layer that had indexes for "object type" and then check against that if a player tried to read a sign... "


I'm not Rich but you could add a check to see if the bottom layer has a 3 then load up the second layer right above it for the sign number to show the right sign. You can use a 1D array for all the sign text.

Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 5th Apr 2011 10:46
1) You can use the existing ScrollMapX ScrollMapY or related variable, just when you check or draw the mob/objects you do something like "X = MobX(m)-ScrollMapX*32".

2) You can dim your arrays to fit multiple maps. Use a 3rd dimension in your map array like DIM Map(60,60,5). The 5 means there are 6 different maps and the 60x60 works the same way you've already been using.

3) Show your codes. You should run a routine or function to update your sprite.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 5th Apr 2011 13:05
Thank you. I will test tonight when i get home to see if my other sprite is being updated, if i think he is but still cant get it working i will post up some code.

In response to point 1) What would happen in regards to where a mob may end up on a path. For example if the player moved south and a mob was south and east and moved from east to west. He would not be drawn because he would not be there when the player was south but eventually should be as his path would make him walk into the players screen. Basically how would the computer know to not bother with the mob (so as to increase speed so its not constantly updating everyone), but to bother with him if his path possibly comes in contact with the player screen. I am having a hard time getting my head round what would be happening. I may be able to describe this better in a diagram, and i would probably learn better from a diagram if anyone could be kind enough to draw one.

Many thanks.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 5th Apr 2011 19:29
This thing here "If MapX > 0 And MapX < 31 And MapY > 0 AND MapY < 15" is called an Area Check. It is a very basic way to check if a single set of coordinates are inside a boxed area. This is great for checking any boxed based collision.


Reply. 1) Use the AREA CHECK that I keep suggesting to you to see if the character is within the screen. In this example the subroutine loops through 10 mob coordinates and check if they are inside the screen, if so then do something.


Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 5th Apr 2011 20:22
Yeah i think i understand that, just make the mob do something if its within the area, but my original point was what if its not, then would be if the waypoint or path would normally cross the player where he is. For example see the picture, the player walks to this point on the map then stops, now technically he should see the mob briefly as he crosses into the player viewport (indicated by the red circles) but because the player stops the mob is never drawn and never works out where the mob would perhaps be. Or you have to update the x and y position for every single moving element in the whole game every loop in case its position would be where the player might see. Even if the player just stands there, if somethings path crosses the viewport then the player should see it. I hope my poor diagram explains this better.

Attachments

Login to view attachments
Lost Dragon
14
Years of Service
User Offline
Joined: 22nd Aug 2010
Location:
Posted: 5th Apr 2011 21:56 Edited at: 5th Apr 2011 22:03
Off the top of my head...

Instead of checking mobs within the viewport you could check for mobs within the viewport + x_distance_where x_distance covers 3 or 4 tiles outside the viewport on each side.

You'd probably want to make sure your check was still in bounds of the map array.

You could update all mobs when the player is occupied with certain activities (checking his backpack, talking to npcs, goes to sleep, etc.).

You could use a fast distance function to decide which mobs were going to be updated.

You could have a mob property called "activated" that any mob within a certain distance from the player would get. Then any "activated" mob would play out their canned moves (eg: sine wave) to completion, then get a "deactivated" property when the move was done.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 6th Apr 2011 00:17
You should update the mob's data every loop. There's no real reason not to as all that takes VERY little resource and is still blazing fast! Only real slowdown would be to draw too many sprites like over 100 or so.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 6th Apr 2011 00:46
Ahh right, this is good. So i can update the stats and positions and belongings and other deeds and states of all characters good or bad in a game at very little cost. Its only drawing them that takes up all the power? I was thinking of one day expanding it you see and making it very large, very full and very complex and wondered how it would cope. But if just changing many variables is okay then i think i might be able to roll my sleeves up and get stuck into the first part of this soon. Thanks.
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 6th Apr 2011 22:07 Edited at: 6th Apr 2011 22:34
Still not going so good im afraid. I cant get the other sprite to show up. I have tried pasting and just sprite command within a function that is in the game loop. Now the code is a bit messy to be posting and i know that would seem to be the root cause of it but to be honest if im saying paste sprite (or just sprite) within the game loop at globally variabled co-ordinates then i dont see why it wouldnt paste him down when it shows the player character.

Now i have a bit of a problem getting my head round the co-ordinates and i think its the reason hes not showing up. I pasted him a little away from the player characters co-ordinates so it should show up (i havent even been able to tackle checking for bounds yet, im just drawing him outright plain and simple). I am pasting him at co-ordinates based on the players and close enough to see on the first screen.

Id love to post code up but its a bit much. I think i will scrap what i have got and start again, trying to adapt the 3d scrolling map - which was working perfectly pasting the player down - is just not working.

Rich if you have used your examples and pasted any more mobs down i would love to see the code i really would. Just to see whats what. Oh and also i tried every single combination of numbers known to man on that Set Object Texture (or whatever it was) and it still came up with lines showing.

Many thanks.

Edit:



Using this code i am unsure of how to get more accurate speed scrolling as seen as scrollspeed cant be incremented in smaller steps. Maybe 2 is too fast but 1 is too slow etc.
Also i have no idea why it only displays what it does when its run. There doesnt seem to be anything obvious to me that makes it show more of the map at one time on the screen.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 7th Apr 2011 17:42
The scrollspeed# is re-set in this function, you need to remove this or set it here to take your new speed.


Look if you need help with codes just post what ever you got. I'm sure you're just missing a few simple steps to get it to work.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 7th Apr 2011 18:06 Edited at: 7th Apr 2011 18:07
Thanks Ashingda, and let me just say, without people like you, Grog, IanM, and Rich to name but a few of the folk who have helped me i would have given up on this long ago as its not something i can just stop and think about and magically work out for myself, at the moment i am not 'tuned' in to programming like that just yet (hopefully soon ) so once again big thanks.

I started again last night and was very surprised at how much i remembered and managed to do on my own with very little referencing to this thread. So far i have a very nice clean example and i am going to add some more tonight. I will undoubtebly need some help a little further down the line but i am hoping i can get at least the map scrolled on its own (so far i am reading in map data, displaying it and the sprite with full animated movement in the centre of the screen all very neatly) and possibly add a moving mob by either the end of tonight or tomorrow. Once i have done this sucessful or not i will post up my code and re-add a zip file with all the media to keep it neat. Watch this space
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 7th Apr 2011 20:42
Awesome, glad you're doing well. If you need to know any 2D tricks I'd most likely be able to help.

As for putting mobs onto the screen, you can try a different approach. Instead of using a different variable for mobs you can turn your already working character variables into an array such as CharX into CharX(10) and make a clone of your character. You can later change the sprite image of the extras to a mob and flag it as enemy so you can hit it. It may be an easier way to learn this process because you're looping and checking only 1 array rather than 2 different sets of variables or arrays.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 7th Apr 2011 22:35 Edited at: 7th Apr 2011 23:36


If like some help further understanding the above code if you would please. I am still currently trying to get my head round how the map scrolls and your earlier example (the one with the red box showing what was going on) was pretty much what i was looking for but there are a few things i am still a little unclear on. I have edit out a few things and added a debug function just to throw some text out but i would like it if you could perhaps review my comments and see what is what while explaining in a little more detail 'the maths' behind what is going on.

From what i can get the float is counting from 0.0 to 1 in steps of 0.1 and then moves the tiles over by 1 but there are some other things i cant quite follow. Mainly just in the display map part, not anything else (like i say, displaying the character, reading in the map, the tile numbers, displaying the map static is all well understood by now).

I know it has been explained a dozen times by now but i just need a little more, recently i have been exposed to so many different ways that i am still having troubles so i would appreciate a little more clarity and the above code has a few things that i dont need or arent needed so it seems, other things for example are PosX and Y always seem to be 320 no matter where you move but if you replace the numbers with 320 the map does not display properly, just little things like that.

Thanks.

Edit: After taking a look at the above, here is what i have so far, it doesnt work but im not sure why just yet.
Media Attached.

Attachments

Login to view attachments
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 8th Apr 2011 00:07 Edited at: 8th Apr 2011 00:34
Quote: "From what i can get the float is counting from 0.0 to 1 in steps of 0.1"

The floats ScrollMoveX# & Y# goes from 0.0 to (32.0 or -32.0) this is what directly effects the smooth scrolling. The values are 32 because that is the size of the Terrain tiles. Once the float reaches or surpass the value 32 then the ScrollMapX & Y integers are changed and the floats are returned to 0.


Quote: "PosX and Y always seem to be 320 no matter where you move but if you replace the numbers with 320 the map does not display properly, just little things like that.
"

You have to remember that the variables PosX and Y are just place holders or calulations for "Paste Image Tile, PosX+ScrollMoveX#, PosY+ScrollMoveY#". You can easily just use the calculations directly with the paste image statement "Paste Image Tile, (X *32 -32)+ScrollMoveX#, (Y *32 -32)+ScrollMoveY#". The reason why PosX and Y always turns out the same is because it's ran inside the X & Y loop so by the time you print it onto the screen PosX and Y will still be equal to the last calculation it was assigned inside the loop. This demonstrates that PosX and PosY will always end up the same with values of 11.



Quote: "If MapX > 0 And MapX < 60 And MapY > 0 AND MapY < 55 ` These numbers determine how much of the map eventually gets displayed which tbh we want all of it."

This is partially correct. This is an AreaCheck and it checks to make sure that we don't try to access the array with an out of bounce value. If MapX = -3 and MapY = -2 and we try to access the map array with those values "Tile = Map(MapX, MapY)" BAMM program crashes!

Now what directly determines how much of the map is drawn is the X and Y loop.
This loop is telling the process to check the tiles of the array from 0x0 to 11x11 of the Map() array. The AreaCheck then makes sure that while checking from 0 to 11 plus the offsets from the Scrolling variables doesn't make an out of bounce while checking the Map() array. If you change the value of the 11 in the X,Y loop you'll see it draw more or less tiles onto the screen.




[Edit]
Quote: "Tile = Map(x,y)"

Concerning your new code: You are not checking the right tiles while scrolling the map.

Quote: "MapX = x + ScrollMapX
MapY = y + ScrollMapY"

The MapX and MapY variables are assigned the values of x+ScrollMapX and x+ScrollMapY to shorten it down and to speed up process. Or else you can use the calculations directly:
The thing is, using a single variable for example like MapX from this example is a faster process compaired to always having to calculate x+ScrollMapX for every check and it's also shorter to keep it neat. I usually like to shorten it down more to just a single letter variable.

The terrain although shifts back and forth does not actually scroll because you are checking the exact same values in the Map() array over and over. Change the "Tile = Map(x,y)" to "Tile = Map(MapX,MapY)" and it should scroll properly.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 8th Apr 2011 00:44
Thats great. I get that now. In the case of my code PosX for example, is basically screen width(1024) / tilewidth(32) which works out at 32.
Then at the end of the for loop its X * 32 - 32(because of the last tile on the end, paste from there i.e 992) + scrollmove which will draw just off the screen if your going in that direction therefore appearing smooth by the time you get to it. Thats good.
Had a tinker with my code though and its still displaying very strange so i have something out of place somewhere. I beleive its possibly the line
If MapX > 0 And MapX < Screen Width() And MapY > 0 And MapY < Screen Height()
which is the area check. Now i know what this is for (you cant have an array going out of bounds or it will crash.) i understand what its for and i get what its for. How to make it work properly and working out what numbers its crunching and why its displaying the results its displaying if thats whats causing the problem with my code is unfortunatley beyond me right now. I really dont know enough about what exactly that line is doing to make it work otherwise i am sure it would be working right now.
All i can think of is i dont want it going to Map(-1, -1) and thats pretty much it. As long as that doesnt happen then the area check is doing its job and not going out of bounds. Or does the problem lie elsewhere with the code pasted above. Perhaps a global variable i missed or something trivial.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 8th Apr 2011 00:54 Edited at: 8th Apr 2011 01:02
If you DIM MAP(10,10) then you call a T=MAP(60,80), that's out of bounce too and the program also crash!


[Edit]
Quote: "If MapX > 0 And MapX < Screen Width() And MapY > 0 And MapY < Screen Height()"

Yes you are correct about this line. You're allowing the array to check up to Map(1024,768) when you only DIM Map(59,54). Will surely crash when you scroll Right or Down too far.



Hey if you're checking to find out if a character/mob is on the screen you can compare their coordinates in the AreaCheck with the screen width/height.

Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 8th Apr 2011 01:13 Edited at: 8th Apr 2011 01:14


This happens because you didn't draw an extra tile outside of the screen. Screen Width()/Tilesize = 32 and Screen Height()/Tilesize = 24 you need to add 1 point more for each of those to draw the extra set of tiles.

Remember the example with the red box acting as the screen edge.

Attachments

Login to view attachments
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 8th Apr 2011 09:40
I got to be honest with you, i tried that first as it made more sense to me to do that.
If MapX > 0 And MapX < Screen Width() / 32 And MapY > 0 And MapY < Screen Height() / 32
But when i tried it, it didnt work. The full code i pasted before was just the last thing that i tried.
Adding the above line in just causes the same jittering effect and wont draw the extra tiles. I really cant follow what my examply is doing and i have gone through it line by line. It makes sense to me but obviously not the computer. I will try checking elsewhere in my code, any other functions i have missed but so far i cant see why it:

1) wont draw the extra bit (i have added a 1 and a 32 to nearly every number i can find to make it extend the draw screen)

and
2) judders like a mad man.
If i could work through exactly what each messed up part of my code was doing then i might be able to spot what ive done, but i think its fine, i see the operations as being fine yet they arent because thats not what the computer would do. I just dont think like it does so cant work out what its doing, instead i just look at each line and think about what i would do with that line which is not right because me and the computer are getting very different results.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 8th Apr 2011 16:24 Edited at: 8th Apr 2011 16:27
Your AreaCheck needs to be equal to your Map array size and not the screen because it's an out of bounce check while checking the Map array.


What I mean about adding a 1 is to increase the amount of loops in the X & Y loop.
So now Y is looping 0 to 25 and X is looping 0 to 33. This should draw you that extra tile on the Right and Down edge. And you may also use the values directly.


Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 8th Apr 2011 21:17 Edited at: 8th Apr 2011 21:28
Managed to get it working now, you were right about the tiles not being right, it didnt know what to display. Thanks.

Just got a problem with the other 4 directions, the diaganols.


This now causes the character to go twice as fast when he is diaganol than when he is just using north, south, east or west.
I know why this is happening - because i am changing 2 variables of movement - and i know what its doing but i cant think for the life of me how to fix it.
Remeber that Scrollspeed does not exist in my code, in the code that you posted a while back it literally did nothing after it was declared so i ommited it from my code.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 8th Apr 2011 21:50 Edited at: 8th Apr 2011 21:53
The variable ScrollSpeed# works, it's because after declaring and setting a value you forget to remove the previous line that assigns ScrollSpeed# with the value of 1 that was inside the function.


[Edit]
When scrolling diagonal it will appear faster because you're moving 2 pixels at a time. Just inc or dec the values by a smaller amount.


Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 8th Apr 2011 22:25 Edited at: 8th Apr 2011 22:45
Yeah that will do the trick nicely. I originally stated that scrollspeed was doing nothing because it wasnt used in any calculation or anywhere else but 2 places. Once when it was declared then once in the function, i couldnt find it anywhere else, when i removed it it had no effect and it is not used at all in my code. But just reducing the inc and dec values to 0.5 on each the the diagonal directions will work a treat.

1) While i was waiting for a reply i got down to popping a mob on the screen (not moving him just yet but im getting to it ) He appears perfectly when i declare his x and y position to be within the original screen co-ordinates.
I cant really make the area check work with him because any co-ordinates above the screens co-ordinates never get shown so the screen is 1024 but if i give him an x of 1050 he will never show up because even with an area check he will never be within those bounds. I tried giving him world co-ordinates aswell and thinking about how to make them appear on screen but to be honest i am very lost. I dont know how to say "the character is here, when he is moving he is now here in the world, the mob is here, if its within the world co-ordinates surrounding the player (the area check) then paste him down"

I declared an enemy type using this :

Declared the mob using this :


And i have created a MobHandle() function in the main loop to set up checks but dont really know how to manipulate the world co-ordinates into the screen. 1350 as an x position will always be 1350 and never 1024 within the screen boundarys, an area check will never pick this up and the mob will never be displayed. If i could move the world co-ordinates around somehow i could use an area check to see if i should be pasting him down but if i cant move his world co-ordinates i cant paste anything that is not immediately on the beginning screen.

2) Any tips on how to make him move along a path would be great as well because although i think i can make a simple path by increase the x and y co ordinates in a loop till a certain point then reversing them to make him walk back i have a feeling its not as easy as that and its just not going to work that way at all. In fact i am certain i know what will happen, it will either move a little then keep on moving indefinately in one direction because the co-ordinates will no longer exist in some way shape of form so it wont be a case of "when you reach here, stop and turn around", it wont happen like that. Or it will move along with the character scroll as well as the direction hes moving in making him judder everywhere. I can literally see it happening, i already know how it will turn out like ive dreamt it. So tips would be fab to save me from doing it wrong in the first place.
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 8th Apr 2011 22:37 Edited at: 8th Apr 2011 22:44
3) Also reducing the values to 0.5 on the speed did not work as they were very slow. Playing around with them i found that 0.7 seems to be closeish but more will need to be done i fear as now when travelling in any diaganol direction, horrible splits and lines appear everywhere.

Edit: Back to point 1) this is as far as i got in the mobhandle
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 8th Apr 2011 23:20 Edited at: 8th Apr 2011 23:22
When doing an AreaCheck for the mob coordinates which is based on the screen, you want to use the screen values. You are half way on the right path here by checking ScrollMapX * 32 - ScrollMoveX# because that needs to be applied to the Ogres X and Y values. Also remember to swap the CheckX = Ogres(1).WorldX into CheckX = Ogres(a).WorldX because you're doing a loop a = 0 to MaxOgres.



Quote: "horrible splits and lines appear everywhere"

Yes about that, it's because of the use of a float while pasting the terrain tiles. Turn it into an integer using int(float#) or pass the float value into an integer variable.
Example Int() :

Example Integer:


Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 8th Apr 2011 23:45
I'm going to be very honest with ya, 2D may seem easier to learn than 3d but that lighter learning curve only last for a bit then it becomes just as challenging as 3D. The plain DBPro supports 3D much better than it does the basic 2D elements so you'll have to pick up some lower level though process to actually get things to work out the way you want. If you really don't plan to stick around with 2D, now is a good time to move on into 3D because from on out it'll require a lot of technical skills that only applies to 2D and won't be very useful later on in 3D.

It's still just your choice, if you plan to stick this out for a bit more I'd still help you out.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 8th Apr 2011 23:58
Quote: "Turn it into an integer using int(float#) or pass the float value into an integer variable."

Thats what i was looking for, great.

The check at the moment still doesnt work though. Because it is a whole sprite sheet just pasting that code into the function makes it paste everything so thats ok as id expect it to do that, what i need to do is cut it down to just play a certain frame, or in the case of what i tried, just frames, using play sprite but this has ill effect as it just does not show up at all.
The maths behind what

Is doing is going over my head a little. As surely you would not check PLUS scrollmapX, wouldnt it be minus, as the worldx co-ordinate is already way beyond the screen so adding even more numbers will never make it appear within the screen boundary.
Is there a way i can paste text on top of the sprites (there are currently just over 100,000 threads on this and none of them with answers i understand) so i can see what numbers are going on in the background because sitting there with a calculator trying to work out what number i think the computer is coming up with is not working and its a bit of a slow way to do it anyway.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 9th Apr 2011 00:06
Quote: "Is there a way i can paste text on top of the sprites"

Your text are not showing up because you draw that first then draw the terrain and everything else over it. You have to move your DebugText() to be called last. Things are drawn or displayed in the order that you paste or plot it to the screen.


Quote: "As surely you would not check PLUS scrollmapX,"

You are absolutely correct! I haven't test but I think the 2 variables need to be swapped. CheckX = Ogres(a).WorldX + ScrollMoveX# - ScrollMapX * 32

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 9th Apr 2011 00:26 Edited at: 9th Apr 2011 00:34
Edit: I got him pasted down, thanks! Just going to start working on the movement and so on now but should just be a case of checking his direction and playing the appropriate frames etc, all of this shouldnt be too bad.

I dont really want to try 3d just yet as i know your right with DB pro being more 3d friendly and all, and a lot of things i learn will be specific to 2d only that would then not get used but i still cant help thinking that learning this first will somehow make me get to grips with 3d better later on down the line. Some of the best people who can code all started with 2d as there was no 3d way back in the day, i cant help thinking that there is something in that, the way 2d forces you to start thinking, plus i would love to make something out of this if i can.

Edit: I dont know if you have run a recent version but there is some unpredictable movement in the speed that it scrolls. It can change a little mid walk, plus it increases exponentially when coming up to and going out of the confines of the map. This is rather odd and i was wondering what was happening here.
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 9th Apr 2011 00:38
Quote: "It can change a little mid walk, plus it increases exponentially when coming up to and going out of the confines of the map"

That's because you are drawing less things onto the screen so it's faster. Like I keep telling you, only graphical output really slows things down. There is a method you can use to cause this to go blazing fast. I can show it to you if you're up for it.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 9th Apr 2011 00:54
Quote: "There is a method you can use to cause this to go blazing fast. I can show it to you if you're up for it."

Not just yet thanks but hopefully soon.

Still got a few glitches here and there but slowly getting over this brick wall.

This is what i have so far (using same media as before)
Its not working as intended at all but i feel like im getting closer. I definately need to do something about the world co-ordinates though as i need to know what they are to make a check against them, every other number is not pasting things where desired. Take a quick look

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 9th Apr 2011 01:04
Was thinking of adding some sort of function that gets the world co-ordinates (no idea how see poor psuedo code example)

Then changes them into simple local x, y co-ordinates (Ogres(1).x, Ogres(1).y) that can then physically display along the screen for when the mob is moving (if they are patrolling a path or whatever) so hopefully making updating its moves on screen easier. As it just updates its out of sight stuff using the world co-ordinates then all the drawn stuff inside the local or something. But i dont know how this will work, in fact i dont even think this will work but if i get that function written then i can at least try.

Login to post a reply

Server time is: 2024-11-16 21:15:47
Your offset time is: 2024-11-16 21:15:47