Can´t load avatar to new room....

Post here your questions about the OpenSpace 1.x or notify bugs and suggestions.

Moderators: Lapo, Bax

fabianres@live.com.mx
Posts: 40
Joined: 14 Apr 2010, 17:40

Can´t load avatar to new room....

Postby fabianres@live.com.mx » 21 May 2010, 23:05

Im fairly new to this´

Im trying to create in the ISO world a control panel above the openspace window with a button(instance name:nayeli) that can
take my avatar toi a new map/room.

This is the code that I have applied:

nayeli.addEventListener(MouseEvent.CLICK, changeRoomie);


function changeRoomie(roomId:String, px:int = -1, py:int = -1, dir:int = -1):void
{
nextMap = {}
nextMap.px = px
nextMap.py = py
nextMap.dir = dir
{

nextMap.sfsRoomName = "Ranch (inside)"
nextMap.filename = "patioOutside.xml"
}


smartFox.joinRoom(nextMap.sfsRoomName)


}


....when I click it does change the map and room but without the avatar.
Its nowhere to be found.

Did I have to load it previously? Give it new coordinates in the new map?

Can someone explain what I´m doing wrong?
How would I proceed to write the code to correct this?

Any help is appreciated.

F.Enders
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 22 May 2010, 09:29

Actually I don't understand how your code can work: the changeRoomie listener triggered by the button click receives a MouseEvent parameter, not roomId, px, etc.
Anyway, changing room is not so automatic: first of all you have to join the corresponding SmartFoxServer room. On join ok event you have to load the new map. On map loading completion you have to re-create the avatar.
Check the Ranch example provided with OpenSpace: the click on the house doors makes a new map to be loaded just like you are trying to do.
Paolo Bax
The SmartFoxServer Team
fabianres@live.com.mx
Posts: 40
Joined: 14 Apr 2010, 17:40

Okay...

Postby fabianres@live.com.mx » 22 May 2010, 14:37

Yes it does work...maybe it is just switching the background, but in the output box it says "map rendered and parsed....now creating avatar" and that´s where it stalls....

Acually I have been looking into the onDoorClick function in the Ranch example.

Source Example:

function onDoorClick(evt:MouseEvent):void
{
trace("Door clicked")
trace("-> Destination map reference:", evt.currentTarget.params[0])
trace("-> Destination coordinates:", evt.currentTarget.params[1] + "," + evt.currentTarget.params[2])
trace("-> Avatar direction:", evt.currentTarget.params[3])

// Remove event listener on entrance, or memory won't be released
evt.currentTarget.removeEventListener(MouseEvent.CLICK, onDoorClick)

changeRoom(evt.currentTarget.params[0], evt.currentTarget.params[1], evt.currentTarget.params[2], evt.currentTarget.params[3])
}

function changeRoom(roomId:String, px:int = -1, py:int = -1, dir:int = -1):void
{
nextMap = {}
nextMap.px = px
nextMap.py = py
nextMap.dir = dir

switch (roomId)
{
case "patioOutside":
nextMap.sfsRoomName = "Ranch (inside)"
nextMap.filename = "patioOutside.xml"
break

case "dormInside":
nextMap.sfsRoomName = "Ranch (outside)"
nextMap.filename = "dormInside.xml"
break
}

smartFox.joinRoom(nextMap.sfsRoomName)
}


I actually used this to write my code. I think that that the problem lies in that I am not giving the avatar new coordinates on the map.

I don´t understand this part of the code:

changeRoom(evt.currentTarget.params[0], evt.currentTarget.params[1], evt.currentTarget.params[2], evt.currentTarget.params[3])

Can someone explain this part of the code to me...what is evt? what params are they referencing to (params[0])?

I´m gonna work on this until it is solved with all your help....and i´m gonna post the code here for everone. :)
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 24 May 2010, 07:30

I actually used this to write my code. I think that that the problem lies in that I am not giving the avatar new coordinates on the map.

If your map has one or more access points, this is not a problem.
I think your avatar is not showing because you have to call again the createMyAvatar method each time you load a new map.

I don´t understand this part of the code:

changeRoom(evt.currentTarget.params[0], evt.currentTarget.params[1], evt.currentTarget.params[2], evt.currentTarget.params[3])

Can someone explain this part of the code to me...what is evt? what params are they referencing to (params[0])?

In the Editor, some custom parameters have been assigned to the door's skin instance (in the Tile Editor, below the main editing view). Those parameters contain what you describe in those trace statements.[/quote]
Paolo Bax
The SmartFoxServer Team
fabianres@live.com.mx
Posts: 40
Joined: 14 Apr 2010, 17:40

I have figured it out

Postby fabianres@live.com.mx » 24 May 2010, 14:47

I spent half of yesterday figuring this out, and its pretty damn simple:

This is what I had:


function changeRoomie(roomId:String, px:int = -1, py:int = -1, dir:int = -1):void

The avatar can´t access those coordinates, they aren´t valid because t
hey are off the grid (in the negatives)...so you substitute them by positive integers....

function changeRoomie(roomId:String, px:int = 5, py:int = 5, dir:int = 5):void

Finally the avatar shows up in the iso world.

Thanks, I hope this is useful for everyone.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 24 May 2010, 21:21

The variables are set to -1 by default in the method signature, but they are supposed to be passed by the method's caller.
Paolo Bax
The SmartFoxServer Team

Return to “OpenSpace v1 discussions and help”

Who is online

Users browsing this forum: No registered users and 14 guests