Game Development Community

Telling if my enemy is on screen.

by Matthew Harris · in Torque Game Builder · 10/16/2006 (12:22 am) · 6 replies

Hi. I have an enemy that is a static sprite. Is there a way to tell if its visible in the screen. Thanks in advanced. Matthew.

#1
10/16/2006 (2:24 am)
From the reference doc:

getIsWindowPoint(%worldX, %worldY)
Purpose
Gets whether or not a world point is within the bounds of the window.
Syntax
%worldX - Float
The x coordinate of the world point.
%worldY - Float
The y coordinate of the world point.
Return Value - Bool
True if the world point is in the window, false otherwise.
#2
10/16/2006 (4:58 pm)
Thanks.
#3
10/17/2006 (2:08 pm)
You probably want to check all four corners of the object for this. You can get the corners and then try getIsWindowPoint for each. Here is how you would get the current world point of each of the corners:

// get top left corner and bottom right corner
%topLeft = %this.getWorldPoint("-1 -1");
%bottomRight = %this.getWorldPoint("1 1");

// get top right corner and bottom left corner from above results
%topRight = getWord( %bottomRight, 0 ) SPC getWord( %topLeft, 1 );
%bottomLeft = getWord( %topLeft, 0 ) SPC getWord( %bottomRight, 1 );

-Thomas
#4
10/25/2006 (8:31 pm)
I tried, but when I do this for my enemies :

// get top left corner and bottom right corner
	%topLeft = %this.getWorldPoint("-1 -1");
	%bottomRight = %this.getWorldPoint("1 1");

	// get top right corner and bottom left corner from above results
	%topRight = getWord( %bottomRight, 0 ) SPC getWord( %topLeft, 1 );
	%bottomLeft = getWord( %topLeft, 0 ) SPC getWord( %bottomRight, 1 );
	
	if(getiswindowpoint(%topRight))
	{
		echo("plop");
	}

The console return :
Unable to find function getIsWindowPoint

I've done something wrong ?
#5
10/25/2006 (8:55 pm)
That function is part of the SceneWindow class. Try SceneWindow2D.getIsWindowPoint(), or (whatever the name of your scenewindow is) .getIsWindowPoint()
#6
10/25/2006 (9:22 pm)
Thanks Joe, it works ^^