A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: wall hitTestObject but with multiple walls

  1. #1
    Junior Member
    Join Date
    Apr 2019
    Posts
    9

    wall hitTestObject but with multiple walls

    im doing a simple rpg game for a programming course held in my college and i have an issue with the walls
    so far this is what i figured out to make character not be able to walk on walls
    Code:
    function gameLoop(loopEvent: Event): void {
    	//////////links movement
    	if (rightPressed == true) {
    		if (linkMc.x < 1200) {
    			linkMc.x += 10
    		} else if (overworldMc.x > -4310) {
    			overworldMc.x -= 10;
    		}
    
    		linkMc.gotoAndStop("walk right frame");
    	} else if (leftPressed == true) {
    		if (linkMc.x > 570) {
    			linkMc.x -= 10
    		} else if (overworldMc.x < 3000) {
    			overworldMc.x += 10;
    		}
    
    		linkMc.gotoAndStop("walk left frame");
    	} else if (downPressed) {
    		
    		if (linkMc.y < 525) {
    			linkMc.y += 10
    		} else if (overworldMc.y > -2232) {
    			overworldMc.y -= 10;
    		}
    
    		linkMc.gotoAndStop("walk front frame");
    	} else if (upPressed) {
    		if(!linkMc.hitTestObject(overworldMc.wallMc)){
    		if (linkMc.y > 300) {
    			linkMc.y -= 10
    		} else if (overworldMc.y < 0) {
    			overworldMc.y += 10;
    		}
    	}
    as you can see in the last one i made an objects called wallMc thats going to be transparent, and it works well to stop the chara from walking forward but i need multiple of these and when i put them all in one object the character is kind of ''inside'' of the symbol so she just has no ability to walk forward, in what way could i set it up so that i have multiple of these?

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,834
    It depends on how complex you want it to be. One of the simpler ways would be to use a direction and when a hit happens to reverse it. This requires you to check hit in the direction you're moving. All hitTestObject does is check if the objects are overlapping. It's best to use direction instead for something like this. For each wall you need the objects to be separate. Your best bet is to place each wall object into an array to cycle through. There are quite a few tutorials out for this already. What version of actionscript are you using?
    .

  3. #3
    Junior Member
    Join Date
    Apr 2019
    Posts
    9
    Quote Originally Posted by swak View Post
    It depends on how complex you want it to be. One of the simpler ways would be to use a direction and when a hit happens to reverse it. This requires you to check hit in the direction you're moving. All hitTestObject does is check if the objects are overlapping. It's best to use direction instead for something like this. For each wall you need the objects to be separate. Your best bet is to place each wall object into an array to cycle through. There are quite a few tutorials out for this already. What version of actionscript are you using?
    as3. could you link me the tutorial? i feel like ive looked trhough eveything and havent found anything

  4. #4
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,834
    Have you seen this series of videos: https://www.youtube.com/watch?v=N_gL...FNy2nD5AsrWSIR Also, if you upload your fla I can take a look at it.
    .

  5. #5
    Junior Member
    Join Date
    Jul 2019
    Posts
    3
    You've gotten among the best online sites.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center