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] Help with positions based on sprite angle, scale and offset (I'm using GetWorldXFromSprite )

Author
Message
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 22nd Aug 2018 10:50
Hi All,

The below code (sorry - you need to create two really simple sprites) creates random dots all over another sprite that is rotating and that can be scaled too - it works exactly as I want it to (it's for generating death splashes on monsters)... EXCEPT that if I also add a sprite offset (which I need to do for my game) it breaks. Can someone help me figure out what extra line(s) of code I need?


Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)

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

Go to answer

Increase
7
Years of Service
User Offline
Joined: 21st Feb 2017
Location:
Posted: 22nd Aug 2018 11:34
maybe in the header you can set

SetSpriteOffset( barsprite, GetSpriteWidth(BarSprite)/2, GetSpriteHeight(BarSprite)/2 )


and replace in the cycle loop


LocX = RandomSign(Random(-GetSpriteWidth(BarSprite)/4 , GetSpriteWidth(BarSprite)/4)) // Find a random location within the sprite's boundaries on the X axis
LocY = RandomSign(Random(-GetSpriteHeight(BarSprite)/4, GetSpriteHeight(BarSprite)/4)) // Find a random location within the sprites boundaries on the Y axis

NewLocX = GetWorldXFromSprite(BarSprite, GetSpriteXByOffset(BarSprite)+LocX , GetSpriteYByOffset(BarSprite)+LocY ) // Convert the above location to the altered sprites position on X
NewLocY = GetWorldYFromSprite(BarSprite, GetSpriteXByOffset(BarSprite)+LocX , GetSpriteYByOffset(BarSprite)+LocY ) // Convert the above location to the altered sprites position on Y


(not tested, just from scratch)
Increase
7
Years of Service
User Offline
Joined: 21st Feb 2017
Location:
Posted: 22nd Aug 2018 11:43
just tested it - doesn't seem to work
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 22nd Aug 2018 12:12
This post has been marked by the post author as the answer.
Just change these lines (line 29,30)

LocX = Random(0, GetSpriteWidth(BarSprite)) - GetSpriteOffsetX(BarSprite)
LocY = Random(0, GetSpriteHeight(BarSprite)) - GetSpriteOffsetY(BarSprite)

Makes it independant of sprite offset
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 22nd Aug 2018 12:46
Increase - Thanks for trying!

Bengisimo - Perfect! Works a treat! I knew it would be a simple tweak somewhere but never tried on the original locations! Well done and thanks.
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)

Login to post a reply

Server time is: 2024-04-20 13:38:39
Your offset time is: 2024-04-20 13:38:39