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 / image moving\replacing? + Screen Size?

Author
Message
Seannny
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: California
Posted: 1st May 2007 17:50
Hey ive got a few questions here. ive got a sprite of Link from Zelda, ive got a fe wpics of him facing different directions and swinging his sword ect. i know how to get him moving around the screen, i got that already in, but i want it so when i hit left key, him faceing left is shown, hit right key, him facing right is show. i can move him but not face him where i move him.
my second question is there a way to slow down the speed that my dude moves? he is darting across the screen. here is my code

is this where i edit the speed of the image shifting around? im confused...
next question is...how would i keep my sprite from leaving the screen? i can make it so he cant leave from left or top.. but i cant get right or down... here my code..=/


thanks for the help!

hey, im a db noob. Lets all throw pies at me.
H4ck1d
18
Years of Service
User Offline
Joined: 27th Dec 2005
Location: Yes
Posted: 2nd May 2007 01:53
As for the direction the sprite is facing, what you could do is use a variable to keep track of which way he is facing, and if he is facing the wrong way then use 'flip sprite.' For example:



To slow down the player, change the varibles by a smaller amount. So instead of "x = x-1", you would have "x = x-.2" for example. Make sure, however, that the variable is a float, because integers can only be whole numbers, no decimals. To declare a float, use



And so on at the beginning of your program. That way you can use decimals.

Finally for your last question - your code should work, you're just missing one thing - it sounds like the coordinates of your sprite are from the top-left corner of the sprite. So if you place the sprite at 0,0, then the top-left corner would be at 0,0. The problem is that the sprite has width and height. So when you check if the x is greater than 640, that's from the top-left corner. The corner might still be less that 640, but most of your sprite could be off the screen! So to make up for this, subtract the width and the height of the sprite from the coordinates you are checking. So for example, if the sprite was 30 pixels by 50 pixels, your code would look like this:



Because 640-30=610 and 480-50=430.

Hope that made sense. Good luck with your game!

-H4ck1d

Seannny
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: California
Posted: 2nd May 2007 02:33
The flip doesnt work. it turns it upside down, it would be easiest if you could simply tell me how to replace a image if i hit the arrow key. this would also help for attacking...

hey, im a db noob. Lets all throw pies at me.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 2nd May 2007 03:45
You could make sure that the images used by the sprite are numbered according to the values of the SpriteDirection variable.

So, if SpriteDirection = 1 for left, when you load the images, make sure that the image of Link facing left is image number 1. If SpriteDirection = 2 for right, then make sure that the image of Link facing right is image number 2.

When you use the sprite command, use:

Sprite SprNum, X, Y, SpriteDirection

TDK_Man

Login to post a reply

Server time is: 2024-09-25 21:20:14
Your offset time is: 2024-09-25 21:20:14