Window resizing & moving entities

Post your help queries and engine programming questions here

Window resizing & moving entities

Postby HumptyDumpty » Sun Jun 29, 2014 3:58 am

I'm having a little trouble trying to get the tilemap to behave the way I want it to when the window is resized.

The entities are mounted to the tilemap-> gameScene -> mainScene, the way it is in the isoimages example. When I resize the window the tilemap (and consequently the entities mounted to it) move their position (resize the isoimages example to get a demonstration of this) when instead I would like them to ignore the window resize/stay in exactly the same position.

Any thoughts?
Posts: 5
Joined: Wed Jun 04, 2014 11:00 am

Re: Window resizing & moving entities

Postby robaldred » Mon Jun 30, 2014 8:42 am

I'm not entirely sure what you mean here, I've looked at example 15.1-isoimages.
When resized, it behaves as I'd expect.
The camera translation remains in the centre of the viewport.

The viewport doesn't care about anything mounted, eg the tilemap or the entities.
the viewport looks through a camera.
Code: Select all

You can adjust it's translation like any other entity.
You can also make it follow other entities, like a player with:
Code: Select all
I don't work for Irrelon. All comments are my own.
I would strongly encourage anyone building production projects with Isogenic to buy a premium licence, it costs very little and will help towards continued development of the engine. Irrelon have spent thousands of hours developing this wonderful platform with many features found in AAA game engine.
User avatar
Posts: 243
Joined: Wed Oct 23, 2013 8:09 pm
Location: Manchester, England

Re: Window resizing & moving entities

Postby HumptyDumpty » Wed Jul 02, 2014 2:07 am

Okay, so let's see if I can explain this -
If you take a look at this attachment maybe this could help explain what I mean.
diagram.png (114.24 KiB) Viewed 9522 times

So the image on the left is the full sized browser, when resized the effect I want is for the area covered in dashed diagonal lines to disappear, instead what happens is that the tilemap moves to the top left of the screen i.e. the tilemap is always trying to stay in the centre of the viewport, I want the tilemap to say exactly where it was before.

Does that make any sense?
Posts: 5
Joined: Wed Jun 04, 2014 11:00 am

Re: Window resizing & moving entities

Postby foolmoron » Wed Jul 02, 2014 6:14 am

Yeah, by default the camera resizes around the center of the viewport. If you want to anchor the camera to one corner (top left in your case) then you need to hook into the screen resize event and translate the camera to compensate for the resized screen.

Conveniently, there is a _resizeEvent function that is called on entities when the screen is resized, including the IgeViewport entity, so you can hook into it and adjust the camera as needed.

Code: Select all
      var self = this;
      var viewport = whatever;
      //keep track of old viewport size so you can calculate deltas
      this._oldViewportWidth = viewport._bounds2d.x;
      this._oldViewportHeight = viewport._bounds2d.y;

      //hook into screen resize event
      this._oldResizeEvent = viewport._resizeEvent;
      viewport._resizeEvent = function(event) {, event);
         //calculate screen size deltas
         var viewportWidth = viewport._bounds2d.x;
         var viewportHeight = viewport._bounds2d.y;
         var widthDelta = viewportWidth - self._oldViewportWidth;
         var heightDelta = viewportHeight - self._oldViewportHeight;

         //push camera towards bottom-right to compensate for resized screen drifting towards top-left

         self._oldViewportWidth = viewportWidth;
         self._oldViewportHeight = viewportHeight;
Posts: 57
Joined: Thu Oct 24, 2013 7:20 pm

Return to Help & Questions

Who is online

Users browsing this forum: No registered users and 1 guest