can someone help with a "Touch to move" problem - Thanks

JamesZeppelinJamesZeppelin Member Posts: 1,927
edited November -1 in Working with GS (Mac)
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

Comments

  • firemaplegamesfiremaplegames Member Posts: 3,211
    You need to account for the camera offset.

    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
  • JamesZeppelinJamesZeppelin Member Posts: 1,927
    Thanks
    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
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Prototypes don't have access to Scene Attributes, only instances do.

    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.
  • JamesZeppelinJamesZeppelin Member Posts: 1,927
    Ok cool,

    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
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Cool!

    yes, prototype will still be empty.

    all the Rules will be in the instance
  • POMPOM Member Posts: 2,599
    JamesZeppelin said:

    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

    im on the same boat here, i was wondering, cant you just directly use :

    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?!
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    p-o-m said:
    im on the same boat here, i was wondering, cant you just directly use :
    ...
    (not on the prototype but on the instance) and save 2 constrains?!

    You could but if you have to do that with multiple actors it will be a pain to find which of your actor instances are unlocked if you have to change behaviors around. I've scene many people unlocking instances for no reason. Not only can this bloat your game because now the scene has to keep track of all the behaviors for that unlocked actor, but it will take a lot of time for you (or someone else) to debug if something goes wrong.

    The less number of actors you unlock for scene specific settings or scene attribute logic, the better.
  • POMPOM Member Posts: 2,599
    got it!
    thanks.
  • chicopchicop Member Posts: 263
    Ok so i create 2 new booleans named camX and camY

    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
  • forkliftforklift Member Posts: 386
    I wouldn't think the CamX, CamY attributes would be booleans, but hey, what do I know...

    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)
  • chicopchicop Member Posts: 263
    should be integer it seems
  • forkliftforklift Member Posts: 386
    Did it work with integers then?
  • chicopchicop Member Posts: 263
    http://gamesalad.com/forums/topic.php?id=11890

    yes it did, it was in 2 posts but the above link is where i have what worked for me...

    thanks!
Sign In or Register to comment.