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.

AppGameKit Classic Chat / How to get player to remain in facing direction

Author
Message
sskethan
15
Years of Service
User Offline
Joined: 20th Sep 2008
Location: Oshawa, ON. Canada
Posted: 5th Nov 2012 16:26
Hello,
How would i get the player to stay facing in the direction/angle it is when I release the joystick? Currently when the joystick is released the player will face back the start position of 90 degree angle. Also need help with centering the player to the screen with the scrolling background. The screen scrolls and moves smooth but the player is positioned at the top left corner of the screen.
Thank you

Attachments

Login to view attachments
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 5th Nov 2012 16:54 Edited at: 5th Nov 2012 16:55
You should move the code that sets the angle inside the part of the if statement that handles when there is input from the joystick. The way you are doing it, you reset the angle every time, regardless of whether there is joystick usage.

Something like this:


Cheers,
Ancient Lady
AGK Community Tester
sskethan
15
Years of Service
User Offline
Joined: 20th Sep 2008
Location: Oshawa, ON. Canada
Posted: 5th Nov 2012 17:39
That's great, thank you for the speedy response. The player now stops and faces the last angle it was on.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 5th Nov 2012 19:53
Always glad to help.

Happy Programming!

Cheers,
Ancient Lady
AGK Community Tester
sskethan
15
Years of Service
User Offline
Joined: 20th Sep 2008
Location: Oshawa, ON. Canada
Posted: 6th Nov 2012 02:44
I'm still having trouble trying to get the player centered on the screen. I have tried to fixspritetoscreen. but when i do this the player moves faster then the background and the player walks off the edges. Is there maybe something i need to change in the SetSpritePosition inside the if statement?
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 6th Nov 2012 16:08
I don't have experience with keeping a player in center and scrolling the background. But in your code you are only moving the player (the same id used for both the animation and position setting). I would expect that you would be moving the background and leaving the sprite fixed to the center (changing its angle and animation).

Maybe someone with more experience in this could help?

Cheers,
Ancient Lady
AGK Community Tester
sskethan
15
Years of Service
User Offline
Joined: 20th Sep 2008
Location: Oshawa, ON. Canada
Posted: 9th Nov 2012 13:33
I have been trying to change the code to keep the player in the center and scroll the background but i'm not sure where to start. Here is what I have now. Can someone please help?

lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 9th Nov 2012 14:05
If you want to keep the player in the middle you either need to stop changing that sprite's position or move the camera with it.

In the case of moving the camera (which I would recomend) you simply set camera offset to the player's position minus half the screen width for x and half the height for y. I'm sorry I'm typing this on my phone but I might be able to paste an example later.

Toby

My hovercraft is full of eels
sskethan
15
Years of Service
User Offline
Joined: 20th Sep 2008
Location: Oshawa, ON. Canada
Posted: 9th Nov 2012 21:30
I think I got it. Thank you for the insight everyone. Here is the code i have now. Player stays centred and background moves. Now to move on to shooting.

Login to post a reply

Server time is: 2024-05-07 14:27:44
Your offset time is: 2024-05-07 14:27:44