Black Screen When Image Displayed

ProfessorChill

Veteran
Veteran
Joined
Jan 28, 2016
Messages
30
Reaction score
0
First Language
English
Primarily Uses
What happens (I walk up to press the event)


What is in the event I press: animatedimages(-110, -125, "FemaleMed", 1, 24)


What does that do? animatedimages(x position, y position, Graphics/Pictures/(Location)/1.png, looping?, frames in folder)


What do you mean black screen? Look below at the gif.





The code:


Why the whole code? I don't know where the error is happening.


class Scene_DataHolder < Scene_Base

def prepare(x, y, path, loop, frames)
@window_x = x
@window_y = y
@path = path
@loop = loop
@frames = frames
@newframes = 1
@rect = Rect.new(@window_x, @window_y, 0, 0)
@image = Sprite.new
create_background
create_window
end

def update
Graphics.wait(10)
@newframes += 1
if @newframes != @frames
@image.bitmap.clear
@image.bitmap.clear_rect(@rect)
create_window
end
else if @newframes == @frames
if @loop == 1
resetframes
end
else if @loop == 0
SceneManager.return if $frames == 0
end
end
end

def resetframes
@newframes = 1
update
end

def create_background
@background_sprite = Sprite.new
@background_sprite.bitmap = SceneManager.background_bitmap
end

def create_window
@rect.set(@window_x, @window_y, 0, 0)
@image.bitmap = Bitmap.new("Graphics/Pictures/" + @path + "/" + @newframes.to_s + ".png")
end
end

class Game_Interpreter
def animatedimages(x, y, path, loop, frames)
SceneManager.call(Scene_DataHolder)
SceneManager.scene.prepare(x, y, path, loop, frames)
end
end


Code updated
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
I suspect it's got something to do with this ...

Code:
    @image.bitmap = Bitmap.new("Graphics/Pictures/" + @path + "/" + @newframes.to_s + ".png")
    @image.bitmap.blt(@window_x, @window_y, @image.bitmap, @rect)


Why are you loading the image and then blitting to it?
 

ProfessorChill

Veteran
Veteran
Joined
Jan 28, 2016
Messages
30
Reaction score
0
First Language
English
Primarily Uses
I suspect it's got something to do with this ...

Code:
    @image.bitmap = Bitmap.new("Graphics/Pictures/" + @path + "/" + @newframes.to_s + ".png")
    @image.bitmap.blt(@window_x, @window_y, @image.bitmap, @rect)


Why are you loading the image and then blitting to it?
You know, I'm not sure.


I'm not firmiliar with using sprite nore bitmap and only found most of what I know through the f1 help menu.


EDIT: I removed the blt and the same thing is occuring.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
Try swapping the order of these two?

Code:
    SceneManager.call(Scene_DataHolder)
    SceneManager.scene.prepare(x, y, path, loop, frames)


I don't really know - I'm just guessing.  Not sure what you're trying to accomplish here
 

ProfessorChill

Veteran
Veteran
Joined
Jan 28, 2016
Messages
30
Reaction score
0
First Language
English
Primarily Uses
Try swapping the order of these two?

Code:
    SceneManager.call(Scene_DataHolder)
    SceneManager.scene.prepare(x, y, path, loop, frames)


I don't really know - I'm just guessing.  Not sure what you're trying to accomplish here
Instant crash, I need the one on top there.


What I'm doing? Making a gif player so that I can have a live view of the character.


I'm trying to do this but since I need a lot of images and folders I feel that doing it by code would be easier.


Theres essentially 24 images per hair/body/face and that's just to have a composite idle animation play.


So this code would just allow me to sort it better and get animations to play in a more efficiant manner.





EDIT: Thank goodness I took this picture, I now know I have a randomly floating guard :I
 
Last edited by a moderator:

ProfessorChill

Veteran
Veteran
Joined
Jan 28, 2016
Messages
30
Reaction score
0
First Language
English
Primarily Uses
@Shaz I found out what was causing it, I'm sorry for not understanding however I stayed up till 2:00AM trying to learn more about RGSS and figuring out more things and what causes what.


I found out that when I run this code:


def create_window
@image.bitmap = Bitmap.new(200,200)
@image.bitmap.draw_text(0,0,200,200,"hello")
#@image.bitmap = Bitmap.new("Graphics/Pictures/" + @path + "/" + @newframes.to_s + ".png")
end


