Citrus-Engine
Citrus-Engine copied to clipboard
switchToTarget doesn't work correctly with classic display list
Hi, i´m trying run the example camera movement using Sprite camera instead Starling camera. I've just modified the classes just for run the example using the display list. When I run the example the initial point of the camera is always 0,0 not the current target.
Thank you,
Hi, have you made sure to call camera.reset(); this forces the camera into its target position instantaneously, no matter what the easing values are, and should be called when you init your game so that the camera doesn't start at 0,0 . If its not in the example, then it should be. If you didn't forget it and you are calling camera.reset() , can you post some code just so I can test your camera setup and the switchToTarget in the same way you are using them?
Hi again! Yes, I call reset when I setup the camera. At this point everything is ok, the camera follows the target from the begining, but when I call switchToTarget the start point always is 0,0.
The follow code doesn't work:
package game
{
import flash.geom.Point;
import flash.geom.Rectangle;
import citrus.core.State;
import citrus.input.controllers.Keyboard;
import citrus.objects.platformer.box2d.Hero;
import citrus.objects.platformer.box2d.Platform;
import citrus.physics.box2d.Box2D;
import citrus.view.spriteview.SpriteCamera;
public class GameState extends State
{
private var _physics:Box2D;
private var _floor:Platform;
private var _hero:Hero;
private var _hero2:Hero;
private var _gameCamera:SpriteCamera;
public function GameState()
{
super();
}
override public function initialize():void {
super.initialize();
_physics = new Box2D("box2d");
_physics.visible = true;
add(_physics);
_floor = new Platform("floor", {x: 1024, y: 1050, width: 2048, height: 300, group: 1000});
_hero = new Hero("hero", {x: 400, y: 800, width: 40, dynamicFriction: 10, height: 80, group: 1000});
_hero2 = new Hero("hero2", {x: 800, y: 800, width: 40, dynamicFriction: 10, height: 80, group: 1000});
add(_hero);
add(_hero2);
add(_floor);
_gameCamera = view.camera as SpriteCamera;
_gameCamera.setUp(_hero,new Rectangle(0, 0, 2048, 1200), new Point(0.5, 0.5), new Point(0.05, 0.05));
_gameCamera.target = _hero;
_gameCamera.reset();
var kb:Keyboard = _ce.input.keyboard;
kb.addKeyAction("switch", Keyboard.Q);
}
override public function update(timeDelta:Number):void
{
super.update(timeDelta);
if (_input.justDid("switch",_input.keyboard.defaultChannel))
{
_input.startRouting(1000);
var newTarget:Object = _gameCamera.target == _hero ? _hero2 : _hero;
_gameCamera.switchToTarget(newTarget,50,function():void
{
_input.stopRouting();
_input.keyboard.defaultChannel = newTarget.inputChannel;
});
}
}
}
}
But if I use Starling everything is OK:
package game
{
import flash.geom.Point;
import flash.geom.Rectangle;
import citrus.core.starling.StarlingState;
import citrus.input.controllers.Keyboard;
import citrus.objects.platformer.box2d.Hero;
import citrus.objects.platformer.box2d.Platform;
import citrus.physics.box2d.Box2D;
import citrus.view.starlingview.StarlingCamera;
public class GameState extends StarlingState
{
private var _physics:Box2D;
private var _floor:Platform;
private var _hero:Hero;
private var _hero2:Hero;
private var _gameCamera:StarlingCamera;
public function GameState()
{
super();
}
override public function initialize():void {
super.initialize();
_physics = new Box2D("box2d");
_physics.visible = true;
add(_physics);
_floor = new Platform("floor", {x: 1024, y: 1050, width: 2048, height: 300, group: 1000});
_hero = new Hero("hero", {x: 400, y: 800, width: 40, dynamicFriction: 10, height: 80, group: 1000});
_hero2 = new Hero("hero2", {x: 800, y: 800, width: 40, dynamicFriction: 10, height: 80, group: 1000});
add(_hero);
add(_hero2);
add(_floor);
_gameCamera = view.camera as StarlingCamera;
_gameCamera.setUp(_hero,new Rectangle(0, 0, 2048, 1200), new Point(0.5, 0.5), new Point(0.05, 0.05));
_gameCamera.target = _hero;
_gameCamera.reset();
var kb:Keyboard = _ce.input.keyboard;
kb.addKeyAction("switch", Keyboard.Q);
}
override public function update(timeDelta:Number):void
{
super.update(timeDelta);
if (_input.justDid("switch",_input.keyboard.defaultChannel))
{
_input.startRouting(1000);
var newTarget:Object = _gameCamera.target == _hero ? _hero2 : _hero;
_gameCamera.switchToTarget(newTarget,50,function():void
{
_input.stopRouting();
_input.keyboard.defaultChannel = newTarget.inputChannel;
});
}
}
}
}
Thankyou very very much! I love citrus! hehe
@exlex84 , if you are still there can you let me know if the latest source version fixed it, I finally got to look at that issue. thank you.