RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[Resolved] Calculating sprite's on screen x and y values?

0 Members and 1 Guest are viewing this topic.

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
Fun little problem that I encountered when working with angles and sprites, and also something that's now really bugging me .-.

Is there any way I can track the location of a sprite according to it's ox value? What I mean is, say for instance I have a sprite that is at x value 0 and y value 0, but at an ox value of -272 and an oy value of -272. The sprite would be somewhere at the bottom of the screen, and my sprites x and y values (on the screen) are 272 and 272, even though my sprite is at 0, 0 according to it's actual x and y values. But if my sprite's angle is set at 180, the sprite's corresponding x and y (on the screen) is -272 and -272, and my sprite is at 0, 0 according to it's actual x and y values.

My dilemma is trying to get the sprite's screen x and screen y co-ordinates. Is there some kind of formula RGSS2 uses for getting these values? Or are the values stored in some default variable that I don't know about?

I'm not sure if I explained this very well, and I will be happy to elaborate on my problem.
« Last Edit: August 27, 2011, 02:21:54 AM by cozziekuns »

***
Rep:
Level 74
I'm baaack!

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween


Not exactly what I was looking for. I was refering to a sprite and it's ox and oy values, as well as it's angle, not an events location. But thanks for the help, I guess.

*****
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Most Missed Member2014 Zero to Hero2014 Best IRC Quote2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
That's a confusing one there. Of course, there's the obvious solution of printing the sprite's ox coordinate, but that would be impractical and annoying. No.
What I would do is have a dummy sprite follow the sprite, so that the dummy's x and y are equal to the actual sprite's ox and oy, or inversely so if required. If the angle of the sprite is 0, leave them unaltered, if it is 180, multiply it by -1, if it is 90 half it(?) and for 270 half and multiply by -1.
Thinking about this is making my head hurt, and I don't even know if I'm helping you at all.
Something that would help me is seeing your problem in action. If you could recreate the problem in code and post it, you'll probably get more constructive answers.
it's like a metaphor or something i don't know

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
The rotation is anchored around the ox and oy coordinates. Try changing those. You could for example set it to half width and half height.
Is this fine or do you still want to know what I assume to be the x- and y-coordinate of the top-left corner of the  bounding box after the sprite's angle has been processed.
I don't think you have access to the underlying transformation matrix so you would probably have to use trigonometric functions to approximate the coordinate.

*hugs*

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
I realize that the angling of a sprite's screen x and y values can be changed with ox and oy values, but like you said I want to know the screen x and screen y co-ordinates of the top right corner of the bounding box after the sprite's angle has been processed. I too was thinking about using trigonometric functions, though I'm not sure how accurate it would be, and I'm not sure where to start.

EDIT: Nevermind, I eventually sorted it out. If anyone wants a demo of the snippet I made, it's here:

Code: [Select]
module Math
 
  def self.sind(value)
    return sin((Math::PI / 180) * value)
  end
 
  def self.cosd(value)
    return cos((Math::PI / 180) * value)
  end
 
end

@sprite = ::Sprite.new
@sprite.bitmap = Bitmap.new(32, 32)
@sprite.bitmap.fill_rect(0, 0, 32, 32, Color.new(255, 255, 255))
@sprite.angle = 0
@sprite.x = (544 - 32) / 2
@sprite.y = (416 - 32) / 2
@sprite.ox = 0
@sprite.oy = 0

loop do
  Graphics.update
  speed = 1
  @sprite.x += (speed * Math.sind(@sprite.angle + 90) * 2)
  @sprite.y += -(speed * Math.cosd(@sprite.angle + 90) * 2)
end

Thanks guys for helping me out! Resolved.


« Last Edit: August 27, 2011, 02:21:02 AM by cozziekuns »