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 / [SOLVED] Can anyone help me with this 2d game mechanics? I'm pretty lost on how to implement . >:/

Author
Message
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 13th Jan 2022 03:37 Edited at: 13th Jan 2022 03:55
Hello everyone ! I'm re-learning how to use AKG around these days, and as I've been away for many years, I'm kind of lost xD.
let's say I'm a "newbie" again, my question is the following, I'm trying to create simple games to get the "rhythm", I'm trying to create a mechanic that in agk "seems" not to be as complex to implement as in others engines.

I would like to make a mechanic similar to this game below: in which the sprite follows the angle of the mouse pointer and is stopped in a position ddo ViewPort but moves around the World, I'm a little confused on how to apply this correctly in AppGameKit .






would you have a tip or an example for me to get inspired and try to replicate and study?
thank you very much for everyone's attention!!

The author of this post has marked a post as an answer.

Go to answer

Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 13th Jan 2022 05:27
Constantly moving the sprite and pointing the sprite at the x and y position of the mouse.

GetPointerX ( ), GetPointerY

No example to show but that is basic easy set up.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 13th Jan 2022 09:10 Edited at: 13th Jan 2022 09:11
I have not got time to code an example but heres a couple of functions that will kick start your idea




PointSprite to the mouse location, MoveSprite by given amount, your 2/3's there
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 13th Jan 2022 14:02 Edited at: 13th Jan 2022 14:06
well, the examples work very well, however, I still have doubts about how to make the movement of the ship in relation to the world, I would need to leave it limited to a certain area of the ViewPort, but if it is fixed in the delimited area, the movement in the world still persists.
what do you suggest i do? something tells me I need to use the command : FixSpriteToScreen.

like this below :
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 13th Jan 2022 14:52
This post has been marked by the post author as the answer.
You can do what you want with SetViewOffset()
You will then need to change the sprites positions relative to the world not the screen.
See:
WorldToScreenX()
WorldToScreenY()
ScreenToWorldX()
ScreenToWorldY()
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 13th Jan 2022 16:04
Heres a small piece of code ripped from my asteroids test project space game thing!, you will need to edit it to suit your project, set the images and player sprite and stuff but this will handle the screen offsets and image background.

I make the background the 3* larger than the screen because I have zooming, but the principle is you move the background with the player sprite and view offset and move the background UV is the opposite direction to travel giving the illusion that its stationary, the benefit of this is a "infinite" space playing area



with minimal edits you should be able to get that running
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 13th Jan 2022 18:50 Edited at: 13th Jan 2022 19:01
I managed to move around the map keeping the sprite fixed in a certain part, however, the algorithm is not " as efficient and fluid ", at some point the sprite gets stuck and doesn't leave the specific point anymore (although it still moves on the map )... (if anyone can help me improve this algorithm xD, I would be happy)

and also how do I get the position of this sprite in relation to the map? if I use the command: GetSpriteXByOffset and GetSpriteYByOffset, I get the sprite's position relative to the ViewPort...

I tried to use the following commands, but I believe I don't know how to use them, the values don't seem to be correct...
Scraggle wrote: "
WorldToScreenX()
WorldToScreenY()
ScreenToWorldX()
ScreenToWorldY()
"


Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 13th Jan 2022 19:00
Look up two posts
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 13th Jan 2022 19:50
Solved Guys thanks Scraggle and PartTimeCoder by help !

Login to post a reply

Server time is: 2024-03-29 09:48:36
Your offset time is: 2024-03-29 09:48:36