Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Newbie: Sprite intersect


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-28-2008, 01:19 PM
Knows the basics
 
Join Date: Oct 2007
Posts: 90
Default Newbie: Sprite intersect

I hope I don't fill this forum with stupid questions. So do you.
I have used...
if sprite.IntersectsPoint(x,y) =True then sprite.direction=90
and have placed it in Timer1.tick in the example program.
I have stepped and used the watch. The sprite position goes through the x,y position (at one point being equal) and never becomes true. What am I not doing please?

Also can I drop the = True?

As an aside the debug watches are brilliantly easy to use, wow what a pleasure.
Reply With Quote
  #2 (permalink)  
Old 04-28-2008, 02:52 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,334
Default

You can see the behavior of IntersectsPoint in the Walking Character example by changing the Timer1_Tick code to:
Code:
Sub Timer1_Tick
    'Manually change the current frame.
    sprite.CurrentFrame = (sprite.CurrentFrame + 1) Mod 8 + 8 * direction
    If sprite.IntersectsPoint(100,100) Then form1.Text = sprite.X & " " & sprite.Y
    gw.Tick
End Sub
Quote:
Also can I drop the = True?
Yes.

If it still doesn't work, please post some of your code so we will be able to help.

BTW, your questions are good questions and I'm sure that the answers will help other users as well.
Reply With Quote
  #3 (permalink)  
Old 04-28-2008, 07:10 PM
Knows the basics
 
Join Date: Oct 2007
Posts: 90
Default

Thank you for your reassurance Erel.
The following is a slightly modified Sprite example provided with B4PPC for learning purposes.
In the App_Start I set cw.direction to 0 and x,y to 48,76. cw.velocity=1, Then I move one pixel in X each tick. The sprite moves perfectly and the watch shows the correct x,y including the target 176,76 and beyond.

I cannot see that putting the test after the tick would have an effect.

Sub Timer1_Tick
gw.Tick 'VERY IMPORTANT: causes the GameWindow to advance to the next step.
tick = tick + 1
If tick Mod 50 = 0 Then gw.DeleteMarkedSprites
If cw.IntersectsPoint(176,76) = True Then cw.direction = 90
End Sub

[EDIT]
I have put the intersect line in the walking sample and it doesn't work, however, without pressing any buttons, just stepping the code, it changes direction of its own accord at x=161 which is not the edge of the screen. ( If it is then I can't see where it has been set) Even so 156 is < 161
I must be missing something here.

I set direction to 0 and sprite.x to 90 and sprite.y to 76
Sub Timer1_Tick
'Manually change the current frame.
'sprite.CurrentFrame = (sprite.CurrentFrame + 1) Mod 8 + 8 * direction
'If sprite.IntersectsPoint(120,100) Then form1.Text = sprite.X & " " & sprite.Y
If sprite.IntersectsPoint(156,76)=True Then sprite.direction = 90
gw.Tick
End Sub

Any pointers please?
[EDIT-1]
Weirder still, if I simply change the number 76 to 77 in intersects line in the above code the sprite starts in direction 270, change it back to 76 and it reverts to direction 0

Now I am baffled.

Last edited by enonod : 04-29-2008 at 08:51 AM.
Reply With Quote
  #4 (permalink)  
Old 04-30-2008, 07:05 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,334
Default

It seems to work fine.
Please try the attached code.

The WalkingChar example uses the CollisionEdge event to change the character direction.
Reply With Quote
  #5 (permalink)  
Old 04-30-2008, 06:04 PM
Knows the basics
 
Join Date: Oct 2007
Posts: 90
Default

Well I must be totally dense. I appreciate that the attached walkingchar did work, I tried it when you first mentioned it. I must be misunderstanding because I am not trying to use an edge. I am trying to choose a point anywhere on screen, send a sprite travelling through it and expect an event when it arrives at it.
To do this I expected to use If sprite.IntersectsPoint(156,76)= but received the unexpected results mentioned above.
I wanted to understand (especially the weirder part) what was going wrong and why. Not find an alternative.
Why dense? Because I cannot see the connection between the edge (which seem to be constants) detection and the intersects point.
If you be a bit more explicit I would be grateful.
Reply With Quote
  #6 (permalink)  
Old 05-01-2008, 06:15 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,334
Default

My previous post was not clear.
CollisionEdge event has nothing to do with the IntersectsPoint.
It only causes the character to change direction if it hits one of the screen edges.
Reply With Quote
  #7 (permalink)  
Old 05-01-2008, 11:15 AM
Knows the basics
 
Join Date: Oct 2007
Posts: 90
Default

I apologise but think we are talking at cross purposes and have got out of sync somehow.

Quote:
Originally Posted by enonod View Post
... I am not trying to use an edge. I am trying to choose a point anywhere on screen, send a sprite travelling through it and expect an event when it arrives at it.
To do this I expected to use If sprite.IntersectsPoint(156,76)= but received the unexpected results mentioned above.
I still don't know why IntersectsPoint is not working for my purpose nor why I get the strange behaviour.
If it is incorrect use, then please tell me that I have chosen the wrong keyword and put me right. I wish to change direction at pre-programmed chosen points, not edges.
If I have not made myself clear please tell me.
Thank you.
Reply With Quote
  #8 (permalink)  
Old 05-01-2008, 11:17 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,896
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Quote:
Originally Posted by enonod View Post
If I have not made myself clear please tell me.
Why not post the code that doesn't work then we can see what the problem is?
Reply With Quote
  #9 (permalink)  
Old 05-01-2008, 05:21 PM
Knows the basics
 
Join Date: Oct 2007
Posts: 90
Default

Thank you for your comment. The code was posted and I did say that it was a simple modification to the Sprite example program provided with B4PPC. The modification is posted and the results I received (one of them odd).
I don't see what more I can do.
Here it is again...

I set direction to 0 and sprite.x to 90 and sprite.y to 76
Sub Timer1_Tick
'Manually change the current frame.
'sprite.CurrentFrame = (sprite.CurrentFrame + 1) Mod 8 + 8 * direction
'If sprite.IntersectsPoint(120,100) Then form1.Text = sprite.X & " " & sprite.Y
If sprite.IntersectsPoint(156,76)=True Then sprite.direction = 90
gw.Tick
End Sub

The edit can be seen with the commenting out and the replacement line.
I am not for one moment suggesting that I haven't written something stupid or missed something out. I simply posted the code and sought help.
Then the conversation appeared to go onto edges.

Have I still not made it clear?
Thank you.
Reply With Quote
  #10 (permalink)  
Old 05-01-2008, 05:36 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,896
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Quote:
Originally Posted by enonod View Post
Have I still not made it clear?Thank you.
I am afraid not. I meant post the actual sbp file so we can run it and see exactly what is happening (or not!).
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie: animation texaspoker11 Questions & Help Needed 3 11-05-2008 06:43 PM
Sprite Z Priority fjsantos Questions & Help Needed 4 07-20-2008 06:43 PM
Newbie Question Stevenator65 Questions & Help Needed 9 05-30-2008 09:53 PM
Newbie Questions Bruno Questions & Help Needed 2 05-05-2008 07:45 PM
Newbie questions stratus Questions & Help Needed 2 11-13-2007 02:21 PM


All times are GMT. The time now is 01:40 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0