can someone help with a "Touch to move" problem - Thanks
JamesZeppelin
Member Posts: 1,927
Im totally at a loss here
My charcater moves around perfectly so long as the scene is the same size as the camera
(both 480x320)
When i make the scene bigger and add camera control to the actor it works fine until the screen starts to scroll
Any idea why??
Here is what i use for movement
Hidden actor has two rules:
When touch is pressed
constrain game.movex to game.Touches.Touch 1.X
constrain game.movey to game.Touches.Touch 1.y
Actual character has:
When touch is pressed move to
x = game.movex
y = game.movey
There are a few other variables but only for drag and fluid rotation so i dont think they are effecting anything
My charcater moves around perfectly so long as the scene is the same size as the camera
(both 480x320)
When i make the scene bigger and add camera control to the actor it works fine until the screen starts to scroll
Any idea why??
Here is what i use for movement
Hidden actor has two rules:
When touch is pressed
constrain game.movex to game.Touches.Touch 1.X
constrain game.movey to game.Touches.Touch 1.y
Actual character has:
When touch is pressed move to
x = game.movex
y = game.movey
There are a few other variables but only for drag and fluid rotation so i dont think they are effecting anything
Comments
Create global game attributes called CameraX and CameraY.
Create a new Actor called CameraTracker. A simple box will do. Do NOT put any code in the Prototype.
Drag the CameraTracker Actor into the Scene, and place it just outside of view.
Double-click on the CameraTracker Actor in the Scene and click the padlock.
Add two Constrain Attribute behaviors to the Actor:
Constrain Attribute: game.CameraX To: Scene.Camera.Origin.X
Constrain Attribute: game.CameraY To: Scene.Camera.Origin.Y
So:
When touch is pressed
constrain game.movex to game.Touches.Touch 1.X + game.CameraX
constrain game.movey to game.Touches.Touch 1.y + game.CameraY
Hope this helps!
Joe
I'll give it a try
I'm curious.
So, does that mean if an actor is making some sort of change in relation to a scene attribute it cannot be a prototype?
I'm not 100% sure but now that the attribute is called "current scene" i thought you could make a prototype to drop in every scene
So if you need an Actor to react to a Scene Attribute, you have to make it a global Attribute first.
The Camera attributes are only accessible by instances.
First
Awesome!!!!
That did the trick and opened my eyes to something i have been missing.
Second
After i did what you said i put all of the rules you had suggested into a group box named "cameratracker" and dragged it over to "my attributes" on the left
Then i dargged that box back into a prototype and dropped the prototype into a a fresh scene and it worked!!
I'm guessing somewhere along the way they changed it so scene rules can identify they are in a new scene.
thanks man!!!!
EDIT
ok this may be a gltich
I cant actually go into the prototype and see that I even dragged the group of rules in....
But after i drag it into the scene it seems to work even though in the prototype pane it is seemingly empty?
I cant even see the rules in the scene unless i unlock it
Its as if the rule set wont be recognized until i make the PT into a instance again
very odd
yes, prototype will still be empty.
all the Rules will be in the instance
When touch is pressed
constrain game.movex to game.Touches.Touch 1.X + Scene.Camera.Origin.X
constrain game.movey to game.Touches.Touch 1.y + Scene.Camera.Origin.Y
(not on the prototype but on the instance) and save 2 constrains?!
The less number of actors you unlock for scene specific settings or scene attribute logic, the better.
thanks.
then i create a camera controller and ad constrain attribute game.camX to scene.camera.originX do the same for Y
now this is the part i get lost..
when touch is pressed
constrain game.movex to game.Touches.Touch 1.X + game.CameraX
constrain game.movey to game.Touches.Touch 1.y + game.CameraY
this is not what i have at al in my actors that i drag out of a menu into the game field..
i have a when dragging is true snap to grid rule which has a constrain attribute in it as follows..
self.position.x to (ceil((floor((game.mouse.position.x / game.cellwidth )*2))/2))* game.cellwidth (not my code i got this out of the snap to grid tutorial) and then a otherwise constrain attribute self.position.x to game.mouse.position.x (also for y)
i take these two tell it where and when to snap to grid etc however i hust cant figure out where to place it all.. perhaps my code is over complicated and im just getting lost
thanks
threadjack> Still can't get my "shoot from actor to mouse click" to work right with: vector to angle (game.mouse.x - self.position.x + game.CameraX, game.mouse.y - self.position.y + game.CameraY)
yes it did, it was in 2 posts but the above link is where i have what worked for me...
thanks!