(I replaced bitmap with draw_text to do a test, it is still the same general code.)


It runs the update:


def update
Graphics.wait(10)
@newframes += 1
if @newframes != @frames
@image.bitmap.clear
create_window
end
else if @newframes == @frames
if @loop == 1
#resetframes
end
else if @loop == 0
SceneManager.return if $frames == 0
end
end
end


However, this pauses the SceneManager causing the game to freeze unless I run SceneManager.return


Now with that said, if I put SceneManager.return, I can play the game.


But the image leaves, it essentially unloads my code.


Any advice on that?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
I don't see anything in that that would freeze the game.  What's in the #resetframes that you've left out?
 

ProfessorChill

Veteran
Veteran
Joined
Jan 28, 2016
Messages
30
Reaction score
0
First Language
English
Primarily Uses
I don't see anything in that that would freeze the game.  What's in the #resetframes that you've left out?
def update
Graphics.wait(10)
@newframes += 1
if @newframes != @frames
@image.bitmap.dispose
create_window
end
else if @newframes == @frames
if @loop == 1
resetframes
end
else if @loop == 0
SceneManager.return if $frames == 0
end
end
end

def resetframes
@newframes = 1
update
end


Not sure why it's happening either, the screen just goes blank and in a sense "freezes" being as the player cannot do anything however the animation plays.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
lol - reset frames is called from update, but then it calls update.  You've given yourself an endless loop.
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
First, you didn't call super in the update method. That will result in your inputs being ignored (it will look like it freezes your game).


Either call a super there somewhere, or call Input.update.


What you did in that method will pause your entire screen for 10 frames, which is certainly not what you want.


You want to set the number of frames (in time) between each animation frame to 10 without affecting anything else on the scene.


To do this effectively, you need to make image-sheets, not single images. Using an image sheet and just moving around the rect of the sprite is way better performance-wise than constantly clearing and drawing the bitmap (with blt) on the sprite or constantly disposing and changing the bitmap.


Get familiar with image-sheets first. It must follow a format. The basic ones can simply go in a horizontal or vertical line, while some more complicated ones (code-wise, graphically it is almost the same, just some position changes) follow a grid-like sheet for positioning.


I usually just go with horizontal or vertical sheets, because I need the other axis for something else (well, most of the time), like direction based images and such. If you don't need the other axis for anything else, you might as well try the grid type sheet (but the code for that one is a bit more complicated).


When you made your image-sheet(s), you can start to work on your code. What you want to do is to make an entirely new class solely dedicated for maintaining animated images from an image-sheet. That way, you can re-use it for specific purposes, and you can also use it on any scene, anywhere and anytime.


The initialize method should contain the parameters for that instance of the class in it's arguments. That way, you can initialize the same class with different starting values.


Well, it's the same as the arguments in your script call, but this time, the entire instance gets these values.


You can take a look at this class I made:


http://pastebin.com/t7QrwEH7


I added some notes and instructions there to explain what each method does.


Now you got a class which can animate image using image-sheets. How to use it?


Well, you just store an instance of the class in a variable and update it until you dispose it.


Making one is as simple as making a sprite (check the header of the script).


To show you an example, here is a sample scene:

class Scene_AnimExample < Scene_Base

def update
super
update_buttons
end

def update_buttons
trigger_anim_image if Input.trigger?:)C)
trigger_animation if Input.trigger?:)UP)
trigger_flash if Input.trigger?:)DOWN)
return_scene if Input.trigger?:)B)
@anim_img.update if @anim_img && !@anim_img.disposed?
end

def trigger_anim_image
Sound.play_ok
@anim_img.dispose if @anim_img && !@anim_img.disposed?
data = { # An example data setup. Edit them how you want!
:img => "hp2a_fill",
:opa => 255, :z => 100,
:rows => 4, # Meaning it will be a vertical image-sheet!
:frames => [0,1,2,3,2,1],
:wait => 8,
}
folder = "Graphics/AnimGauges/HP/"
@anim_img = AnimatedImage.new(data,nil,folder)
@anim_img.x = Graphics.width/2
@anim_img.y = Graphics.height/2
end

def trigger_animation # Plays a random animation.
return unless @anim_img && !@anim_img.disposed?
@anim_img.set_anim:)test1,rand(100)+1)
end

