I've a little positioning problem


(Bora Kasap) #1

I gave a break to flashpunk for working with javascript but making games in javascript looks like too much hard… So, i came back…

But i have a disturbing problem, i’m so confused…

I added Comments to the code about my problem

package
{
	import net.flashpunk.Entity;
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.graphics.Text;
	import net.flashpunk.utils.Draw;
	import net.flashpunk.utils.Input;

	/**
	 * ...
	 * @author Bora Kasap
	 */

	public class ComboView extends Entity
	{
		private var _combomin:int = 0;
		private var _timemin:int = 300;
		private var _timermin:int = 0;
		
		private var _minbox:Text;
		private var _graphicfx:Image;
		
		public function ComboView()
		{
			this.x = 50; //i'm setting x
			this.y = 50; //i'm setting y as you see
			refreshMin(); //i'm drawing a text at this position "Min: 1"
		}
		
		private function refreshMin():void
		{
			this.graphic = _graphicfx = new Text("Min: " + _combomin.toString(), this.x, this.y);
		}
		
		public function min():void
		{
			_combomin++;
			refreshMin();
			_timermin = _timemin;
		}
		
		override public function update():void 
		{
			super.update();
			if (_timermin > 0) _timermin--;
			else if (_combomin > 0)
			{
				_combomin = 1;
				refreshMin();
			}
		}
		
		override public function render():void 
		{
			super.render();
			Draw.rect(this.x, this.y, this._timermin, 3); //I'm not changing x and y positions of this entity but rect(combo timer bar) and text not positioning on same coordinates like in the image. Actually rect drawing on true position but text positioning on x:100 y:100 and i can't understand why this is happening
		}
	}
}


(azrafe7) #2

It’s probably due to the fact that graphic coords are relative to Entity's position, while Draw works with World coords.

So you’re basically setting the text to render at (this.x + this.x), (this.y + this.y) = (50 + 50), (50 + 50) = 100, 100, and drawing the rect at this.x, this.y = 50, 50.


(Martí Angelats i Ribera) #3

I see the same problem. Try to change this line:

this.graphic = _graphicfx = new Text("Min: " + _combomin.toString(), 0, 0);

(Bora Kasap) #4

ohh thanks guys, so i’ve just realized that functions have different description in functions.

For draw: (x:Number //X position.)

For text: (x:Number //X offset.)