External Sprite Loader

niccosw

  • Posts: 91
This pack allows sprites to be loaded externally at runtime from a user's computer or from a single server. Crossdomain security is not set up yet so it can't load images from other servers and is unlikely to work with most game portals. Presently only one sprite is loaded per actor, but future versions will hopefully allow animations to be loaded.

Instructions:
Attach Load Sprite to an Actor.
Do NOT attach External Image.
Specify the URL in the actor's attributes of the behavior.

When the character loads, the sprite will be generated from an external file.

This uses code from this blogpost: http://www.iokat.com/posts/3/loading-external-images-for-use-with-flixel-sprites

« Last Edit: June 13, 2011, 03:49:45 am by niccosw »

DoctorMikeReddy

  • *
  • Posts: 180
I had real problems with this at first. Firstly, I had a few problems with the correct path, as I took the "plat" in the Attributes help message literally; it is actually "plaf", but that was less of a problem as relative paths are fine. Secondly, there needs to be a default icon for the Actor or it will not appear, which is more of a problem as I couldn't work out why Safari was telling me that the graphic was loaded successfully, but the actor wasn't appearing.

I'm going to jump in now and see if I can work out how to get a Background modifiable this way, and if it is possible to load a new sprite during run-time, rather than at set up, but if you have any thoughts on how to do this (to save me time) I would appreciate it.

niccosw

  • Posts: 91
Sorry about the spelling error.

I'll look into loading backgrounds. Even if it can't be done, you can create an actor the size of the screen.

I'm working on an External Sprite Loader right now, but I've hit a roadblock. I can stream sprites in but they don't remain resident in memory.

I gotta go to bed now, but I can share more with you tomorrow.

DoctorMikeReddy

  • *
  • Posts: 180
I worked out the "Background" actor sprite and knocked up a quick script that would take an actor (the size of the screen as you suggested) and place it into layer 0 at (0,0) and this is fine. I would be interested in whether the sprite could be changed during the game. Also, I had a go at deconstructing scene but unlike actor there is no image information that is easily accessible. There is an ImageBackground data type, but no methods that appear to be able to change it.

DoctorMikeReddy

  • *
  • Posts: 180
I've written elsewhere on my failed attempts to get a code version of your design mode sprite loader, but the preview as code has some weird stuff. Namely, the animation attributes show as String, as does the Control one. Putting them in as Animation and Control data types allows the correct types for attributes, but only when you put it in the inbuilt editor. But syntax checking throws a wobbler with the Control type and the .toString() bit of assigning the animations. Changing this to the relevant public data type for animation didn't work. Ground to a halt really. :-(

niccosw

  • Posts: 91
The problem I am having is with the actor.addAnim function. Specifically the imgData Bitmap/Class.

addAnim(name:String, imgData:*, frameCount:Number = 1, frameWidth:Number = 0, frameHeight:Number = 0, durations:Array = null, looping:Boolean = true, shapes:Array = null):void

It may be due to my BitmapData have the improper width/height dimensions but I haven't found a way to correct it.

I'm going to be out of town for a few days but I'll try to work on it and post the code when I get back on Sunday. I'd appreciate it if you could have a look at it.

DoctorMikeReddy

  • *
  • Posts: 180
I always made sure that all the graphics were the same size...

molanisgames

  • Posts: 1
Hi all,
Is the External Sprite Loader supported in the current version?
I got it but it does not show any image. Is it possible to add external images to a game? I want my actor to get the sprite from a url in my site
Thanks

niccosw

  • Posts: 91
I just tested it and it works fine. Attach the script to your actor, give the behavior the target URL and place the actor in the scene. Remember that you may not be able to use it cross-domain (SWF and target image should be on the same server).

eldiablo

  • Posts: 23
I have this problem:

Code: [Select]
8/1/12 3:24:23.196 PM [0x0-0x7f17f1].Stencyl: [LOG] Behavior: LoadSprite at line 68
8/1/12 3:24:23.196 PM [0x0-0x7f17f1].Stencyl: [LOG] Method marked override must override another method.
8/1/12 3:24:23.196 PM [0x0-0x7f17f1].Stencyl: [LOG] override public function update():void
8/1/12 3:24:23.196 PM [0x0-0x7f17f1].Stencyl: [LOG] Behavior: LoadSprite at line 73
8/1/12 3:24:23.196 PM [0x0-0x7f17f1].Stencyl: [LOG] Method marked override must override another method.
8/1/12 3:24:23.196 PM [0x0-0x7f17f1].Stencyl: [LOG] override public function draw(g:Graphics, x:Number, y:Number):void
8/1/12 3:24:23.196 PM [0x0-0x7f17f1].Stencyl: [LOG] Behavior: LoadSprite at line 77
8/1/12 3:24:23.196 PM [0x0-0x7f17f1].Stencyl: [LOG] Method marked override must override another method.
8/1/12 3:24:23.196 PM [0x0-0x7f17f1].Stencyl: [LOG] override public function handleCollision(event:Collision):void

Any idea whats the cause?

stepstream

  • Posts: 40
I'm also having this problem. Anyone?

stepstream

  • Posts: 40
bump. What am I doing wrong?

captaincomic

  • *
  • Posts: 6108
After the introduction of events in 2.0 code mode behaviors need to be updated.

Replace
Code: [Select]
override public function update():voidwith
Code: [Select]
public function update(list:Array):void
and
Code: [Select]
override public function draw(g:Graphics, x:Number, y:Number):voidwith
Code: [Select]
public function draw(list:Array, g:Graphics, x:Number, y:Number):void
and
Code: [Select]
override public function handleCollision(event:Collision):voidwith
Code: [Select]
public function handleCollision(list:Array, event:Collision):void
and add these lines to init
Code: [Select]
addWhenUpdatedListener(null, update);
addWhenDrawingListener(null, draw);

and only in actor behaviors add
Code: [Select]
addCollisionListener(actor, handleCollision);
This is the general procedure for all code mode behaviors. If you don't need the update/draw/handleCollision functions (like in the External Sprite Loader) you could also just remove them.