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 / Scroll Sprite - Reverse

Retired Moderator
Years of Service
User Offline
Joined: 22nd Oct 2004
Location: UK
Posted: 27th Aug 2011 00:14 Edited at: 27th Aug 2011 01:25
Hi Everyone,

Enjoying AGK. I am stuck with a few things which I have searched for solutions for in the manuals, online help, examples and so on as well as trying various things myself without any luck as yet and any help would be appreciated.

I have a game in which I have a sprite moving left to right across the top of the screen using a simple script :
SetSpritePosition ( compad, x#, 95 )
//add 0.5 to the variable x#
x# = x# + 1.0

This works just fine.

The sprite is stopped at the right hand side of the screen and I have it looping back to the left and repeating from left to right again continuously from the left hand side.

When it gets to the right hand side of the screen - does anyone know if there is a way to have the sprite reverse direction from its position at the right hand side so that it goes from left to right and the right to left and continues in that loop?

I hope some of that makes some kind of sense.

Thanks and happy game making

Years of Service
User Offline
Joined: 28th Jan 2004
Posted: 27th Aug 2011 02:29
Set a direction variable, say it equals 0 for right and 1 for left, or vice versa. When the sprite hits the edge, just change the direction value. In your code to move the sprite just add in a check for the direction and set the movement variable accordingly, eg x=x+1 or x=x-1.
Probably quicker to have just put some code, but you should get the idea.

Years of Service
User Offline
Joined: 17th Sep 2008
Posted: 27th Aug 2011 11:16
I'd do something like this:

This starts your sprite moving to the right at a speed of 1. When it hits the right edge, moveSpeed becomes -1 so the sprite moves left. When it hits the left edge, moveSeed becomes 1 and it starts moving right again.

Login to post a reply

Server time is: 2023-12-07 04:53:48
Your offset time is: 2023-12-07 04:53:48