Hi
I'm making an isometric game, using Tiled as a map editor.
Currently I'm adding a minimap, and have come across a few things I'm wondering about.
1. how do i add a unique mouseDown function for each viewport? Right now they seem to override each other.
2. how do I get the correct screen position of the viewport, when bottom, right, left or top are set?
viewport.screenPosition() does not give the correct values.
3. how can I hide a map layer from being drawn?
Isn't that what the .hide() and .show() functions should be used for?
I have lots of other questions, but I'll make relevant posts for those.
Viewports, minimaps, and questions
- coolbloke1324
- Posts: 181
- Joined: Mon Jan 23, 2012 5:20 pm
Re: Viewports, minimaps, and questions
Hey ya!seltar wrote:Hi
I'm making an isometric game, using Tiled as a map editor.
Currently I'm adding a minimap, and have come across a few things I'm wondering about.
1. how do i add a unique mouseDown function for each viewport? Right now they seem to override each other.
2. how do I get the correct screen position of the viewport, when bottom, right, left or top are set?
viewport.screenPosition() does not give the correct values.
3. how can I hide a map layer from being drawn?
Isn't that what the .hide() and .show() functions should be used for?
I have lots of other questions, but I'll make relevant posts for those.
1) Good question. I never considered that anyone would want to know what viewport was the origin of the mouse event. I'll need to look at the event code and work out if it's currently possible and if not, write some new code to make it possible.
2) Hmm. That should work. If it's not then it is a bug. I will create a test project and see what the issue is. The UI (and positioning system) was recently updated and I might have missed a section related to screen position.
3) Any entity or IgeEntity derivitive can be hidden via .hide(). Is that not working? What class type are you calling .hide() on?
Re: Viewports, minimaps, and questions
Hi, thanks for the reply.
1 & 2)
I've extended the engine a little bit to get access to the raw data from the Tiled maps.
Regarding getting the position of the viewport using .screenPosition(), I ended up doing something like this to detect which viewport was pressed.
...
3)
I had loaded a Tiled map, and was trying to hide a layer using .hide();
I had to add this to the tick method in IgeTextureMap, which isn't the best solution, but it solved my problem for now.
1 & 2)
I've extended the engine a little bit to get access to the raw data from the Tiled maps.
Regarding getting the position of the viewport using .screenPosition(), I ended up doing something like this to detect which viewport was pressed.
Code: Select all
// set up viewport
self.minimap = new IgeViewport()
.id('minimap')
.depth(2)
.autoSize(false)
.width(300)
.height(150)
.right(10)
.bottom(10)
.borderWidth(1)
.borderColor('#ffffff')
.scene(self.mainScene)
.drawBounds(false)
.drawMouse(false)
.mount(ige)
.hide();
Code: Select all
// map.widthPx and map.heightPx are just [number of tiles wide] * [tilewidth] and [number of tiles high] * [tileheight]
// center and scale minimap
var scaleX = self.minimap.width() / map.widthPx,
scaleY = self.minimap.height() / map.heightPx;
// find smallest scale, to fit the entire map into the tiny view
var scale = Math.min(scaleX, scaleY);
self.minimap.mouseDown(function(mouseEvent, state){
// Get the relative mouse position
var x = -1 * (ige._geometry.x - mouseEvent.clientX - self.minimap.right() - self.minimap.width()),
y = -1 * (ige._geometry.y - mouseEvent.clientY - self.minimap.bottom() - self.minimap.height());
// check if we're inside the minimap
if(x >= 0 && x < self.minimap.width() && y >= 0 && y < self.minimap.height()){
// x: -width/2 to width/2, y: 0 to height
x -= self.minimap.width() / 2;
// move the main viewport camera to the selected location
self.viewport.camera.panTo(new IgePoint(x / scale, y / scale), 200);
}
});
I had loaded a Tiled map, and was trying to hide a layer using .hide();
I had to add this to the tick method in IgeTextureMap, which isn't the best solution, but it solved my problem for now.
Code: Select all
// Don't render hidden layers
if(this.isHidden()){
return false;
}
Re: Viewports, minimaps, and questions
Although, I might be overcomplicating things.
If I could render a viewport to texture after the map has loaded, I could make my own Minimap entity that could have it's own mouse events etc.
The map doesn't need to be redrawn each frame if I could just have it as an image.
If I could render a viewport to texture after the map has loaded, I could make my own Minimap entity that could have it's own mouse events etc.
The map doesn't need to be redrawn each frame if I could just have it as an image.
- coolbloke1324
- Posts: 181
- Joined: Mon Jan 23, 2012 5:20 pm
Re: Viewports, minimaps, and questions
I am currently investigating the screenPosition() issue. It appears that it works on everything except viewports correctly.
- coolbloke1324
- Posts: 181
- Joined: Mon Jan 23, 2012 5:20 pm
Re: Viewports, minimaps, and questions
OK I've found the screenPosition bug, it relates only to *scaled* viewports (those whose camera's are scaled).
Fixing now...
Fixing now...
- coolbloke1324
- Posts: 181
- Joined: Mon Jan 23, 2012 5:20 pm
Re: Viewports, minimaps, and questions
OK I've pushed a fix to the screen position bug on viewports to the dev branch.
Re: Viewports, minimaps, and questions
Thank you so much!