def trigger_flash # Plays a flash effect.
return unless @anim_img && !@anim_img.disposed?
r = rand(255); g = rand(255); b = rand(255); a = rand(255)
col = Color.new(r,g,b,a)
dur = rand(120) + 60
@anim_img.start_flash(col,dur)
end

def dispose_all_windows
@anim_img.dispose if @anim_img
super
end

end



Open the scene and press the confirm button. You will see your image appear and it should be animated (if your settings are correct).


You can press the cancel button to exit the scene.


You can press UP to play an animation on the image.


You can press DOWN to play a flash effect on the image.


Remember to change the data/folder settings in the trigger_anim_image method to your own settings!


Again, this is just an example scene.


You can also make a container for these images in Scene_Base itself, and do the update/dispose methods there directly. That way, you can initiate this class literally anywhere and it will work. From events, on custom scenes, and so on. This requires some proper initialize and disposal methods to function (so that the images show up on the scenes you specified, and not on all the scenes), so I won't go that way now.


In the case of your example, you need it on the map, right?


I will show you how to make a container on that scene for them. Look at the code below:

class Game_System

attr_accessor :map_anim_imgs

# This will store all the animated images on the map currently!
def map_anim_imgs
@map_anim_imgs = {} if @map_anim_imgs.nil?
return @map_anim_imgs
end

end

class Scene_Map < Scene_Base

alias add_anim_imgs9937 start
def start
add_anim_imgs9937
init_anim_images
end

# Initializing the images based on the container in Game_System!
def init_anim_images
@anim_imgs = {}
$game_system.map_anim_imgs.each do |key,data|
@anim_imgs[key] = AnimatedImage.new(data[:data],nil,data[:folder])
@anim_imgs[key].x = data[:pos][0]
@anim_imgs[key].y = data[:pos][1]
end
end

# This adds a new animated image on the map!
def add_anim_img(key,pos,data,folder)
@anim_imgs[key].dispose if @anim_imgs[key] && !@anim_imgs[key].disposed?
@anim_imgs[key] = AnimatedImage.new(data,nil,folder)
@anim_imgs[key].x = pos[0]
@anim_imgs[key].y = pos[1]
end

# This removes an animated image from the map.
def remove_anim_img(key)
@anim_imgs[key].dispose if @anim_imgs[key] && !@anim_imgs[key].disposed?
end

alias update_anim_imgs9222 update
def update
update_anim_imgs9222
update_anim_imgs
end

# Updating all animated images currently on the screen!
def update_anim_imgs
@anim_imgs.each_value {|img| next if img.nil? || img.disposed?; img.update }
end

def dispose_all_windows
dispose_anim_imgs
super
end

# Disposing all animated images currently on the screen!
def dispose_anim_imgs
@anim_imgs.each_value {|img| next if img.nil? || img.disposed?; img.dispose }
end

end

class Game_Interpreter

# Script call to show an animated image on the map!
# key = The unique key of the image. You can NOT use duplicates here!
# If you already have an image with the :test key, and still use the
# same key, the old image will be replaced with the new one!
# If you use a different key, you can show more than one images ta once!
# pos = The X and Y position of the image in an array. Sample: [x,y]
# data = The data of the image and it's animation settings.
# Uses the same format like explained in the script for the
# AnimatedImage class.
# folder = The folder where the image is.
# Optional. You can see it's default value.
def show_anim_img(key,pos,data,folder="Graphics/Pictures/")
$game_system.map_anim_imgs[key] = {:pos => pos, :data => data, :folder => folder}
SceneManager.scene.add_anim_img(key,pos,data,folder)
end

# Script call to remove an animated image from the map!
# key = The unique key of the image.
# You must use a valid key otherwise nothing will happen!
def remove_anim_img(key)
return unless $game_system.map_anim_imgs[key]
$game_system.map_anim_imgs.delete(key)
SceneManager.scene.remove_anim_img(key)
end

end

Now you can show and hide these images however you want on the map scene whenever you want.


Depending on what you want to do, you might need to change some things here and there. 


You can also expand that AnimatedImage class I made with your own methods if needed as well.


I wonder if I reached the character limit or not... Lets see... :D
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,051
Messages
1,018,549
Members
137,836
Latest member
T62352536256t362
Top