Can't get background to show

Ask a Question related to Macromedia Director 3D, Design and Development.

  1. #1

    Default Can't get background to show

    I'm very new to this, but I've been able to piece together code from several
    sources to get the basic functionality I want. But somewhere along the way
    I've killed my ability to have a background texture show up. Can anybody take
    a look at this code and tell me where my problem is? Sorry, it's a bit long.

    -Spaz

    -- create properties for when arrow keys are pressed
    -- properties will either be TRUE or FALSE values
    property pLeftArrow, pRightArrow, pDownArrow, pUpArrow

    property p3dMember -- reference to 3D cast member
    property pSprite -- reference to the 3D sprite
    property pCharacter -- reference to the character in the 3D world
    property pCharBoundingBox -- reference to character's bounding box

    property pMouseInitPos, pCamera


    on beginSprite me

    -- initiate properties
    p3dMember = sprite(me.spriteNum).member
    p3dMember.resetWorld()

    pSprite = sprite(me.spriteNum)
    pCamera = pSprite.camera

    createCharacterBoundingBox
    setUpCamera

    --set background "texture"
    p3dMember.newtexture("backdrop", #fromCastMember, member("sky"))
    p3dMember.camera(1).insertBackdrop(1, p3dMember.texture("backdrop"),
    point(0,0),0)

    -- register the member for regular timeMS events in order to respond to
    -- user input and resolve camera collisions
    -- i.e. after specified time segments activate collisionDetect handler
    p3Dmember.registerForEvent(#timeMS,#collisionDetec t,me,1000,10,0)

    setMouseLoc(160,120)
    end


    on createCharacterBoundingBox
    -- create modelResource
    charModRes = p3Dmember.newModelResource("charModRes",#box)
    charModRes.height = 1
    charModRes.width = 1
    charModRes.length = 3

    -- create model and reference to it
    pCharBoundingBox = p3Dmember.newmodel("CharBoundingBox",charModRes)

    pCharBoundingBox.transform.position = vector(0, 0,
    0)------------------------------
    pCharBoundingBox.transform.rotation = vector(0, 0, 0)

    boxShader = p3Dmember.newshader("transparentShad",#standard)
    boxShader.transparent = TRUE
    -- set opacity of shader 0 is invisible - only works if transparent prop =
    TRUE
    boxShader.blend = 50
    pCharBoundingBox.shaderlist = p3Dmember.shader("transparentShad")
    end





    on setUpCamera

    -- create 2 new cameras
    frontCam = p3Dmember.newCamera("frontCam")
    pCamera = p3Dmember.newCamera("pCamera")

    -- frontCam settings
    -- set up the camera's vertical viewing angle (D8.5)
    --frontCam.projectionAngle = 90

    -- position the camera
    frontCam.transform.position = vector(0, 0, 0)

    -- set rotation of camera
    frontCam.transform.rotation = vector(90,0,80)

    -- pCamera settings
    -- set postion of the camera to position of the box
    pCamera.transform.position =
    pCharBoundingBox.transform.position--------------------

    -- set rotation of camera
    pCamera.transform.rotation = vector(70,0,180)

    -- move camera up and back
    pCamera.translate(0,30,300)

    -- set the camera of the sprite to the frontCam
    pSprite.camera = p3Dmember.camera("frontCam")

    -- make cameras children of the box
    pCharBoundingBox.addChild(frontCam,#preserveParent )-------------------
    pCharBoundingBox.addChild(pCamera,#preserveParent)--------------------

    end


    on changeCamera

    -- check the sprites camera and switch
    if pSprite.camera = p3Dmember.camera("pCamera") then
    pSprite.camera = p3Dmember.camera("frontCam")
    else
    pSprite.camera = p3Dmember.camera("pCamera")
    end if

    end




    on collisionDetect me

    -- create a list to store collision data created by modelsUnderRay
    -- cast ray to left
    collisionList = p3Dmember.modelsUnderRay(pCharBoundingBox.worldPos ition,
    -pCharBoundingBox.transform.yAxis,#detailed)

    -- if models picked up by ray, then activate checkForCollion
    -- handler and send the collisionList as a parameter
    if (collisionList.count) then me.checkForCollision(collisionList[1])

    -- cast ray to right
    collisionList = p3Dmember.modelsUnderRay(pCharBoundingBox.worldPos ition,
    pCharBoundingBox.transform.yAxis,#detailed)

    -- if models picked up by ray, then check for collision
    if (collisionList.count) then me.checkForCollision(collisionList[1])

    -- cast ray forward
    collisionList = p3Dmember.modelsUnderRay(pCharBoundingBox.worldPos ition,
    pCharBoundingBox.transform.xAxis,#detailed)

    -- if models picked up by ray, then check for collision
    if (collisionList.count) then me.checkForCollision(collisionList[1])

    -- cast ray backward
    collisionList = p3Dmember.modelsUnderRay(pCharBoundingBox.worldPos ition,
    -pCharBoundingBox.transform.xAxis,#detailed)

    -- if models picked up by ray, then check for collision
    if (collisionList.count) then me.checkForCollision(collisionList[1])

    end


    on checkForCollision me, collisData

    -- grab the #distance value from the CollisionList
    dist = collisData.distance

    -- check if distance is less than width of bounding box
    if (dist < pCharBoundingBox.resource.width ) then

    -- get distance of penetration
    diff = pCharBoundingBox.resource.width - dist

    -- calculate vector perpendicular to the wall's surface to move the
    character
    -- using the #isectNormal property
    tVector = collisData.isectNormal * diff

    -- move the character in order to resolve the collision
    pCharBoundingBox.translate(tVector,#world)

    end if

    end


    on keyDown

    -- check to see which key has been pressed
    -- and set the property relating to that key to TRUE
    if keypressed(123) then pLeftArrow = TRUE -- 123 = left arrow key
    if keypressed(124) then pRightArrow = TRUE -- 124 = right arrow key
    if keypressed(125) then pDownArrow = TRUE -- 125 = down arrow key
    if keypressed(126) then pUpArrow = TRUE -- 125 = up arrow key

    -- if 'r' key pressed, return character to starting position
    if keypressed("r") then resetCharacter

    -- if 'c' key is pressed, then switch camera
    if keypressed("c") then changeCamera

    end

    on keyUp
    -- when the arrow keys are released, set the properties to FALSE
    pLeftArrow = FALSE
    pRightArrow = FALSE
    pUpArrow = FALSE
    pDownArrow = FALSE
    end





    on resetCharacter
    pCharBoundingBox.transform.position = vector(0, 0, 0)
    end



    on enterFrame (me)
    pMouseInitPos = the mouseLoc
    -- For a 320x240 stage:
    -- check if cursor went to left edge of screen
    if pMouseInitPos[1] < 1 then
    setMouseLoc(318, the mouseLoc[2])
    pMouseInitPos = the mouseLoc
    end if
    -- check if cursor went to right edge of screen
    if pMouseInitPos[1] > 318 then
    setMouseLoc(1, the mouseLoc[2])
    pMouseInitPos = the mouseLoc
    end if
    -- check if cursor went to top edge of screen
    --if pMouseInitPos[2] < 1 then
    -- setMouseLoc(the mouseLoc[1], 238)
    -- pMouseInitPos = the mouseLoc
    --end if
    -- check if cursor went to bottom edge of screen
    --if pMouseInitPos[2] > 238 then
    -- setMouseLoc(the mouseLoc[1], 1)
    -- pMouseInitPos = the mouseLoc
    --end if
    end enterFrame


    on exitFrame
    mouseNewPos = the mouseLoc
    mouseDiff = pMouseInitPos - mouseNewPos
    rotateAmountH = mouseDiff[1] * 1.6
    rotateAmountV = mouseDiff[2] * 0.1

    pCharBoundingBox.rotate(pCharBoundingBox.worldPosi tion,vector(0,0,1),rotateAmoun
    tH,#world)
    pCamera.transform.rotate(rotateAmountV,0,0)
    pMouseInitPos = mouseNewPos

    -- if the right arrow is pressed,
    -- move the character 5 pixels to the right
    if pRightArrow then pCharBoundingBox.translate(0,2,0)

    -- if the right arrow is pressed,
    -- ove the character 5 pixels to the left
    if pLeftArrow then pCharBoundingBox.translate(0,-2,0)

    -- if the up arrow is pressed,
    -- move the character 5 pixels along the y-axis
    if pUpArrow then pCharBoundingBox.translate(-1,0,0)

    -- if the down arrow is pressed,
    -- move the character -5 pixels along the y-axis
    if pDownArrow then pCharBoundingBox.translate(1,0,0)


    -- move along terrain
    -- create reference for terrain (ground)
    terrain = p3Dmember.model("Rectangle")------------------------------ Change
    to whatever base model name is

    -- store box's position
    charPos = pCharBoundingBox.worldPosition
    charPos.y = charPos.y - 2

    -- cast a ray down
    collisData = p3Dmember.modelsUnderRay(charPos,vector(0,0,-1),#detailed)

    -- if model is picked up on ray.
    if collisData.count then

    -- store total no of models detected by the ray
    totalCount = collisData.count

    repeat with modelNo = 1 to totalCount

    -- check if over the terrain model
    if (collisData[modelNo].model = terrain) then

    terrainPos = collisData[modelNo].isectPosition

    -- find out the distance the character should move up or down
    diff = (terrainPos.z - pCharBoundingBox.worldPosition.z)+2

    -- move the character
    pCharBoundingBox.translate(0,0,diff,#world)


    end if

    end repeat

    end if

    end exitFrame

    Spastuscat Guest

  2. Similar Questions and Discussions

    1. How to force background images to show
      When I place the gif as a background object, it will only print if my browser is set to print background images. Is there an alternative way I could...
    2. why the table cannot show background image?
      please help! Thanks so much!!! When i Add the image as background inside a row in the table, the background image cannot be shown after IE...
    3. Matching Jpeg background with Page Background?
      In article <bgpgfq$3sh$1@forums.macromedia.com>, "JohnnyA" webforumsuser@macromedia.com wrote: You can't, because (1) JPEG compression almost...
    4. Background Image for cell in DWMX, it doesn't show up in Preview!
      On Mon, 28 Jul 2003 03:52:14 +0000 (UTC), "Beatleman" webforumsuser@macromedia.com wrote: That's because the background is applied to the...
    5. background images don't show
      Tim: It's a known misbehavior of DW4. Are you using DMX? -- Murray --- ICQ 71997575 Team Macromedia Volunteer for Dreamweaver MX (If you...
  3. #2

    Default Re: Can't get background to show

    Just a quick look. It seems that you assigned the "sky" background to the default camera and then made two new cameras. Could it be that you need to assign the background to your other cameras?
    John Craig Freeman Guest

  4. #3

    Default Re: Can't get background to show

    That's what I figured, but how do I apply a background to a specific camera? The only code I've found requires an "index" instead of the name of a camera.

    -Spaz
    Spastuscat Guest

  5. #4

    Default Re: Can't get background to show

    Hi Spaz, try

    -- create backdrop texture from bitmap
    backdropTexture = sprite(me.spriteNum).newtexture("backdrop",
    #fromCastMember, member("sky"))
    -- add backdrop to frontCam
    frontCam.camera.addBackdrop(backdropTexture,point( 0,0),0)


    John Craig Freeman Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139