I cannot get TinelineFX to work with pther drawing code
Home › Forums › TimelineFX Module › I cannot get TinelineFX to work with pther drawing code
- This topic has 1 reply, 2 voices, and was last updated 15 years, 3 months ago by imported_peterigz.
-
AuthorPosts
-
September 20, 2009 at 6:44 am #3120
bugzillaParticipantI have been copying bits from the Vaders sample game to attempt to make something. I can get the effects to animate fine but once the effects appear, all other bitmap sprites disappear. I have tried moving the drawing code into various functions and attempted using both standard BlitzMax drawing code and TimelineFX tlEntity drawing code. I am about to give up. I have been working on it for about two days straight with not luck. Here is the code I have at the moment.
Strict
Framework brl.max2d
Import rigz.entity
Import rigz.tweener
Import brl.pngloader
Import rigz.timelinefxSetGraphicsDriver GLMax2DDriver()
Graphics 1024, 768
HideMouse()
‘
PARTICLE VARIABLES
Global effectslib:tlEffectsLibrary
Global particles:tlParticleManager ‘The main particle manager for all the explosions and bulletsparticles = CreateParticleManager()
effectslib = LoadEffects(“vadereffects.eff”)
‘Orient the particles so that screen coords are what we use to position stuff
particles.SetScreenSize(GraphicsWidth(), GraphicsHeight())
particles.SetOrigin(GraphicsWidth() / 2, GraphicsHeight() / 2)
particles.SetIdleTimeLimit(5)
‘
Type player Extends tlEntity
Field img:TAnimImage
Field dx:Int
Field dy:Int
Field angle:Float
Field speed:Float
Field moving = FalseMethod moveTo()
angle = ATan2(dy – y, dx – x)
x = x + Cos(angle) * speed
y = y + Sin(angle) * speed
If(Distance(x, y, dx, dy) < 10)
speed = 0
moving = 0
End If
End MethodEnd Type
Type background Extends tlEntity
Field img:TAnimImage
End TypeType cursor Extends tlEntity
Field img:TAnimImage
End TypeLocal p:player=New player
p.img = LoadSprite(“Player.png”)
p.SetPosition(400, 400)
p.Capture()
p.speed = 0Local bg:background = New background
bg.img = LoadSprite(“background.png”)
bg.SetPosition(200, 200)
bg.Capture()
bg.speed = 0Local curs:cursor = New cursor
curs.img = LoadSprite(“CURSOR.png”)
curs.setPosition(MouseX(), MouseY())‘set up a tweener using the tweener module
Global tweener:tTweener = New tTweener.Create(30)
SetUpdateFrequency(30)While Not KeyDown(KEY_ESCAPE)
Clstweener.Update()
For Local Ticks:Int = 1 To tweener.FrameTicks
‘Update the execution time for the tweener
tweener.UpdateExecutionTime()
particles.Update()
Next
particles.DrawParticles(tweener.Tween)
If(MouseDown(1))
Local explode:tlEffect
explode = CopyEffect(effectslib.GetEffect(“player Explosion”), particles)
‘create the explosion and add it to the particle manager
explode.setx(MouseX())
explode.sety(MouseY())
particles.addeffect(explode)
p.dx = MouseX()
p.dy = MouseY()
p.speed = 1
p.moving = True
End If
If(p.moving)
p.moveTo()
End IfDrawSprite(bg.img, bg.x, bg.y)
DrawSprite(p.img, p.x, p.y)
DrawSprite(curs.img, MouseX(), MouseY())Flip
Wend
Function Distance(x0:Float, y0:Float, x1:Float, y1:Float)
Local distx:Float = x0 – x1
Local disty:Float = y0 – y1
Return Sqr(distx * distx + disty * disty)
End FunctionSeptember 20, 2009 at 11:52 am #3508
imported_peterigzParticipantHi Bugzilla,
The reason they disappear like that is because when the particles are drawn there’s no telling what state they will leave the values of SetScale, SetRotation, SetAlpha etc. So when you use drawSprite or DrawImage, it’s good practice to set these to what you want for each image drawn. I see that you’re extending tlEntity, in which case you can use the render method to draw your sprites. I had a play with your code and got it working, I’d advise that you have a read through of the tutorial on this site called “Making a game from start to finish”, and also, there is a similar tutorial in the BlitzMax Coder magazine that explains a lot about extending tlEntity and how to use it. Post here as much as you want too, I’m happy to help, as it helps me make it a better module!
You’ll notice in the code below I’ve added update methods to your types, these override the update methods in tlEntity, but like I say, things are explained more in detail in the tutorials.
Strict
Framework brl.max2d
Import rigz.entity
Import rigz.tweener
Import brl.pngloader
Import rigz.timelinefx
SetGraphicsDriver GLMax2DDriver()
Graphics 1024, 768
HideMouse()
'
PARTICLE VARIABLES
Global effectslib:tlEffectsLibrary
Global particles:tlParticleManager 'The main particle manager for all the explosions and bullets
particles = CreateParticleManager()
effectslib = LoadEffects("vadereffects.eff")
'Orient the particles so that screen coords are what we use to position stuff
particles.SetScreenSize(GraphicsWidth(), GraphicsHeight())
particles.SetOrigin(GraphicsWidth() / 2, GraphicsHeight() / 2)
particles.SetIdleTimeLimit(5)
'
Type player Extends tlEntity
'Field img:TAnimImage
Field dx:Int
Field dy:Int
Field angle:Float
Field speed:Float
Field moving = False
Method moveTo()
angle = ATan2(dy - y, dx - x) + 90
'x = x + Cos(angle) * speed
'y = y + Sin(angle) * speed
Self.SetEntityDirection(angle)
If(Distance(x, y, dx, dy) < 10)
Self.SetSpeed(0)
moving = 0
End If
DebugLog Distance(x, y, dx, dy)
End Method
Rem
bbdoc:Update the entity
End Rem
Method Update()
Self.capture()
If Self.moving
Self.moveTo()
End If
Super.Update()
End Method
End Type
Type background Extends tlEntity
'Field img:TAnimImage
End Type
Type cursor Extends tlEntity
'Field img:TAnimImage
Rem
bbdoc:Update the entity
End Rem
Method Update()
Self.capture()
Self.SetPosition(MouseX(), MouseY())
Super.Update()
End Method
End Type
Local p:player = New player
p.setsprite(LoadSprite("Player.png"))
p.SetPosition(400, 400)
p.Capture()
p.Update()
p.speed = 0
Local bg:TImage = New TImage
bg = LoadImage("background.png")
Local curs:cursor = New cursor
curs.SetSprite(LoadSprite("CURSOR.png"))
curs.setPosition(MouseX(), MouseY())
curs.Capture()
curs.Update()
'set up a tweener using the tweener module
Global tweener:tTweener = New tTweener.Create(30)
SetUpdateFrequency(30)
While Not KeyDown(KEY_ESCAPE)
Cls
tweener.Update()
For Local Ticks:Int = 1 To tweener.FrameTicks
'Update the execution time for the tweener
tweener.UpdateExecutionTime()
curs.Update()
If(MouseHit(1))
Local explode:tlEffect
explode = CopyEffect(effectslib.GetEffect("player Explosion"), particles)
'create the explosion and add it to the particle manager
explode.setx(MouseX())
explode.sety(MouseY())
particles.addeffect(explode)
p.dx = MouseX()
p.dy = MouseY()
p.SetSpeed(100)
p.moving = True
End If
p.Update()
particles.Update()
Next
drawbackground(bg)
'DrawSprite(bg.img, bg.x, bg.y)
p.Render(tweener.Tween)
'DrawSprite(p.img, p.x, p.y)
curs.Render(tweener.Tween)
'DrawSprite(curs.img, MouseX(), MouseY())
particles.DrawParticles(tweener.Tween)
Flip
Wend
Function drawbackground(background:TImage)
SetScale GraphicsWidth() / Float(ImageWidth(background)), GraphicsHeight() / Float(ImageHeight(background))
SetColor 255, 255, 255
SetAlpha 1
SetBlend SOLIDBLEND
SetRotation 0
DrawImage(background, 0, 0)
End Function
Function Distance(x0:Float, y0:Float, x1:Float, y1:Float)
Local distx:Float = x0 - x1
Local disty:Float = y0 - y1
Return Sqr(distx * distx + disty * disty)
End Function
-
AuthorPosts
You must be logged in to reply to this topic.