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.

Dark GDK / sidescroller help

Author
Message
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 11th Aug 2009 21:01
im have three problems making a sidescrolling game. the first one is that i cant get the screen to scroll when i get to the edge of the screen, the second one is when you jump you float at the top of the jump if you hold the jump button down, and the third one is i cant get collision to work properly any help would be great
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 11th Aug 2009 21:14
Quote: "any help would be great"


So would some code to give an idea of what you're attempting.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 11th Aug 2009 21:18
1.
The SCREEN doesn't really scroll, it's your background and level and stuff so to move to the right you take away from your backgrounds X position and it makes the apperance of a "Camera" moving.

2.
I am not sure asi have no code from it but my first geuss is put a switch so like this:



3.
If you are using native collision commands then it would be something like this:


if your using custom collision then just substitute the "dbSpriteCollision" with your collision function. pretty much just change the position then check for collision. if there is collision move it back because theres no update inbatween the user doesn't see the change.

New Site! Check it out \/
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 15th Aug 2009 05:23
ok sorry it took so long but heres my source

Attachments

Login to view attachments
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 18th Aug 2009 02:22
if anyone could help me that would be great ive tried everything i could think of to fix the problems
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 18th Aug 2009 14:20
Jumping: The sprite can "float" because as soon as the player sprite starts to fall, you set the "jumping" flag to false, so the code will allow starting a new jump while still in the air. I suggest you to introduce a "player state" variable which can have three values: jumping, falling, on the ground. Allow starting a new jump only when you are on the ground.

Remark: You have a constant gravity value which you add to the Y position of the player directly. The result will be that the speed of the jump is constant. This may be OK for your game, depending on how it's designed, but the usual way to jump is to have a starting velocity, then deduct the gravity from the velocity and deduct the velocity from the Y position. This way, the jump will gradually slow down, then start to fall and the downward speed will increase the longer it falls. This would make the jump look more realistic.

Collision: I see you have written your own function to compare the coordinates of the player sprite and the enemy sprite and you say it doesn't work properly. There are two ways to fix this: either you find out what's wrong with your coordinate calculation, or simply use dbSpriteCollision which should solve your problem easily.

The best use I can see for calculating your own coordinates is to call dbSpriteCollision only for those sprites which are in the immediate vicinity of the player. dbSpriteCollision is rather slow when you have a lot of "ground" or "obstacle" sprites and it's a waste of CPU time to check collision with sprites which are far away from the player.

I see you are using dbSpriteHit in a few places, to check for collision between player and "floor" sprites. If that doesn't work properly either, then I would change that also to dbSpriteCollision, to check for overlap instead of edge-to-edge (during falling, the sprite may miss the stage when it is exactly lined up with the floor).

Scrolling: I'm afraid you'll have to work it out yourself, because the only way to do it is to adjust the coordinates of the background sprites. When you reach the edge, it's not the player that moves, but the background. Or you can keep the player always in the centre and move only the background around the player. In any case, it's not an easy task and how exactly you do it depends on your game design. Number your background sprites so that the numbers are in a continuous range, then you can update them all in a loop. This is useful when the background is composed of many small blocks.

If you have also a big background picture (like "sky.png" or "ground.png" which I see in your code), then you can apply the following trick: Make two copies of the background image and position them side by side. If you want to scroll the background to the left, you scroll them both, so as the first image slides out of view, the second one slides in from the right and it seems as if it were a continuous background. Of course, for this effect to work, the edges of the pictures should match seamlessly, so that you don't see where one image ends and the other begins.

Some general remarks to your code:

You have put the player.makePlayer() function call in your GAME part, but this function only contains a call to dbCreateAnimatedSprite(). You don't need to load and recreate the sprite every loop. Do this in the game setup part instead.



Does it really matter which key is pressed if a collision happens? I don't think you need the KeyState condition here.



I hope you realise that these lines don't do anything? You calculate a difference value, but it's not assigned to any variable, the result of the calculation is not used.




Same mistake in two places: dbKeyState is always either 1 or 0, so this condition is always true. It doesn't do anything and it is exactly the same as writing the code without it:




Finally, in the UpdatePlayer function, you first draw the player sprite, then move it. It should be the other way around, since in this case you will draw the sprite at the previous position, not at the new position calculated by the move function. It's not a big difference in a fast loop, but it's better to draw always the latest situation.

I hope that helps.
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 19th Aug 2009 06:47
ok thanks for all the tips ill try to get it to work
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 20th Aug 2009 03:30
and i really cant use dbSpriteHit or dbSpriteCollision because im trying to make it like mario where you have to jump on top of the enemy to kill them
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 20th Aug 2009 12:03
I see. It may still be possible to use dbSpriteCollision and if it collides, then check if the player sprite arrived from the top or from another directon. For example, by storing the previous position of the player sprite and checking if, in the previous position, its bottom edge was above the upper edge of the enemy sprite. I don't know if this would work well and of course, if you have to check coordinates anyway, then you might as well do your own calculations, but it's a possibility.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 20th Aug 2009 15:44
Or look for collision but only if the player was on his way down instead of jumping up or moving horizontally.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 21st Aug 2009 04:26
ok thanks for all the help

Login to post a reply

Server time is: 2024-10-01 10:31:04
Your offset time is: 2024-10-01 10:31:04