Help with scaling using fixed projection

#1

Hi!

Okay, I’m making a game which I need to work on various re-scaled screen sizes without distorting the images. Right now I have it so that images are scaled (both their x and y sizes) according to the height of the window, which is the desired behaviour.

Here’s what I’d like it to look like:

Notice how the labels are positioned at 25%, 50% and 75% of the window height.

But when I resize the screen, this happens:

The labels stay in the correct positions (25%, 50%, and 75% of the window height) but the hands disappear! Both the labels and the sprites are part of the same game object.

Another image:


The hands change scale correctly, as far as i can tell, but even though their y-position is always 0 (both the game object and the sprite itself), they seem to drift away from the label.

here’s the code I’m using to rescale the sprites and move everything to the right place.

> local function callback(self, event, data)
> 	if event == window.WINDOW_EVENT_RESIZED then
> 		self.screenwidth = data.width
> 		self.screenheight = data.height
> 	end
> 	print(self.screenwidth.." "..self.screenheight)
> 	self.scale = (self.screenheight*0.00060)
> 	
> 	for i=1,6 do
> 		go.set_scale(self.scale, "/arm"..i.."#sprite")
> 		local aa = go.get("/arm"..i.."#sprite", "size.x")
> 		self.armsize = aa*self.scale
> 		print(self.armsize.."scaled armsize")
> 	end
> 
> 	--scale and position players
> 	self.topl = vmath.vector3(100, self.screenheight*0.75, 0.4)
> 	self.midl = vmath.vector3(100, self.screenheight*0.5, 0.4)
> 	self.botl = vmath.vector3(100, self.screenheight*0.25, 0.4)
> 	self.topr = vmath.vector3(self.screenwidth-(100), self.screenheight*0.75, 0.4)
> 	self.midr = vmath.vector3(self.screenwidth-(100), self.screenheight*0.5, 0.4)
> 	self.botr = vmath.vector3(self.screenwidth-(100), self.screenheight*0.25, 0.4)
> 	go.set_position(self.topl, "/pl1")
> 	go.set_position(self.midl, "/pl3")
> 	go.set_position(self.botl, "/pl5")
> 	go.set_position(self.topr, "/pl2")
> 	go.set_position(self.midr, "/pl4")
> 	go.set_position(self.botr, "/pl6")
> end

any help??

0 Likes

#2

…Okay I have removed the “scaling” part of the code and it’s still not working. The labels automatically go where they should, the sprites keep moving. A good summary of my problem would be: I would like the sprites to be scaled/moved the same way as the labels in my project.

0 Likes

#3

Zip the project and upload here, I’d take a look tomorrow.

0 Likes

#4

Pianner 2.zip (4.6 MB)

thanks! it’s a very small project. I am sure you will understand it.

0 Likes

#5

Okay… I think I have the problem solved here, just not sure if it’s a bug or not (when using stretch projection).

This code correctly places a GO with a label in the middle of the Y axis when resizing a window (label position 0,0,0):

self.height.y = data.height/2 – set an object to this Y co-ordinate to get it in the middle.

But this code works for a GO object with a sprite (sprite position is 0,0,0):

self.ss = vmath.vector3(data.width, data.height, 1) – gets new screen size
if self.iss == nil then
self.iss = vmath.vector3(data.width, data.height, 1) – sets initial screensize
end
self.screensize.y = self.iss.y+(self.iss.y/self.ss.y) – middle of the screen (for an object with a sprite)

0 Likes

#6

Hi. A bit later than promised, but here is my take on it.

Modified project is here.
Pianner.zip (4.5 MB)

3 Likes