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.

Newcomers DBPro Corner / 2D Zooming In

Author
Message
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 6th Aug 2008 02:04
Basically, the title says it all.
I'm trying to zoom in on a 2D screen, like in adobe photoshop or flash. The problem is, it's harder than it looks . I have a bunch of sprites set up, and I'd like to zoom in on them, having each sprite stay positioned and sized relative to how far zoomed in I am. Does anyone have any ideas on how to go about doing this? An example even?

Thanks in advance,
-Sixty Squares

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Aug 2008 04:07
You'd have to scale each sprite and reposition them accordingly, keeping the proper aspect ratios. Tricky, but doable.


Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 6th Aug 2008 04:16 Edited at: 6th Aug 2008 04:17
Thanks for responding,
Quote: "You'd have to scale each sprite and reposition them accordingly, keeping the proper aspect ratios. "

I've been trying that but failing.

Has anyone done this before? It'd be nice to see an example or have the concept/procedure involved explained in more depth.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Aug 2008 04:21
Are you dealing with just a single sprite or are you trying to zoom in on an entire tile map or something?


Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Aug 2008 08:37
single sprite, piece of cake! Zooming to a specific point, no problem. Doing all this on a tilemap of multiple images, TRICKY!
I think the hardest part for me was figuring out how to translate the scaled coordinates so the tiles still fit together properly. There's a small gap between tiles with a scale less than 1, might be a DBP float precision issue.


This demo will zoom in on a tilemap. The mouse coordinates represent the position of the map. The zoom always focuses on the center of the map.


Swap the image for whatever tile image you want to use for the demo, just make sure you input the dimensions for the tile size.



Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 6th Aug 2008 16:41
Wow thanks for the example Phaelax! I'll be sure to review it until I understand how it works. In my program I have a bunch of sprites put in no particular spot on a scrollable screen. I just wanted to be able to zoom in on various positions on the screen and have the sprites scaled + offset accordingly.
Thanks again

Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 6th Aug 2008 20:42
Hmm... I'm having trouble adapting your tileset based example to my program, which allows for freehand sprite movement and scaling. Since there is no "maximum tile" or "map width" in my case (the amount of space is virtually unlimited), how would one determine the "width" of a map? I tried dividing the screen's width by the original size of the sprite, but that only worked for smaller sprites. Any help would be greatly appreciated.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Aug 2008 23:01
You could try making up a max width by figuring the distance between the two furthest sprites.


Nano brain
16
Years of Service
User Offline
Joined: 7th May 2008
Location:
Posted: 6th Aug 2008 23:04 Edited at: 6th Aug 2008 23:18
Or use a center point of the map, in which all tiles are positioned relative to this center point. Then, all zoom positioning could be based on their relative distance from this center point on the x and y axis. The maps' center point would also need a relative offset from the center of the screen, and be repositioned accordingly based on zoom also:

1. reposition map center relative to x and y distances from center of screen

2. reposition tiles relative to x and y distances from map center

A non zoom value(or a 100% zoom) would have to equal 1, and a zoom value of 200% would be 2. So, if a tile has a -40 offset from the map center on the x axis at a normal zoom, then it would have a 150%(1.5 zoom value) zoom offset of -60, and a 200% zoom offset of -80. This same method is used for the map center offset from the center of the screen.

This will work for sure, and probably be the most practicle, and is more likely to be the way that the problem is usely tackled. I have no time right now to create an example. But, if you need help, I will hopefully have a working example next time I log into the forums.
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 7th Aug 2008 00:41 Edited at: 7th Aug 2008 00:42
Thank you for responding.

@Phaelax: That's a good point, but the sprites vary in size making it difficult to divide the screen up into tiles...

@Nano Brain: Wow that was a good idea. It worked perfectly, but in using it I found another issue which I think has nothing to do with the zoom code...

It seems that when a sprite's X/Y position is too far negative off of the screen, the sprite's position simply cannot go any farther negative. Does anyone know if this is a bug or if it has happened to them before? I'm using DBP u6.6.

Nano brain
16
Years of Service
User Offline
Joined: 7th May 2008
Location:
Posted: 7th Aug 2008 01:20 Edited at: 7th Aug 2008 01:21
It might have to do with the variable type integer, which has a limit, just like all types. Of course I could be wrong, because usually once the value goes below it's limit it wraps back around to the positive limit. So, I'm not really sure.

Do you know what the max negative value is? Is it always the same, or does it vary?

However, you can fix this by not moving the sprite if it so far off screen. I'm sure you've already thought of this though.
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 7th Aug 2008 02:05
I've seen integers go down way farther than I'm moving my sprite, so I don't think that's the issue. I guess I'll just try to keep my sprites at a lower scale to avoid this limit. Thanks for all of your help.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th Aug 2008 03:39
You should be clipping your view anyway and not even bothering with sprites that far off screen.


Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 7th Aug 2008 15:20
Clipping my view? Does that mean hiding off screen sprites?

Well, the program I'm creating is not a game, but sortof a sprite video creating software. When I wish to use a large backdrop, I scale a backdrop sprite to a very large size. When I zoom in, the backdrop sprite starts to go too negative off screen. Any ideas for a work around?

Login to post a reply

Server time is: 2024-09-27 18:21:49
Your offset time is: 2024-09-27 18:21:49