need spawning help from an experienced user
iDeveloperz
Member Posts: 1,169
Hi everyone, with some help from VML, i'm doing a game but the cans wont spawn correctly as the camera goes up. When its the start of the game the camera is perfect but after it starts to move the pawn point is lower down from where the user clicks.
Comments
what you need to do is add the camera offset to your touch x and y position.
you can get the camera offset from a scene scoped actor. it's not available to prototype actors (why the hell not??!)
so what most people do is create two game attributes called cameraOffsetX and cameraOffsetY (both reals)
then in an off camera actor (usually called something like game controller or scene controller etc) you constrain the game attributes defined above to the scene camera offset x and y.
that in essence "lifts" the camera origin x and y out of scene scope and up into global scope where all your prototype actors can see them.
then add those offsets to any touch coordinates you are using to spawn your actor.
touch.x + cameraoffsetx
touch.y + cameraoffsety
Create a global game attribute called 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 a Constrain Attribute behavior to the Actor:
Constrain Attribute: game.CameraY To: Scene.Camera.Origin.Y
Now, any time you spawn a new actor, you will add game.CameraY to the Y Position.
So:
Spawn Actor
[new Actor]
At: Touch.X, Touch.Y + game.CameraY
Can the camera tracker go anywhere outside the view? or on top of it, outside?
Thank you for replying.
Edit: Sorry I cant do it. VML did something that spawns the cans for me and i don't know whats what.
You're not dumb.
Dig around in the code, you should be able to find the Spawn Actor behavior somewhere. It might also be in one of the instances on the stage.
Imagine you have an iPad and your holding your finger down. - A 50% Opacity can appears. When you let go it goes 100% and (By changing actors). Whilst its 50% you can drag it around by the way. So you just let go and the new actor fell until it collides with the table at the bottom. Now you keep on adding cans. When it moves up. You go to click the screen but the can spawns say 100 pixels below where you spawned. To be honest I cant explain. I can send anyone the built version for Mac OSX. if you email me... ideveloperz@me.com
Once again i'm sorry for being stupid.
And I understand your spawning issue.
But trust me, you need to do what ORBZ and I mention above. You need to account for the camera offset. Perhaps VML can help you with it.
You have to add the distance that the camera has moved to your Spawning position. Or the can will appear in the wrong place.
when touch is pressed
spawn actor:
Can overlay
Direction 0 - Actor
Position game.touch.touch1.x _ game.touch.touch1.y
This is one an invisible actor that covers the whole iPad screen.
Your spawn Rule needs to look like this:
when touch is pressed
spawn actor:
Can overlay
Direction 0 - Actor
Position game.touch.touch1.x _ game.touch.touch1.y + game.cameraY <----- YOU NEED TO ADD THIS
Follow my post above about creating a cameraTracker actor or it will not work.
When the CanOverlay was being created it was constraining it to touchY instead of touchY+cameraOffset