sprite move to stylus))

Discussion in 'Questions (Windows Mobile)' started by Byak@, Aug 18, 2008.

  1. Byak@

    Byak@ Active Member Licensed User

    i want:
    sprite moving to place,when i press mouse key or tap stylus.
    but my algoritm doesnot work

    it is my sourse.i'm spend many time for it.sprite move but not correct
    Code:
    Sub Globals
    stop=
    1
    End Sub

    Sub App_Start
    Sip(false)
    game.Show
    gamewin.New1(
    "game",0,30,game.Width,game.Height-30)
    gamewin.DrawBackgroundImage(AppPath&
    "\2.jpg")
    muxa.New2(AppPath&
    "\1.bmp",8,16,15,8)
    muxa.FrameSpeed=
    1
    muxa.X=
    0
    muxa.Y=
    100
    muxa.Velocity=
    5
    muxa.Direction=
    90
    gamewin.SpriteAdd(muxa.Value)
    tanim.Enabled=
    true
    gamewin.Tick
    End Sub

    Sub tanim_tick
    gamewin.Tick
    If stop=1 Then tanim.Enabled=false
    End Sub


    Sub gamewin_NoCollisionMouse
    i=
    Round((ASin(gamewin.X/Sqrt((gamewin.X)^2+(gamewin.Y)^2)))*180/cpi)

    l1.Text=gamewin.X&
    "-"&muxa.X&" "&gamewin.Y&"-"&muxa.y&" "&i
    If gamewin.y>muxa.y Then muxa.Direction=90-i
    If gamewin.y<muxa.y Then muxa.Direction=i+270
    'muxa.Direction=180-i
    'muxa.Direction=i
    tanim.Enabled=true
    stop=
    0

    End Sub

    Sub mrefr_Click
    stop=
    1
    tanim.Enabled=
    false
    muxa.X=
    100
    muxa.Y=
    0
    gamewin.Tick
    End Sub
    help me!:sign0148:
     
  2. Cableguy

    Cableguy Expert Licensed User

    If what you intend is the sprite to move to were the stilus is, then you must "animate" it in either the form_mousedown, form_mousemove or Form_mouseup events, wich return the actual stilus position...
     
  3. Byak@

    Byak@ Active Member Licensed User

    i know it.but how select directions for moving sprite&i'm use formula but system of coordinats in gamewinwow is wrong
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Please don't attach images which may offend other users.

    You need something like:
    Code:
    Sub gamewin_NoCollisionMouse
        x = muxa.X + muxa.Width/
    2
        y = muxa.Y + muxa.Height/
    2
        angle = 
    ATan((gamewin.Y - y)/(gamewin.X-x+0.0001)) * 180/cpi
        
    If gamewin.X < x Then angle = angle + 180
        game.Text = angle
        muxa.Direction=angle
        tanim.Enabled=
    true
        stop=
    0
    End Sub
     
  5. Byak@

    Byak@ Active Member Licensed User

    Erel thanks!it's work!But it moves is inexact a little.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice