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 / Boundaries on a screen?

Author
Message
Hatebreed
17
Years of Service
User Offline
Joined: 18th Sep 2007
Location:
Posted: 30th Oct 2007 03:21
Hey guys,

My instructor has given us an assignment to work on throughout the week and this is what he needs us to do:

1.Have an animated sprite that moves in all four directions either by keyboard or mouse (or both)

2. The animated sprite must also face the direction it is moving in.

O.k., I have those two things complete. The only thing is something personally bugging the heck out of me. I have rummaged through the book and because I don't know what it is called I have no clue where to look.

When I move the object it runs completely off the screen and, I guess, keeps going. I have googled phrases I think it could be, searched through the forums here and I still cannot find snippets of code or a tutorial that could help me out.

If anyone knows where I could find one of the two (preferably Tutorial so I am actually learning it...Then I can show off in class when we learn it!!!)

To reiterate the question because I feel I got a little off track:

I am trying to figure out how to keep an object or sprite from going off the edge of the screen.

Thanks,
Hatebreed
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 30th Oct 2007 03:31
When the sprite moves to the left, you reduce the variable which controls it's X position. To stop it moving off the left side of the screen, immediately after the line which calculates it's screen X position you use something like:

If LeftKey()=1 Then Dec SpriteXPos: If SpriteXPos < 0 Then SpriteXPos = 0
Sprite 1,SpriteXPos,SpriteYPos,1


You repeat the same thing after the other three directions (not forgetting to take into account the sprite dimensions). Eg something like:



TDK_Man

Hatebreed
17
Years of Service
User Offline
Joined: 18th Sep 2007
Location:
Posted: 30th Oct 2007 03:36
Ok so, that code is a little confusing to me but I have to just read it slowly. Anyways, it looks as though I will need more then the origional two variables I started out with?

i started with pacX and pacY for the x and Y coordinates using the keys to move around. Will I need more or will spriteXpos and SpriteYpos be replaced by my origional two variables?

I hope that makes sense...

I attached my code so I hope it makes a little more sense.

Attachments

Login to view attachments
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 30th Oct 2007 05:08
Man TDK - We are hitting the same stuff - perusing at the same time - hope I'm not toe stepping by trying to help also

(you nailed this one )

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 30th Oct 2007 05:14
Quote: "hope I'm not toe stepping by trying to help also"


No of course not - lol!

Quote: "i started with pacX and pacY for the x and Y coordinates using the keys to move around. Will I need more or will spriteXpos and SpriteYpos be replaced by my origional two variables?"


I just used spriteXpos and SpriteYpos as examples. You only need two - the top left X position for the sprite and the top left Y position.

Just replace the two variable names I used for whatever your program uses (pacX and pacY).

TDK_Man

Eevil Weevil
17
Years of Service
User Offline
Joined: 1st Aug 2007
Location: Wherever you are, I wil follow
Posted: 17th Nov 2007 20:53
And for rotating your sprite, you could have a string, perhaps 'pacDirection$'. If the leftkey() is being pressed, then you could check if the sprite if already facing left ('pacDirection$="left"'). If it is, don't do anything. However, if it isn't already facing left then you could have the program A; Mirror it if it is facing right ('Mirror Sprite SPRITENUM') and B; set the 'pacDirection$' string to "left". You could then do that with right, up and down (You can flip the sprite vertically by using 'Flip sprite SPRITENUM')

Impossible? Anything is impossible. 48'6F'77'20'64'61'72'65'20'79'6F'75'20'77'6F'72'6B'20'6F'75'74'20'6D'79'20'73'69'67'21

Login to post a reply

Server time is: 2024-09-27 08:31:35
Your offset time is: 2024-09-27 08:31:35