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 / Looking for a goto command for setViewOffset

Author
Message
Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 4th Oct 2012 21:10
I realize that setViewOffset moves the screen along the axis the number that is set by X and Y.

I have several characters in my game. As I move from each character I want the view offset to line up on each character.

Is there a command that will move the offset to an exact location such as the getSpriteX(player) position?

I don't want it to move a number of units in X or Y, just go to these coordinates. Maybe something like setViewOffsetCoordiante(X,Y).
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 4th Oct 2012 23:43 Edited at: 4th Oct 2012 23:57
You just need to calculate the correct offset for each character.

For example, if you are using a virtual resolution of 800 x 600, then the horizontal center of your screen is 400 when the view offset is zero x and zero y.

To move the view to a character that is at x = 500 (100 units to the right of center), SetViewOffset(100, 0).

If the character was at x = 300, then you would move the view offset to -100 for the x coordinate.

That's for the horizontal offset, you can do the same for the vertical, if your characters are at different heights.

If you set the view offset to the exact coordinates of the character, you will end up with the character in the upper left corner of the screen!

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Oct 2012 11:30 Edited at: 5th Oct 2012 11:32
Here's one I happen to have lying around. Take a look and you'll see it does what Rich was suggesting.


Edit: This version doesn't allow for view scaling which complicates matters a little, particularly if you centre the scaling too. I still haven't gotten around to creating a version that works on centred scaling.


this.mess = abs(sin(times#))
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 5th Oct 2012 11:41
Nice, bax. But...

What if the coder has changed the offset on the sprite?

Maybe get the actual center of the sprite (sprite x/y plus half of width/height) instead of x/y by offset?

Also, instead of just changing the view offset, it would be neat to pan from the current offset to the new, with an ease in/ease out.

I'm working on that for HOTspot Designer, because I want to zoom into a HOTspot and center on it. But changing the view offset while zooming in is a bit tricky so far.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Oct 2012 11:45
Quote: "What if the coder has changed the offset on the sprite?"

Well I'd be surprised if it was noticeable for a character sprite (why would you offset your character from it's centre?), but it's easily adaptable.

Quote: "Also, instead of just changing the view offset, it would be neat to pan from the current offset to the new, with an ease in/ease out."

That's what the "smooth" option does

Quote: "I'm working on that for HOTspot Designer, because I want to zoom into a HOTspot and center on it. But changing the view offset while zooming in is a bit tricky so far."

I would forget centering the view using zoom mode and use manual offsets, it's less tricky. Just remember to use screenToWorld and worldToScreen...


this.mess = abs(sin(times#))
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 5th Oct 2012 12:52 Edited at: 5th Oct 2012 12:56
Quote: "(why would you offset your character from it's centre?)"


I don't know. Maybe to have it rotate around some arbitrary point on it's image? Like a shoulder joint on a zombie's arm? Hmmm?

Quote: "but it's easily adaptable.
"


Agreed

Quote: "That's what the "smooth" option does"


I don't see how that works. There's no loop to move the view in increments. Would you call the function recursively until you get the view moved?

Quote: "I would forget centering the view using zoom mode and use manual offsets, it's less tricky."


Yah, I may have to just center first, and then zoom in.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Oct 2012 12:56
Quote: "I don't see how that works. There's no loop to move the view in increments. Would you call the function recursively until you get the view moved?"

I would just call this function for every loop I wanted to centre on a particular object. Isn't that the most likely way to use a function to centre on a character?

Example:


Quote: "Yah, I may have to just center first, and then zoom in."

Clever idea, just reset the view zoom to 1.0, centre the view then set the zoom again (using a centred zoom mode). Now why didn't I think of that!?


this.mess = abs(sin(times#))
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 5th Oct 2012 12:59
Quote: "I would just call this function for every loop I wanted to centre on a particular object"

Ah, I see what you mean. Good idea.

Lesse, it's about 5 am here, so it's 11 am there? Or is my time zone calc not right?

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Oct 2012 13:00
Yes, about 11am. Early start or late night?


this.mess = abs(sin(times#))
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 5th Oct 2012 13:10 Edited at: 5th Oct 2012 19:31
Late night, as I'm off work tomorrow. Err, later today. Friday. Heh.

Here's a quick and dirty version of what I'm working on...



I'll want to combine the two loops instead of doing x first, then y. And maybe put in some ease in/ease out code, but I still haven't been able to get my head around how to do that.

EDIT: changes to the code, as it evolves.

MORE EDIT: I decided to NOT use the smooth zoom and centering. It looks cool and all, but I don't have much patience to wait for it, so I'm just having the zoom and center pop into place. So I'm just about done with HOTspot Designer's release version, look for it in AppGameKit Showcase soon!

Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 6th Oct 2012 06:11
Thanks guys. I use the percentage system so it took me a little longer.

In the end here is what I used

the current view offset added in the new sprite x/y position then minus 40%

I got the 40 from 50 % of the screen minus half of the width/height of the sprite which is 20%.

Login to post a reply

Server time is: 2024-05-02 23:14:26
Your offset time is: 2024-05-02 23:14:26