RESOLVED: Very Strange WorldLimit Problem
by Deozaan · in Torque Game Builder · 07/18/2008 (7:14 pm) · 2 replies
EDIT: I've figured out the problem. I've changed the thread topic to state that this issue has been resolved. But I'm leaving the thread here in case someone else has similar issues. [/Edit]
I've been designing a simple space/shooter test and I had some starry background that moves along with the ship and wraps when it hits the world limit so that it seems endless without taking up too many resources.
In setting this up, I noticed that the tilemaps wouldn't wrap immediately upon hitting the Top or Left sides of the World Limit, but would instead wait until the center of the tilemap crossed the Top or Left side before it would wrap.
The strange thing is that the Bottom and Right sides will wrap as soon as they touch the Bottom or Right side of the World Limit.
I couldn't quite tell this was what was going on until I decided to randomize the stars in the tilemap when they wrapped. And that's when I noticed something really strange happening.
Here's the problem: The World Limit Callback is triggered when the object's bounding box crosses the limit, and my starry tilemap begins to randomize. But for some reason it doesn't wrap on the Top or the Left until the center of the object hits the world limit. In other words, once the bounding box hits the top or left limits, it will endlessly randomize the stars (because it's still hitting the limits) until it finally reaches halfway across the limit when it wraps to the other side. This makes things look very messy in action.
It's kind of hard to describe the problem in words or even to see in screenshots. So I've captured a video of it (flash) here:
World Limit Strangeness
I've been designing a simple space/shooter test and I had some starry background that moves along with the ship and wraps when it hits the world limit so that it seems endless without taking up too many resources.
In setting this up, I noticed that the tilemaps wouldn't wrap immediately upon hitting the Top or Left sides of the World Limit, but would instead wait until the center of the tilemap crossed the Top or Left side before it would wrap.
The strange thing is that the Bottom and Right sides will wrap as soon as they touch the Bottom or Right side of the World Limit.
I couldn't quite tell this was what was going on until I decided to randomize the stars in the tilemap when they wrapped. And that's when I noticed something really strange happening.
Here's the problem: The World Limit Callback is triggered when the object's bounding box crosses the limit, and my starry tilemap begins to randomize. But for some reason it doesn't wrap on the Top or the Left until the center of the object hits the world limit. In other words, once the bounding box hits the top or left limits, it will endlessly randomize the stars (because it's still hitting the limits) until it finally reaches halfway across the limit when it wraps to the other side. This makes things look very messy in action.
It's kind of hard to describe the problem in words or even to see in screenshots. So I've captured a video of it (flash) here:
World Limit Strangeness
#2
As usual, the solution is simply PEBKAC. :-D
And thanks to Jaimi, who also pointed out the problem after I'd already figured it out. I got an e-mail showing Jaimi's post but it's not showing here. My guess is that it was eaten or Jaimi deleted it.
07/18/2008 (9:19 pm)
Okay, it seems as though my math was wrong. I was sending it to a position that was still triggering the world limit callback so it was constantly wrapping back and forth, but it only visually displayed it on one side.As usual, the solution is simply PEBKAC. :-D
And thanks to Jaimi, who also pointed out the problem after I'd already figured it out. I got an e-mail showing Jaimi's post but it's not showing here. My guess is that it was eaten or Jaimi deleted it.
Torque Owner Deozaan
function backgroundClass::onWorldLimit(%this, %mode, %limit) { switch$ (%limit) { case "left": %this.paintStars(); // this randomizes the tilemap %this.setPositionX(%this.getPositionX() + (%this.getSizeX() * 2)); case "right": %this.paintStars(); // this randomizes the tilemap %this.setPositionX(%this.getPositionX() - (%this.getSizeX() * 2)); case "top": %this.paintStars(); // this randomizes the tilemap %this.setPositionY(%this.getPositionY() + (%this.getSizeY() * 2)); case "bottom": %this.paintStars(); // this randomizes the tilemap %this.setPositionY(%this.getPositionY() - (%this.getSizeY() * 2)); } }