ForumsProgramming ForumBitmap Attachment - Need Some Help

2 4036
Klemzo
offline
Klemzo
14 posts
Nomad

Hello. Here's a script that goes to a frame ofc.

I wonder why it doesn't work? The bitmap is not attached, plus the hero moves weird (spinning and stuff like that)
What did I do wrong? Any help appreciated.
Thanks

<br><br>_root.attachMovie("hero", "hero_on_stage", 10000,{_x:200,_y:20});<br>_root.attachMovie("trail_sprite", "trail_mc", 8000);<br>trailbitmap = new flash.display.BitmapData(500, 350, true,0x000000);<br>_root.createEmptyMovieClip("trail", 1);<br>trail.attachBitmap(trailbitmap, 0);<br>trail_mc._visible = false;<br>yspeed = 0;<br>xspeed = 0;<br>wind = 0.0;<br>power = 0.75;<br>gravity = 0.0;<br>upconstant = 0.75;<br>friction = 0.98;<br>hero_on_stage.onEnterFrame = function() {<br>	if (Key.isDown(Key.LEFT)) {<br>		xspeed = xspeed-power;<br>	}<br>	if (Key.isDown(Key.RIGHT)) {<br>		xspeed = xspeed+power;<br>	}<br>	if (Key.isDown(Key.UP)) {<br>		yspeed = yspeed-power;<br>	}<br>	if (Key.isDown(Key.DOWN)) {<br>		yspeed = yspeed+power;<br>	}<br>	xspeed = (xspeed+wind)*friction;<br>	yspeed = (yspeed+gravity)*friction;<br>	if(sunken == 0){<br>		_y = _y+yspeed;<br>		_x = _x+xspeed;<br>	}<br>	else{<br>		_y = _y+(yspeed/5);<br>		_x = _x+(xspeed/3);<br>	}<br>	_rotation = _rotation+xspeed;<br>	if (_root.wall.hitTest(_x, _y, true)) {<br>		xspeed = 0;<br>		yspeed = 0;<br>		_x = 76;<br>		_y = 87;<br>	}<br>	if (_root.water.hitTest(_x, _y, true)) {<br>		sunken = 1;<br>	}<br>	else{<br>		sunken = 0;<br>	}<br>	this._rotation = this._rotation+xspeed;<br>	_root.trail_mc.trail_sprite._x = this._x;<br>	_root.trail_mc.trail_sprite._y = this._y;<br>	_root.trailbitmap.draw(_root.trail_mc);<br>	trail_rectangle = new flash.geom.Rectangle(0, 0, 500, 350);<br>	trail_blur = new flash.filters.BlurFilter(2, 2, 3);<br>	_root.trailbitmap.applyFilter(_root.trailbitmap, trail_rectangle, new Point(0, 0), trail_blur);<br>}<br>
  • 2 Replies
Klemzo
offline
Klemzo
14 posts
Nomad

I know there is a lot of great scripters on this forums, can't noone help me?

IQAndreas
offline
IQAndreas
299 posts
Peasant

Long time on see everyone.

This code should MOSTLY work, but it still requires a few modifications to the way Keyboard Events are handled.

Look into that tutorial I recommended for you, and you should be able to make the rest of the modifications on your own.
http://gamedev.michaeljameswilliams.com/as3-avoider-game-tutorial-base/

And here is the code:

import flash.events.Event;<br>import flash.display.MovieClip;<br>import flash.display.Sprite;<br><br>//_root.attachMovie("hero", "hero_on_stage", 10000,{_x:200,_y:20});<br>var hero_on_stage:hero = new hero();<br>hero.x = 200;<br>hero.y = 20;<br>this.addChild(hero);<br><br>//_root.attachMovie("trail_sprite", "trail_mc", 8000);<br>var trail_mc:trail_sprite = new trail_sprite();<br>this.addChild(trail_mc);<br><br>var trailbitmap = new BitmapData(500, 350, true, 0x000000);<br>var trail:MovieClip = new MovieClip();<br>this.addChild(trail);<br><br>//trail.attachBitmap(trailbitmap, 0);<br>//trail_mc._visible = false;<br>trail.addChild(trailbitmap);<br>trail.visible = false;<br><br>var yspeed = 0;<br>var xspeed = 0;<br>var wind = 0.0;<br>var power = 0.75;<br>var gravity = 0.0;<br>var upconstant = 0.75;<br>var friction = 0.98;<br><br>hero_on_stage.addEventListener(Event.ENTER_FRAME, movePlayer);<br><br>function movePlayer(e:Event) <br>{<br>    if (Key.isDown(Key.LEFT)) {<br>        xspeed = xspeed-power;<br>    }<br>    if (Key.isDown(Key.RIGHT)) {<br>        xspeed = xspeed+power;<br>    }<br>    if (Key.isDown(Key.UP)) {<br>        yspeed = yspeed-power;<br>    }<br>    if (Key.isDown(Key.DOWN)) {<br>        yspeed = yspeed+power;<br>    }<br>	<br>    xspeed = (xspeed+wind)*friction;<br>    yspeed = (yspeed+gravity)*friction;<br>    if(sunken == 0){<br>        hero_on_stage.y += yspeed;<br>        hero_on_stage.x += xspeed;<br>    }<br>    else{<br>        hero_on_stage.y += (yspeed/5);<br>        hero_on_stage.x += (xspeed/3);<br>    }<br>    hero_on_stage.rotation += xspeed;<br>	<br>    if (wall.hitTestPoint(hero_on_stage.x, hero_on_stage.y, true)) {<br>        xspeed = 0;<br>        yspeed = 0;<br>        hero_on_stage.x = 76;<br>        hero_on_stage.y = 87;<br>    }<br>    if (water.hitTestPoint(hero_on_stage.x, hero_on_stage.y, true)) {<br>        sunken = 1;<br>    }<br>    else{<br>        sunken = 0;<br>    }<br>	<br>	//I really am not sure what all this does...<br>    this._rotation = this._rotation+xspeed;<br>    _root.trail_mc.trail_sprite._x = this._x;<br>    _root.trail_mc.trail_sprite._y = this._y;<br>    _root.trailbitmap.draw(_root.trail_mc);<br>    trail_rectangle = new flash.geom.Rectangle(0, 0, 500, 350);<br>    trail_blur = new flash.filters.BlurFilter(2, 2, 3);<br>    _root.trailbitmap.applyFilter(_root.trailbitmap, trail_rectangle, new Point(0, 0), trail_blur);<br>}
Showing 1-2 of 2