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 stop sprite going off screen

Author
Message
MattDroid Inc
11
Years of Service
User Offline
Joined: 28th Nov 2012
Location:
Posted: 28th Nov 2012 16:20
Hello,

I have just started using AppGameKit and I have hit a stumbling block. I am trying to make a ball move around the screen, I have got it to move but it doesn't stop on the edge of the screen and just disappears off screen.

How is it that I can sop this? Ideally I want the ball to bounce off of the edge of the screen and keep bouncing around.

Matt

Matt
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 28th Nov 2012 16:58
Use SetPhysicsWallBottom/Top/Left/Right commands like this:

Do this where you set up your display, it only needs to be done once.

Cheers,
Ancient Lady
AGK Community Tester
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Nov 2012 17:29
That will only work if your ball uses physics of course, if you are using your own system you will need to redirect the sprite yourself after detecting where on the screen your sprite is.

It would help if we knew how your ball is being controlled?


this.mess = abs(sin(times#))
MattDroid Inc
11
Years of Service
User Offline
Joined: 28th Nov 2012
Location:
Posted: 28th Nov 2012 19:50
Thanks guys, one other thing. How do i code it so my sprite (paddle)moves left and right when the user clicks and drags?

Matt
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 30th Nov 2012 12:26 Edited at: 30th Nov 2012 12:31
There are many different ways you could do this, all depending on how you want to design your game and also depending on if you are using physics enabled sprites.

Example 1: No physics

Without physics, a very elementary way of doing this which you probably would like to expand on. For instance this would cause the paddle to jump to the position of the pointer at a click.



Code not tested

Example 2: With physics enabled on paddle



Right I haven't tested this but I hope it gives you ideas of what you can do

If you need more specifics let me know

My hovercraft is full of eels
MattDroid Inc
11
Years of Service
User Offline
Joined: 28th Nov 2012
Location:
Posted: 30th Nov 2012 14:11
Thanks everyone, managed to get it sorted

Matt

Login to post a reply

Server time is: 2024-05-03 14:56:37
Your offset time is: 2024-05-03 14:56:37